diff options
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/base/bus.c | 14 | ||||
-rw-r--r-- | drivers/base/core.c | 1 | ||||
-rw-r--r-- | drivers/base/power/resume.c | 8 | ||||
-rw-r--r-- | drivers/base/power/suspend.c | 3 |
4 files changed, 20 insertions, 6 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c index 80ce88de56f..aa27f76d28c 100644 --- a/drivers/base/bus.c +++ b/drivers/base/bus.c @@ -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); } diff --git a/drivers/base/core.c b/drivers/base/core.c index a293a788abd..93440824b80 100644 --- a/drivers/base/core.c +++ b/drivers/base/core.c @@ -212,6 +212,7 @@ void device_initialize(struct device *dev) INIT_LIST_HEAD(&dev->driver_list); INIT_LIST_HEAD(&dev->bus_list); INIT_LIST_HEAD(&dev->dma_pools); + init_MUTEX(&dev->sem); } /** diff --git a/drivers/base/power/resume.c b/drivers/base/power/resume.c index 26468971ef5..bdd96b03b88 100644 --- a/drivers/base/power/resume.c +++ b/drivers/base/power/resume.c @@ -22,6 +22,9 @@ extern int sysdev_resume(void); int resume_device(struct device * dev) { + int error = 0; + + down(&dev->sem); if (dev->power.pm_parent && dev->power.pm_parent->power.power_state) { dev_err(dev, "PM: resume from %d, parent %s still %d\n", @@ -31,9 +34,10 @@ int resume_device(struct device * dev) } if (dev->bus && dev->bus->resume) { dev_dbg(dev,"resuming\n"); - return dev->bus->resume(dev); + error = dev->bus->resume(dev); } - return 0; + up(&dev->sem); + return error; } diff --git a/drivers/base/power/suspend.c b/drivers/base/power/suspend.c index 0ec44ef840b..807e13fb205 100644 --- a/drivers/base/power/suspend.c +++ b/drivers/base/power/suspend.c @@ -39,6 +39,7 @@ int suspend_device(struct device * dev, pm_message_t state) { int error = 0; + down(&dev->sem); if (dev->power.power_state) { dev_dbg(dev, "PM: suspend %d-->%d\n", dev->power.power_state, state); @@ -58,7 +59,7 @@ int suspend_device(struct device * dev, pm_message_t state) dev_dbg(dev, "suspending\n"); error = dev->bus->suspend(dev, state); } - + up(&dev->sem); return error; } |