Commit 557aebd2 authored by Patrick Mochel's avatar Patrick Mochel

driver model: protect drivers' device list accesses with bus's rwsem.

Drivers must belong to bus, and each bus has an rwsem. Instead of mucking with
the device_lock spinlock, and dropping it on each iteration of the loop, we take 
the bus's lock (read, so multiple drivers can access their list at the same time)
around the entire walk of the list.
parent de9d4fa4
...@@ -16,26 +16,23 @@ int driver_for_each_dev(struct device_driver * drv, void * data, ...@@ -16,26 +16,23 @@ int driver_for_each_dev(struct device_driver * drv, void * data,
int (*callback)(struct device *, void * )) int (*callback)(struct device *, void * ))
{ {
struct list_head * node; struct list_head * node;
struct device * prev = NULL;
int error = 0; int error = 0;
get_driver(drv); drv = get_driver(drv);
spin_lock(&device_lock); if (drv) {
down_read(&drv->bus->rwsem);
list_for_each(node,&drv->devices) { list_for_each(node,&drv->devices) {
struct device * dev = get_device_locked(to_dev(node)); struct device * dev = get_device(to_dev(node));
if (dev) { if (dev) {
spin_unlock(&device_lock);
error = callback(dev,data); error = callback(dev,data);
if (prev) put_device(dev);
put_device(prev);
prev = dev;
spin_lock(&device_lock);
if (error) if (error)
break; break;
} }
} }
spin_unlock(&device_lock); up_read(&drv->bus->rwsem);
put_driver(drv); put_driver(drv);
}
return error; return error;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment