aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
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.