diff options
Diffstat (limited to 'drivers/base/class.c')
-rw-r--r-- | drivers/base/class.c | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/drivers/base/class.c b/drivers/base/class.c index 71ce3ff6bdf5..2eb7048003a8 100644 --- a/drivers/base/class.c +++ b/drivers/base/class.c | |||
@@ -256,11 +256,14 @@ char *make_class_name(const char *name, struct kobject *kobj) | |||
256 | /** | 256 | /** |
257 | * class_for_each_device - device iterator | 257 | * class_for_each_device - device iterator |
258 | * @class: the class we're iterating | 258 | * @class: the class we're iterating |
259 | * @start: the device to start with in the list, if any. | ||
259 | * @data: data for the callback | 260 | * @data: data for the callback |
260 | * @fn: function to be called for each device | 261 | * @fn: function to be called for each device |
261 | * | 262 | * |
262 | * Iterate over @class's list of devices, and call @fn for each, | 263 | * Iterate over @class's list of devices, and call @fn for each, |
263 | * passing it @data. | 264 | * passing it @data. If @start is set, the list iteration will start |
265 | * there, otherwise if it is NULL, the iteration starts at the | ||
266 | * beginning of the list. | ||
264 | * | 267 | * |
265 | * We check the return of @fn each time. If it returns anything | 268 | * We check the return of @fn each time. If it returns anything |
266 | * other than 0, we break out and return that value. | 269 | * other than 0, we break out and return that value. |
@@ -269,8 +272,8 @@ char *make_class_name(const char *name, struct kobject *kobj) | |||
269 | * re-acquired in @fn, otherwise it will self-deadlocking. For | 272 | * re-acquired in @fn, otherwise it will self-deadlocking. For |
270 | * example, calls to add or remove class members would be verboten. | 273 | * example, calls to add or remove class members would be verboten. |
271 | */ | 274 | */ |
272 | int class_for_each_device(struct class *class, void *data, | 275 | int class_for_each_device(struct class *class, struct device *start, |
273 | int (*fn)(struct device *, void *)) | 276 | void *data, int (*fn)(struct device *, void *)) |
274 | { | 277 | { |
275 | struct device *dev; | 278 | struct device *dev; |
276 | int error = 0; | 279 | int error = 0; |
@@ -279,12 +282,14 @@ int class_for_each_device(struct class *class, void *data, | |||
279 | return -EINVAL; | 282 | return -EINVAL; |
280 | down(&class->sem); | 283 | down(&class->sem); |
281 | list_for_each_entry(dev, &class->devices, node) { | 284 | list_for_each_entry(dev, &class->devices, node) { |
285 | if (start) { | ||
286 | if (start == dev) | ||
287 | start = NULL; | ||
288 | continue; | ||
289 | } | ||
282 | dev = get_device(dev); | 290 | dev = get_device(dev); |
283 | if (dev) { | 291 | error = fn(dev, data); |
284 | error = fn(dev, data); | 292 | put_device(dev); |
285 | put_device(dev); | ||
286 | } else | ||
287 | error = -ENODEV; | ||
288 | if (error) | 293 | if (error) |
289 | break; | 294 | break; |
290 | } | 295 | } |