device core: Consolidate locking and unlocking of parent and device
Try to consolidate all of the locking and unlocking of both the parent and device when attaching or removing a driver from a given device. To do that I first consolidated the lock pattern into two functions __device_driver_lock and __device_driver_unlock. After doing that I then created functions specific to attaching and detaching the driver while acquiring these locks. By doing this I was able to reduce the number of spots where we touch need_parent_lock from 12 down to 4. This patch should produce no functional changes, it is meant to be a code clean-up/consolidation only. Reviewed-by: Luis Chamberlain <mcgrof@kernel.org> Reviewed-by: Bart Van Assche <bvanassche@acm.org> Reviewed-by: Dan Williams <dan.j.williams@intel.com> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Alexander Duyck <alexander.h.duyck@linux.intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:

committato da
Greg Kroah-Hartman

parent
3451a495ef
commit
ed88747c6c
@@ -187,11 +187,7 @@ static ssize_t unbind_store(struct device_driver *drv, const char *buf,
|
||||
|
||||
dev = bus_find_device_by_name(bus, NULL, buf);
|
||||
if (dev && dev->driver == drv) {
|
||||
if (dev->parent && dev->bus->need_parent_lock)
|
||||
device_lock(dev->parent);
|
||||
device_release_driver(dev);
|
||||
if (dev->parent && dev->bus->need_parent_lock)
|
||||
device_unlock(dev->parent);
|
||||
device_driver_detach(dev);
|
||||
err = count;
|
||||
}
|
||||
put_device(dev);
|
||||
@@ -214,13 +210,7 @@ static ssize_t bind_store(struct device_driver *drv, const char *buf,
|
||||
|
||||
dev = bus_find_device_by_name(bus, NULL, buf);
|
||||
if (dev && dev->driver == NULL && driver_match_device(drv, dev)) {
|
||||
if (dev->parent && bus->need_parent_lock)
|
||||
device_lock(dev->parent);
|
||||
device_lock(dev);
|
||||
err = driver_probe_device(drv, dev);
|
||||
device_unlock(dev);
|
||||
if (dev->parent && bus->need_parent_lock)
|
||||
device_unlock(dev->parent);
|
||||
err = device_driver_attach(drv, dev);
|
||||
|
||||
if (err > 0) {
|
||||
/* success */
|
||||
@@ -773,13 +763,8 @@ EXPORT_SYMBOL_GPL(bus_rescan_devices);
|
||||
*/
|
||||
int device_reprobe(struct device *dev)
|
||||
{
|
||||
if (dev->driver) {
|
||||
if (dev->parent && dev->bus->need_parent_lock)
|
||||
device_lock(dev->parent);
|
||||
device_release_driver(dev);
|
||||
if (dev->parent && dev->bus->need_parent_lock)
|
||||
device_unlock(dev->parent);
|
||||
}
|
||||
if (dev->driver)
|
||||
device_driver_detach(dev);
|
||||
return bus_rescan_devices_helper(dev, NULL);
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(device_reprobe);
|
||||
|
Fai riferimento in un nuovo problema
Block a user