[PATCH 4/4] Driver core: bus_rescan_devices improper locking

From: Dmitry Torokhov
Date: Sat Oct 30 2004 - 03:41:58 EST



===================================================================


ChangeSet@xxxxxx, 2004-10-30 03:13:25-05:00, dtor_core@xxxxxxxxxxxxx
Driver core: bus_rescan_devices() should take write lock to guarantee
that 2 threads will not probe same device and therefore
can not be implemented with bus_for_each_dev().

Signed-off-by: Dmitry Torokhov <dtor@xxxxxxx>


bus.c | 24 +++++++++++-------------
1 files changed, 11 insertions(+), 13 deletions(-)


===================================================================



diff -Nru a/drivers/base/bus.c b/drivers/base/bus.c
--- a/drivers/base/bus.c 2004-10-30 03:15:58 -05:00
+++ b/drivers/base/bus.c 2004-10-30 03:15:58 -05:00
@@ -571,18 +571,6 @@
}


-/* Helper for bus_rescan_devices's iter */
-static int bus_rescan_devices_helper(struct device *dev, void *data)
-{
- int *count = data;
-
- if (!dev->driver && device_attach(dev))
- (*count)++;
-
- return 0;
-}
-
-
/**
* bus_rescan_devices - rescan devices on the bus for possible drivers
* @bus: the bus to scan.
@@ -594,9 +582,19 @@
*/
int bus_rescan_devices(struct bus_type * bus)
{
+ struct device *dev;
int count = 0;

- bus_for_each_dev(bus, NULL, &count, bus_rescan_devices_helper);
+ if (!(bus = get_bus(bus)))
+ return 0;
+
+ down_write(&bus->subsys.rwsem);
+ list_for_each_entry(dev, &bus->devices.list, bus_list) {
+ if (!dev->driver && device_attach(dev))
+ count++;
+ }
+ up_write(&bus->subsys.rwsem);
+ put_bus(bus);

return count;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/