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) {
list_for_each(node,&drv->devices) { down_read(&drv->bus->rwsem);
struct device * dev = get_device_locked(to_dev(node)); list_for_each(node,&drv->devices) {
if (dev) { struct device * dev = get_device(to_dev(node));
spin_unlock(&device_lock); if (dev) {
error = callback(dev,data); error = callback(dev,data);
if (prev) put_device(dev);
put_device(prev); if (error)
prev = dev; break;
spin_lock(&device_lock); }
if (error)
break;
} }
up_read(&drv->bus->rwsem);
put_driver(drv);
} }
spin_unlock(&device_lock);
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