diff options
author | mochel@digitalimplant.org <mochel@digitalimplant.org> | 2005-03-21 13:41:04 -0500 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-06-20 18:15:12 -0400 |
commit | af70316af182f4716cc5eec7e0d27fc731d164bd (patch) | |
tree | 22fa4732c8270db8fd3f681355cd83e4b8088847 /drivers/base/bus.c | |
parent | eb51b65005737b777e0709683b061d5f82aefd97 (diff) |
[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>
Diffstat (limited to 'drivers/base/bus.c')
-rw-r--r-- | drivers/base/bus.c | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 80ce88de56fa..aa27f76d28cd 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c | |||
@@ -283,18 +283,22 @@ void device_bind_driver(struct device * dev) | |||
283 | */ | 283 | */ |
284 | int driver_probe_device(struct device_driver * drv, struct device * dev) | 284 | int driver_probe_device(struct device_driver * drv, struct device * dev) |
285 | { | 285 | { |
286 | int error = 0; | ||
287 | |||
286 | if (drv->bus->match && !drv->bus->match(dev, drv)) | 288 | if (drv->bus->match && !drv->bus->match(dev, drv)) |
287 | return -ENODEV; | 289 | return -ENODEV; |
288 | 290 | ||
291 | down(&dev->sem); | ||
289 | dev->driver = drv; | 292 | dev->driver = drv; |
290 | if (drv->probe) { | 293 | if (drv->probe) { |
291 | int error = drv->probe(dev); | 294 | error = drv->probe(dev); |
292 | if (error) { | 295 | if (error) { |
293 | dev->driver = NULL; | 296 | dev->driver = NULL; |
297 | up(&dev->sem); | ||
294 | return error; | 298 | return error; |
295 | } | 299 | } |
296 | } | 300 | } |
297 | 301 | up(&dev->sem); | |
298 | device_bind_driver(dev); | 302 | device_bind_driver(dev); |
299 | return 0; | 303 | return 0; |
300 | } | 304 | } |
@@ -385,7 +389,10 @@ void driver_attach(struct device_driver * drv) | |||
385 | 389 | ||
386 | void device_release_driver(struct device * dev) | 390 | void device_release_driver(struct device * dev) |
387 | { | 391 | { |
388 | struct device_driver * drv = dev->driver; | 392 | struct device_driver * drv; |
393 | |||
394 | down(&dev->sem); | ||
395 | drv = dev->driver; | ||
389 | if (drv) { | 396 | if (drv) { |
390 | sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj)); | 397 | sysfs_remove_link(&drv->kobj, kobject_name(&dev->kobj)); |
391 | sysfs_remove_link(&dev->kobj, "driver"); | 398 | sysfs_remove_link(&dev->kobj, "driver"); |
@@ -394,6 +401,7 @@ void device_release_driver(struct device * dev) | |||
394 | drv->remove(dev); | 401 | drv->remove(dev); |
395 | dev->driver = NULL; | 402 | dev->driver = NULL; |
396 | } | 403 | } |
404 | up(&dev->sem); | ||
397 | } | 405 | } |
398 | 406 | ||
399 | 407 | ||