aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/base')
-rw-r--r--drivers/base/bus.c46
-rw-r--r--drivers/base/class.c32
-rw-r--r--drivers/base/driver.c18
3 files changed, 36 insertions, 60 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 76aed01a8b2c..2bcef657a60c 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -296,13 +296,11 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start,
296 if (!bus) 296 if (!bus)
297 return -EINVAL; 297 return -EINVAL;
298 298
299 error = klist_iter_init_node(&bus->p->klist_devices, &i, 299 klist_iter_init_node(&bus->p->klist_devices, &i,
300 (start ? &start->p->knode_bus : NULL)); 300 (start ? &start->p->knode_bus : NULL));
301 if (!error) { 301 while ((dev = next_device(&i)) && !error)
302 while ((dev = next_device(&i)) && !error) 302 error = fn(dev, data);
303 error = fn(dev, data); 303 klist_iter_exit(&i);
304 klist_iter_exit(&i);
305 }
306 return error; 304 return error;
307} 305}
308EXPORT_SYMBOL_GPL(bus_for_each_dev); 306EXPORT_SYMBOL_GPL(bus_for_each_dev);
@@ -332,10 +330,8 @@ struct device *bus_find_device(struct bus_type *bus,
332 if (!bus) 330 if (!bus)
333 return NULL; 331 return NULL;
334 332
335 if (klist_iter_init_node(&bus->p->klist_devices, &i, 333 klist_iter_init_node(&bus->p->klist_devices, &i,
336 (start ? &start->p->knode_bus : NULL)) < 0) 334 (start ? &start->p->knode_bus : NULL));
337 return NULL;
338
339 while ((dev = next_device(&i))) 335 while ((dev = next_device(&i)))
340 if (match(dev, data) && get_device(dev)) 336 if (match(dev, data) && get_device(dev))
341 break; 337 break;
@@ -388,9 +384,7 @@ struct device *subsys_find_device_by_id(struct bus_type *subsys, unsigned int id
388 return NULL; 384 return NULL;
389 385
390 if (hint) { 386 if (hint) {
391 if (klist_iter_init_node(&subsys->p->klist_devices, &i, 387 klist_iter_init_node(&subsys->p->klist_devices, &i, &hint->p->knode_bus);
392 &hint->p->knode_bus) < 0)
393 return NULL;
394 dev = next_device(&i); 388 dev = next_device(&i);
395 if (dev && dev->id == id && get_device(dev)) { 389 if (dev && dev->id == id && get_device(dev)) {
396 klist_iter_exit(&i); 390 klist_iter_exit(&i);
@@ -452,13 +446,11 @@ int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
452 if (!bus) 446 if (!bus)
453 return -EINVAL; 447 return -EINVAL;
454 448
455 error = klist_iter_init_node(&bus->p->klist_drivers, &i, 449 klist_iter_init_node(&bus->p->klist_drivers, &i,
456 start ? &start->p->knode_bus : NULL); 450 start ? &start->p->knode_bus : NULL);
457 if (!error) { 451 while ((drv = next_driver(&i)) && !error)
458 while ((drv = next_driver(&i)) && !error) 452 error = fn(drv, data);
459 error = fn(drv, data); 453 klist_iter_exit(&i);
460 klist_iter_exit(&i);
461 }
462 return error; 454 return error;
463} 455}
464EXPORT_SYMBOL_GPL(bus_for_each_drv); 456EXPORT_SYMBOL_GPL(bus_for_each_drv);
@@ -1119,19 +1111,15 @@ EXPORT_SYMBOL_GPL(bus_sort_breadthfirst);
1119 * otherwise if it is NULL, the iteration starts at the beginning of 1111 * otherwise if it is NULL, the iteration starts at the beginning of
1120 * the list. 1112 * the list.
1121 */ 1113 */
1122int subsys_dev_iter_init(struct subsys_dev_iter *iter, struct bus_type *subsys, 1114void subsys_dev_iter_init(struct subsys_dev_iter *iter, struct bus_type *subsys,
1123 struct device *start, const struct device_type *type) 1115 struct device *start, const struct device_type *type)
1124{ 1116{
1125 struct klist_node *start_knode = NULL; 1117 struct klist_node *start_knode = NULL;
1126 int error;
1127 1118
1128 if (start) 1119 if (start)
1129 start_knode = &start->p->knode_bus; 1120 start_knode = &start->p->knode_bus;
1130 error = klist_iter_init_node(&subsys->p->klist_devices, &iter->ki, 1121 klist_iter_init_node(&subsys->p->klist_devices, &iter->ki, start_knode);
1131 start_knode); 1122 iter->type = type;
1132 if (!error)
1133 iter->type = type;
1134 return error;
1135} 1123}
1136EXPORT_SYMBOL_GPL(subsys_dev_iter_init); 1124EXPORT_SYMBOL_GPL(subsys_dev_iter_init);
1137 1125
diff --git a/drivers/base/class.c b/drivers/base/class.c
index 23dbc661d4a0..03243d4002fd 100644
--- a/drivers/base/class.c
+++ b/drivers/base/class.c
@@ -301,20 +301,15 @@ void class_destroy(struct class *cls)
301 * otherwise if it is NULL, the iteration starts at the beginning of 301 * otherwise if it is NULL, the iteration starts at the beginning of
302 * the list. 302 * the list.
303 */ 303 */
304int class_dev_iter_init(struct class_dev_iter *iter, struct class *class, 304void class_dev_iter_init(struct class_dev_iter *iter, struct class *class,
305 struct device *start, const struct device_type *type) 305 struct device *start, const struct device_type *type)
306{ 306{
307 struct klist_node *start_knode = NULL; 307 struct klist_node *start_knode = NULL;
308 int error;
309 308
310 if (start) 309 if (start)
311 start_knode = &start->knode_class; 310 start_knode = &start->knode_class;
312 error = klist_iter_init_node(&class->p->klist_devices, &iter->ki, 311 klist_iter_init_node(&class->p->klist_devices, &iter->ki, start_knode);
313 start_knode); 312 iter->type = type;
314 if (!error)
315 iter->type = type;
316
317 return error;
318} 313}
319EXPORT_SYMBOL_GPL(class_dev_iter_init); 314EXPORT_SYMBOL_GPL(class_dev_iter_init);
320 315
@@ -392,15 +387,14 @@ int class_for_each_device(struct class *class, struct device *start,
392 return -EINVAL; 387 return -EINVAL;
393 } 388 }
394 389
395 error = class_dev_iter_init(&iter, class, start, NULL); 390 class_dev_iter_init(&iter, class, start, NULL);
396 if (!error) { 391 while ((dev = class_dev_iter_next(&iter))) {
397 while ((dev = class_dev_iter_next(&iter))) { 392 error = fn(dev, data);
398 error = fn(dev, data); 393 if (error)
399 if (error) 394 break;
400 break;
401 }
402 class_dev_iter_exit(&iter);
403 } 395 }
396 class_dev_iter_exit(&iter);
397
404 return error; 398 return error;
405} 399}
406EXPORT_SYMBOL_GPL(class_for_each_device); 400EXPORT_SYMBOL_GPL(class_for_each_device);
@@ -440,9 +434,7 @@ struct device *class_find_device(struct class *class, struct device *start,
440 return NULL; 434 return NULL;
441 } 435 }
442 436
443 if (class_dev_iter_init(&iter, class, start, NULL) < 0) 437 class_dev_iter_init(&iter, class, start, NULL);
444 return NULL;
445
446 while ((dev = class_dev_iter_next(&iter))) { 438 while ((dev = class_dev_iter_next(&iter))) {
447 if (match(dev, data)) { 439 if (match(dev, data)) {
448 get_device(dev); 440 get_device(dev);
diff --git a/drivers/base/driver.c b/drivers/base/driver.c
index 16f6dd2c4403..3ec3896c83a6 100644
--- a/drivers/base/driver.c
+++ b/drivers/base/driver.c
@@ -49,13 +49,11 @@ int driver_for_each_device(struct device_driver *drv, struct device *start,
49 if (!drv) 49 if (!drv)
50 return -EINVAL; 50 return -EINVAL;
51 51
52 error = klist_iter_init_node(&drv->p->klist_devices, &i, 52 klist_iter_init_node(&drv->p->klist_devices, &i,
53 start ? &start->p->knode_driver : NULL); 53 start ? &start->p->knode_driver : NULL);
54 if (!error) { 54 while ((dev = next_device(&i)) && !error)
55 while ((dev = next_device(&i)) && !error) 55 error = fn(dev, data);
56 error = fn(dev, data); 56 klist_iter_exit(&i);
57 klist_iter_exit(&i);
58 }
59 return error; 57 return error;
60} 58}
61EXPORT_SYMBOL_GPL(driver_for_each_device); 59EXPORT_SYMBOL_GPL(driver_for_each_device);
@@ -85,10 +83,8 @@ struct device *driver_find_device(struct device_driver *drv,
85 if (!drv) 83 if (!drv)
86 return NULL; 84 return NULL;
87 85
88 if (klist_iter_init_node(&drv->p->klist_devices, &i, 86 klist_iter_init_node(&drv->p->klist_devices, &i,
89 (start ? &start->p->knode_driver : NULL)) < 0) 87 (start ? &start->p->knode_driver : NULL));
90 return NULL;
91
92 while ((dev = next_device(&i))) 88 while ((dev = next_device(&i)))
93 if (match(dev, data) && get_device(dev)) 89 if (match(dev, data) && get_device(dev))
94 break; 90 break;