aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/bus.c
diff options
context:
space:
mode:
authorHannes Reinecke <hare@suse.de>2012-04-16 09:06:25 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-18 18:39:52 -0400
commita15d49fd3094cff90e5410ca454a870e0a722fe1 (patch)
treef3e458fa4ce3524f756e0faa48d5ed2400c022bf /drivers/base/bus.c
parent97ec448aeadff55234368a89c4a07a7ef290a084 (diff)
driver core: check start node in klist_iter_init_node
klist_iter_init_node() takes a node as a start argument. However, this node might not be valid anymore. This patch updates the klist_iter_init_node() and dependent functions to return an error if so. All calling functions have been audited to check for a return code here. Signed-off-by: Hannes Reinecke <hare@suse.de> Cc: Greg Kroah-Hartmann <gregkh@linuxfoundation.org> Cc: Kay Sievers <kay@vrfy.org> Cc: Stable Kernel <stable@kernel.org> Cc: Linux Kernel <linux-kernel@vger.kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base/bus.c')
-rw-r--r--drivers/base/bus.c46
1 files changed, 29 insertions, 17 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 2bcef657a60c..76aed01a8b2c 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -296,11 +296,13 @@ 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 klist_iter_init_node(&bus->p->klist_devices, &i, 299 error = klist_iter_init_node(&bus->p->klist_devices, &i,
300 (start ? &start->p->knode_bus : NULL)); 300 (start ? &start->p->knode_bus : NULL));
301 while ((dev = next_device(&i)) && !error) 301 if (!error) {
302 error = fn(dev, data); 302 while ((dev = next_device(&i)) && !error)
303 klist_iter_exit(&i); 303 error = fn(dev, data);
304 klist_iter_exit(&i);
305 }
304 return error; 306 return error;
305} 307}
306EXPORT_SYMBOL_GPL(bus_for_each_dev); 308EXPORT_SYMBOL_GPL(bus_for_each_dev);
@@ -330,8 +332,10 @@ struct device *bus_find_device(struct bus_type *bus,
330 if (!bus) 332 if (!bus)
331 return NULL; 333 return NULL;
332 334
333 klist_iter_init_node(&bus->p->klist_devices, &i, 335 if (klist_iter_init_node(&bus->p->klist_devices, &i,
334 (start ? &start->p->knode_bus : NULL)); 336 (start ? &start->p->knode_bus : NULL)) < 0)
337 return NULL;
338
335 while ((dev = next_device(&i))) 339 while ((dev = next_device(&i)))
336 if (match(dev, data) && get_device(dev)) 340 if (match(dev, data) && get_device(dev))
337 break; 341 break;
@@ -384,7 +388,9 @@ struct device *subsys_find_device_by_id(struct bus_type *subsys, unsigned int id
384 return NULL; 388 return NULL;
385 389
386 if (hint) { 390 if (hint) {
387 klist_iter_init_node(&subsys->p->klist_devices, &i, &hint->p->knode_bus); 391 if (klist_iter_init_node(&subsys->p->klist_devices, &i,
392 &hint->p->knode_bus) < 0)
393 return NULL;
388 dev = next_device(&i); 394 dev = next_device(&i);
389 if (dev && dev->id == id && get_device(dev)) { 395 if (dev && dev->id == id && get_device(dev)) {
390 klist_iter_exit(&i); 396 klist_iter_exit(&i);
@@ -446,11 +452,13 @@ int bus_for_each_drv(struct bus_type *bus, struct device_driver *start,
446 if (!bus) 452 if (!bus)
447 return -EINVAL; 453 return -EINVAL;
448 454
449 klist_iter_init_node(&bus->p->klist_drivers, &i, 455 error = klist_iter_init_node(&bus->p->klist_drivers, &i,
450 start ? &start->p->knode_bus : NULL); 456 start ? &start->p->knode_bus : NULL);
451 while ((drv = next_driver(&i)) && !error) 457 if (!error) {
452 error = fn(drv, data); 458 while ((drv = next_driver(&i)) && !error)
453 klist_iter_exit(&i); 459 error = fn(drv, data);
460 klist_iter_exit(&i);
461 }
454 return error; 462 return error;
455} 463}
456EXPORT_SYMBOL_GPL(bus_for_each_drv); 464EXPORT_SYMBOL_GPL(bus_for_each_drv);
@@ -1111,15 +1119,19 @@ EXPORT_SYMBOL_GPL(bus_sort_breadthfirst);
1111 * otherwise if it is NULL, the iteration starts at the beginning of 1119 * otherwise if it is NULL, the iteration starts at the beginning of
1112 * the list. 1120 * the list.
1113 */ 1121 */
1114void subsys_dev_iter_init(struct subsys_dev_iter *iter, struct bus_type *subsys, 1122int subsys_dev_iter_init(struct subsys_dev_iter *iter, struct bus_type *subsys,
1115 struct device *start, const struct device_type *type) 1123 struct device *start, const struct device_type *type)
1116{ 1124{
1117 struct klist_node *start_knode = NULL; 1125 struct klist_node *start_knode = NULL;
1126 int error;
1118 1127
1119 if (start) 1128 if (start)
1120 start_knode = &start->p->knode_bus; 1129 start_knode = &start->p->knode_bus;
1121 klist_iter_init_node(&subsys->p->klist_devices, &iter->ki, start_knode); 1130 error = klist_iter_init_node(&subsys->p->klist_devices, &iter->ki,
1122 iter->type = type; 1131 start_knode);
1132 if (!error)
1133 iter->type = type;
1134 return error;
1123} 1135}
1124EXPORT_SYMBOL_GPL(subsys_dev_iter_init); 1136EXPORT_SYMBOL_GPL(subsys_dev_iter_init);
1125 1137