]> err.no Git - linux-2.6/commitdiff
Driver Core: add ability for class_for_each_device to start in middle of list
authorGreg Kroah-Hartman <gregkh@suse.de>
Thu, 22 May 2008 21:21:08 +0000 (17:21 -0400)
committerGreg Kroah-Hartman <gregkh@suse.de>
Tue, 22 Jul 2008 04:54:47 +0000 (21:54 -0700)
This mirrors the functionality that driver_for_each_device has as well.

We add a start variable, and all callers of the function are fixed up at
the same time.

The block layer will be using this new functionality in a follow-on
patch.

Cc: Kay Sievers <kay.sievers@vrfy.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
drivers/base/class.c
drivers/i2c/i2c-core.c
drivers/ieee1394/nodemgr.c
drivers/power/apm_power.c
drivers/power/power_supply_core.c
include/linux/device.h

index 71ce3ff6bdf53261af4cc41e5763846803569f27..2eb7048003a803fd25b57ce2a7be3a444ad94d89 100644 (file)
@@ -256,11 +256,14 @@ char *make_class_name(const char *name, struct kobject *kobj)
 /**
  * class_for_each_device - device iterator
  * @class: the class we're iterating
+ * @start: the device to start with in the list, if any.
  * @data: data for the callback
  * @fn: function to be called for each device
  *
  * Iterate over @class's list of devices, and call @fn for each,
- * passing it @data.
+ * passing it @data.  If @start is set, the list iteration will start
+ * there, otherwise if it is NULL, the iteration starts at the
+ * beginning of the list.
  *
  * We check the return of @fn each time. If it returns anything
  * other than 0, we break out and return that value.
@@ -269,8 +272,8 @@ char *make_class_name(const char *name, struct kobject *kobj)
  * re-acquired in @fn, otherwise it will self-deadlocking. For
  * example, calls to add or remove class members would be verboten.
  */
-int class_for_each_device(struct class *class, void *data,
-                          int (*fn)(struct device *, void *))
+int class_for_each_device(struct class *class, struct device *start,
+                         void *data, int (*fn)(struct device *, void *))
 {
        struct device *dev;
        int error = 0;
@@ -279,12 +282,14 @@ int class_for_each_device(struct class *class, void *data,
                return -EINVAL;
        down(&class->sem);
        list_for_each_entry(dev, &class->devices, node) {
+               if (start) {
+                       if (start == dev)
+                               start = NULL;
+                       continue;
+               }
                dev = get_device(dev);
-               if (dev) {
-                       error = fn(dev, data);
-                       put_device(dev);
-               } else
-                       error = -ENODEV;
+               error = fn(dev, data);
+               put_device(dev);
                if (error)
                        break;
        }
index 7608df83d6d1e0625a8b0de306a799dac62143d3..7bf38c418086e45aee6f7d6ba47f256eb65e47f6 100644 (file)
@@ -722,7 +722,8 @@ int i2c_register_driver(struct module *owner, struct i2c_driver *driver)
 
        INIT_LIST_HEAD(&driver->clients);
        /* Walk the adapters that are already present */
-       class_for_each_device(&i2c_adapter_class, driver, __attach_adapter);
+       class_for_each_device(&i2c_adapter_class, NULL, driver,
+                             __attach_adapter);
 
        mutex_unlock(&core_lock);
        return 0;
@@ -782,7 +783,8 @@ void i2c_del_driver(struct i2c_driver *driver)
 {
        mutex_lock(&core_lock);
 
-       class_for_each_device(&i2c_adapter_class, driver, __detach_adapter);
+       class_for_each_device(&i2c_adapter_class, NULL, driver,
+                             __detach_adapter);
 
        driver_unregister(&driver->driver);
        pr_debug("i2c-core: driver [%s] unregistered\n", driver->driver.name);
index 05710c7c12206aa1a9fcca8bad4db2eac3be7697..47c0d85e0f32126bfdb65e92eb53e20242a0c7c4 100644 (file)
@@ -1453,7 +1453,8 @@ static void nodemgr_suspend_ne(struct node_entry *ne)
        ne->in_limbo = 1;
        WARN_ON(device_create_file(&ne->device, &dev_attr_ne_in_limbo));
 
-       class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_driver_suspend);
+       class_for_each_device(&nodemgr_ud_class, NULL, ne,
+                             __nodemgr_driver_suspend);
 }
 
 
@@ -1462,7 +1463,8 @@ static void nodemgr_resume_ne(struct node_entry *ne)
        ne->in_limbo = 0;
        device_remove_file(&ne->device, &dev_attr_ne_in_limbo);
 
-       class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_driver_resume);
+       class_for_each_device(&nodemgr_ud_class, NULL, ne,
+                             __nodemgr_driver_resume);
        HPSB_DEBUG("Node resumed: ID:BUS[" NODE_BUS_FMT "]  GUID[%016Lx]",
                   NODE_BUS_ARGS(ne->host, ne->nodeid), (unsigned long long)ne->guid);
 }
