]> err.no Git - linux-2.6/commitdiff
[PATCH] Add driver_for_each_device().
authormochel@digitalimplant.org <mochel@digitalimplant.org>
Mon, 21 Mar 2005 18:59:56 +0000 (10:59 -0800)
committerGreg Kroah-Hartman <gregkh@suse.de>
Mon, 20 Jun 2005 22:15:13 +0000 (15:15 -0700)
Now there's an iterator for accessing each device bound to a driver.

Signed-off-by: Patrick Mochel <mochel@digitalimplant.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Index: linux-2.6.12-rc2/drivers/base/driver.c
===================================================================

drivers/base/driver.c
include/linux/device.h

index 3b269f7e52135472c70b6102e17ca31a5b24c050..484fed1985aa215c2d6c83be1f249595bd650ac7 100644 (file)
 #define to_dev(node) container_of(node, struct device, driver_list)
 #define to_drv(obj) container_of(obj, struct device_driver, kobj)
 
+
+/**
+ *     driver_for_each_device - Iterator for devices bound to a driver.
+ *     @drv:   Driver we're iterating.
+ *     @data:  Data to pass to the callback.
+ *     @fn:    Function to call for each device.
+ *
+ *     Take the bus's rwsem and iterate over the @drv's list of devices,
+ *     calling @fn for each one.
+ */
+
+int driver_for_each_device(struct device_driver * drv, struct device * start, 
+                          void * data, int (*fn)(struct device *, void *))
+{
+       struct list_head * head;
+       struct device * dev;
+       int error = 0;
+
+       down_read(&drv->bus->subsys.rwsem);
+       head = &drv->devices;
+       dev = list_prepare_entry(start, head, driver_list);
+       list_for_each_entry_continue(dev, head, driver_list) {
+               get_device(dev);
+               error = fn(dev, data);
+               put_device(dev);
+               if (error)
+                       break;
+       }
+       up_read(&drv->bus->subsys.rwsem);
+       return error;
+}
+
+EXPORT_SYMBOL(driver_for_each_device);
+
+
 /**
  *     driver_create_file - create sysfs file for driver.
  *     @drv:   driver.
index 195b327f3e19d0ec6d4a09bca8656e4b65f9e2f4..10f5aa20e041699cd1dbf9d694b27d7a3b8485f3 100644 (file)
@@ -136,6 +136,9 @@ struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store)
 extern int driver_create_file(struct device_driver *, struct driver_attribute *);
 extern void driver_remove_file(struct device_driver *, struct driver_attribute *);
 
+extern int driver_for_each_device(struct device_driver * drv, struct device * start,
+                                 void * data, int (*fn)(struct device *, void *));
+
 
 /*
  * device classes