2002-06-13 15:16:53

by Arnd Bergmann

[permalink] [raw]
Subject: [patch] bad locking in {driver,bus}_for_each_{drv,dev}

Hi,

I just ran in a deadlock in driver_for_each_dev, where read_unlock
was called without the lock being held. The patch below avoids the
problem there and in the other two places I found it.

Arnd <><

--- linux-2.5.21/drivers/base/driver.c Thu Jun 13 19:00:48 2002
+++ drivers/base/driver.c Thu Jun 13 19:01:25 2002
@@ -31,6 +31,7 @@
dev = next;
if ((error = callback(dev,data))) {
put_device(dev);
+ read_lock(&drv->lock);
break;
}
read_lock(&drv->lock);
--- linux-2.5.21/drivers/base/bus.c Thu Jun 13 19:05:25 2002
+++ drivers/base/bus.c Thu Jun 13 19:06:01 2002
@@ -61,6 +61,7 @@
dev = next;
if ((error = callback(dev,data))) {
put_device(dev);
+ read_lock(&bus->lock);
break;
}
read_lock(&bus->lock);
@@ -96,6 +97,7 @@
drv = next;
if ((error = callback(drv,data))) {
put_driver(drv);
+ read_lock(&bus->lock);
break;
}
read_lock(&bus->lock);