@@ -1498,7 +1500,8 @@ static int __nodemgr_update_pdrv(struct device *dev, void *data)
 
 static void nodemgr_update_pdrv(struct node_entry *ne)
 {
-       class_for_each_device(&nodemgr_ud_class, ne, __nodemgr_update_pdrv);
+       class_for_each_device(&nodemgr_ud_class, NULL, ne,
+                             __nodemgr_update_pdrv);
 }
 
 
@@ -1591,7 +1594,8 @@ static void nodemgr_node_probe(struct host_info *hi, int generation)
         * while probes are time-consuming. (Well, those probes need some
         * improvement...) */
 
-       class_for_each_device(&nodemgr_ne_class, &param, __nodemgr_node_probe);
+       class_for_each_device(&nodemgr_ne_class, NULL, &param,
+                             __nodemgr_node_probe);
 
        /* If we had a bus reset while we were scanning the bus, it is
         * possible that we did not probe all nodes.  In that case, we
@@ -1826,7 +1830,7 @@ int nodemgr_for_each_host(void *data, int (*cb)(struct hpsb_host *, void *))
 
        hip.cb = cb;
        hip.data = data;
-       error = class_for_each_device(&hpsb_host_class, &hip,
+       error = class_for_each_device(&hpsb_host_class, NULL, &hip,
                                      __nodemgr_for_each_host);
 
        return error;
index a4892275659dc02ffb1d12b85d0774a86bda8b08..936bae560fa1f730255bde8a94c9493c953efdfd 100644 (file)
@@ -78,7 +78,7 @@ static void find_main_battery(void)
        main_battery = NULL;
        bp.main = main_battery;
 
-       error = class_for_each_device(power_supply_class, &bp,
+       error = class_for_each_device(power_supply_class, NULL, &bp,
                                      __find_main_battery);
        if (error) {
                main_battery = bp.main;
index af1633eb3b707c9c53c50e578f0ed5859ee69d96..cb1ccb4729210c1a3cfd8901bf7dea5c56117146 100644 (file)
@@ -41,7 +41,7 @@ static void power_supply_changed_work(struct work_struct *work)
 
        dev_dbg(psy->dev, "%s\n", __func__);
 
-       class_for_each_device(power_supply_class, psy,
+       class_for_each_device(power_supply_class, NULL, psy,
                              __power_supply_changed_work);
 
        power_supply_update_leds(psy);
@@ -79,7 +79,7 @@ int power_supply_am_i_supplied(struct power_supply *psy)
 {
        int error;
 
-       error = class_for_each_device(power_supply_class, psy,
+       error = class_for_each_device(power_supply_class, NULL, psy,
                                      __power_supply_am_i_supplied);
 
        dev_dbg(psy->dev, "%s %d\n", __func__, error);
index de178712e02c7c7c89b6cd02ed99c199bfae7964..6d5b351b29c9975bf7f78a7cd45337313a4cb2cd 100644 (file)
@@ -210,7 +210,8 @@ extern struct kobject *sysfs_dev_block_kobj;
 extern struct kobject *sysfs_dev_char_kobj;
 extern int __must_check class_register(struct class *class);
 extern void class_unregister(struct class *class);
-extern int class_for_each_device(struct class *class, void *data,
+extern int class_for_each_device(struct class *class, struct device *start,
+                                void *data,
                                 int (*fn)(struct device *dev, void *data));
 extern struct device *class_find_device(struct class *class, void *data,
                                        int (*match)(struct device *, void *));