aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
authormochel@digitalimplant.org <mochel@digitalimplant.org>2005-03-21 13:59:56 -0500
committerGreg Kroah-Hartman <gregkh@suse.de>2005-06-20 18:15:13 -0400
commitfae3cd00255e3e51ffd59fedb1bdb91ec96be395 (patch)
tree59e56a65f4b01f496436bd9b0720737ce1937db4 /drivers/base
parent07e4a3e27fe414980ddc85a358e5a56abc48b363 (diff)
[PATCH] Add driver_for_each_device().
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 ===================================================================
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/driver.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 3b269f7e5213..484fed1985aa 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -18,6 +18,41 @@
18#define to_dev(node) container_of(node, struct device, driver_list) 18#define to_dev(node) container_of(node, struct device, driver_list)
19#define to_drv(obj) container_of(obj, struct device_driver, kobj) 19#define to_drv(obj) container_of(obj, struct device_driver, kobj)
20 20
21
22/**
23 * driver_for_each_device - Iterator for devices bound to a driver.
24 * @drv: Driver we're iterating.
25 * @data: Data to pass to the callback.
26 * @fn: Function to call for each device.
27 *
28 * Take the bus's rwsem and iterate over the @drv's list of devices,
29 * calling @fn for each one.
30 */
31
32int driver_for_each_device(struct device_driver * drv, struct device * start,
33 void * data, int (*fn)(struct device *, void *))
34{
35 struct list_head * head;
36 struct device * dev;
37 int error = 0;
38
39 down_read(&drv->bus->subsys.rwsem);
40 head = &drv->devices;
41 dev = list_prepare_entry(start, head, driver_list);
42 list_for_each_entry_continue(dev, head, driver_list) {
43 get_device(dev);
44 error = fn(dev, data);
45 put_device(dev);
46 if (error)
47 break;
48 }
49 up_read(&drv->bus->subsys.rwsem);
50 return error;
51}
52
53EXPORT_SYMBOL(driver_for_each_device);
54
55
21/** 56/**
22 * driver_create_file - create sysfs file for driver. 57 * driver_create_file - create sysfs file for driver.
23 * @drv: driver. 58 * @drv: driver.