diff options
-rw-r--r-- | drivers/base/driver.c | 35 | ||||
-rw-r--r-- | include/linux/device.h | 3 |
2 files changed, 38 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 | |||
32 | int 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 | |||
53 | EXPORT_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. |
diff --git a/include/linux/device.h b/include/linux/device.h index 195b327f3e19..10f5aa20e041 100644 --- a/include/linux/device.h +++ b/include/linux/device.h | |||
@@ -136,6 +136,9 @@ struct driver_attribute driver_attr_##_name = __ATTR(_name,_mode,_show,_store) | |||
136 | extern int driver_create_file(struct device_driver *, struct driver_attribute *); | 136 | extern int driver_create_file(struct device_driver *, struct driver_attribute *); |
137 | extern void driver_remove_file(struct device_driver *, struct driver_attribute *); | 137 | extern void driver_remove_file(struct device_driver *, struct driver_attribute *); |
138 | 138 | ||
139 | extern int driver_for_each_device(struct device_driver * drv, struct device * start, | ||
140 | void * data, int (*fn)(struct device *, void *)); | ||
141 | |||
139 | 142 | ||
140 | /* | 143 | /* |
141 | * device classes | 144 | * device classes |