diff options
Diffstat (limited to 'drivers/base/driver.c')
-rw-r--r-- | drivers/base/driver.c | 39 |
1 files changed, 38 insertions, 1 deletions
diff --git a/drivers/base/driver.c b/drivers/base/driver.c index 3b269f7e5213..1b645886e9eb 100644 --- a/drivers/base/driver.c +++ b/drivers/base/driver.c | |||
@@ -18,6 +18,43 @@ | |||
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 | static struct device * next_device(struct klist_iter * i) | ||
23 | { | ||
24 | struct klist_node * n = klist_next(i); | ||
25 | return n ? container_of(n, struct device, knode_driver) : NULL; | ||
26 | } | ||
27 | |||
28 | /** | ||
29 | * driver_for_each_device - Iterator for devices bound to a driver. | ||
30 | * @drv: Driver we're iterating. | ||
31 | * @data: Data to pass to the callback. | ||
32 | * @fn: Function to call for each device. | ||
33 | * | ||
34 | * Iterate over the @drv's list of devices calling @fn for each one. | ||
35 | */ | ||
36 | |||
37 | int driver_for_each_device(struct device_driver * drv, struct device * start, | ||
38 | void * data, int (*fn)(struct device *, void *)) | ||
39 | { | ||
40 | struct klist_iter i; | ||
41 | struct device * dev; | ||
42 | int error = 0; | ||
43 | |||
44 | if (!drv) | ||
45 | return -EINVAL; | ||
46 | |||
47 | klist_iter_init_node(&drv->klist_devices, &i, | ||
48 | start ? &start->knode_driver : NULL); | ||
49 | while ((dev = next_device(&i)) && !error) | ||
50 | error = fn(dev, data); | ||
51 | klist_iter_exit(&i); | ||
52 | return error; | ||
53 | } | ||
54 | |||
55 | EXPORT_SYMBOL_GPL(driver_for_each_device); | ||
56 | |||
57 | |||
21 | /** | 58 | /** |
22 | * driver_create_file - create sysfs file for driver. | 59 | * driver_create_file - create sysfs file for driver. |
23 | * @drv: driver. | 60 | * @drv: driver. |
@@ -85,7 +122,7 @@ void put_driver(struct device_driver * drv) | |||
85 | */ | 122 | */ |
86 | int driver_register(struct device_driver * drv) | 123 | int driver_register(struct device_driver * drv) |
87 | { | 124 | { |
88 | INIT_LIST_HEAD(&drv->devices); | 125 | klist_init(&drv->klist_devices); |
89 | init_completion(&drv->unloaded); | 126 | init_completion(&drv->unloaded); |
90 | return bus_add_driver(drv); | 127 | return bus_add_driver(drv); |
91 | } | 128 | } |