lkml.org 
[lkml]   [2012]   [Apr]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH] driver core: check 'start' argument in bus iterators
Date
bus_for_each_dev() and bus_find_device() both take a 'start'
argument to start the iteration at a specific list entry.
However, this list entry might already been detached by
the time these functions are called.
So we need to check if the arguments are still valid.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Cc: Greg Kroah-Hartmann <gregkh@linuxfoundation.org>
Cc: Kay Sievers <ksievers@vrfy.org>
Cc: Stable Kernel <stable@kernel.org>

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 26a06b8..264e498 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -297,6 +297,9 @@ int bus_for_each_dev(struct bus_type *bus, struct device *start,
if (!bus)
return -EINVAL;

+ if (start && !klist_node_attached(&start->p->knode_bus))
+ return -ENODEV;
+
klist_iter_init_node(&bus->p->klist_devices, &i,
(start ? &start->p->knode_bus : NULL));
while ((dev = next_device(&i)) && !error)
@@ -331,6 +334,9 @@ struct device *bus_find_device(struct bus_type *bus,
if (!bus)
return NULL;

+ if (start && !klist_node_attached(&start->p->knode_bus))
+ return NULL;
+
klist_iter_init_node(&bus->p->klist_devices, &i,
(start ? &start->p->knode_bus : NULL));
while ((dev = next_device(&i)))

\
 
 \ /
  Last update: 2012-04-16 12:51    [W:2.178 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site