diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2016-10-10 14:37:56 +0200 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2016-10-28 02:42:26 -0400 |
commit | 4bdb35506b89cbbd150c1baa284e7c191698241f (patch) | |
tree | 99969a36f3f967efa5d062252a464300c0f17328 /drivers/base/dd.c | |
parent | 7f847dd31736f1284538e54f46cf10e63929eb7f (diff) | |
download | linux-4bdb35506b89cbbd150c1baa284e7c191698241f.tar.bz2 |
driver core: Add a wrapper around __device_release_driver()
Add an internal wrapper around __device_release_driver() that will
acquire device locks and do the necessary checks before calling it.
The next patch will make use of it.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/base/dd.c')
-rw-r--r-- | drivers/base/dd.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/drivers/base/dd.c b/drivers/base/dd.c index d22a7260f42b..df4ab5509c04 100644 --- a/drivers/base/dd.c +++ b/drivers/base/dd.c @@ -811,6 +811,22 @@ static void __device_release_driver(struct device *dev) } } +static void device_release_driver_internal(struct device *dev, + struct device_driver *drv, + struct device *parent) +{ + if (parent) + device_lock(parent); + + device_lock(dev); + if (!drv || drv == dev->driver) + __device_release_driver(dev); + + device_unlock(dev); + if (parent) + device_unlock(parent); +} + /** * device_release_driver - manually detach device from driver. * @dev: device. @@ -825,9 +841,7 @@ void device_release_driver(struct device *dev) * within their ->remove callback for the same device, they * will deadlock right here. */ - device_lock(dev); - __device_release_driver(dev); - device_unlock(dev); + device_release_driver_internal(dev, NULL, NULL); } EXPORT_SYMBOL_GPL(device_release_driver); @@ -852,15 +866,7 @@ void driver_detach(struct device_driver *drv) dev = dev_prv->device; get_device(dev); spin_unlock(&drv->p->klist_devices.k_lock); - - if (dev->parent) /* Needed for USB */ - device_lock(dev->parent); - device_lock(dev); - if (dev->driver == drv) - __device_release_driver(dev); - device_unlock(dev); - if (dev->parent) - device_unlock(dev->parent); + device_release_driver_internal(dev, drv, dev->parent); put_device(dev); } } |