[PATCH] Add a semaphore to struct device to synchronize calls to its driver.
This adds a per-device semaphore that is taken before every call from the core to a driver method. This prevents e.g. simultaneous calls to the ->suspend() or ->resume() and ->probe() or ->release(), potentially saving a whole lot of headaches. It also moves us a step closer to removing the bus rwsem, since it protects the fields in struct device that are modified by the core. Signed-off-by: Patrick Mochel <mochel@digitalimplant.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
eb51b65005
commit
af70316af1
@@ -283,18 +283,22 @@ void device_bind_driver(struct device * dev)
|
||||
*/
|
||||
int driver_probe_device(struct device_driver * drv, struct device * dev)
|
||||
{
|
||||
int error = 0;
|
||||
|
||||
if (drv->bus->match && !drv->bus->match(dev, drv))
|
||||
return -ENODEV;
|
||||
|
||||
down(&dev->sem);
|
||||
dev->driver = drv;
|
||||
if (drv->probe) {
|
||||
int error = drv->probe(dev);
|
||||
error = drv->probe(dev);
|
||||
if (error) {
|
||||
dev->driver = NULL;
|
||||
up(&dev->sem);
|
||||
return error;
|
||||
}
|
||||
}
|
||||
|
||||
up(&dev->sem);
|
||||
device_bind_driver(dev);
|
||||
return 0;
|
||||
}
|
||||
@@ -385,7 +389,10 @@ void driver_attach(struct device_driver * drv)
|
||||
|
||||
void device_release_driver(struct device * dev)
|
||||
{
|
||||
struct device_driver * drv = dev->driver;
|
||||
struct device_driver * drv;
|
||||
|
||||
down(&dev->sem);
|
||||
drv = dev->driver;
|
||||
if (drv) {
|
||||
sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj));
|
||||
sysfs_remove_link(&dev->kobj, "driver");
|
||||
@@ -394,6 +401,7 @@ void device_release_driver(struct device * dev)
|
||||
drv->remove(dev);
|
||||
dev->driver = NULL;
|
||||
}
|
||||
up(&dev->sem);
|
||||
}
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user