]> git.itanic.dy.fi Git - linux-stable/commitdiff
PM: runtime: Resume the device earlier in __device_release_driver()
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 22 Oct 2020 15:38:22 +0000 (17:38 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 10 Nov 2020 11:39:11 +0000 (12:39 +0100)
commit 9226c504e364158a17a68ff1fe9d67d266922f50 upstream.

Since the device is resumed from runtime-suspend in
__device_release_driver() anyway, it is better to do that before
looking for busy managed device links from it to consumers, because
if there are any, device_links_unbind_consumers() will be called
and it will cause the consumer devices' drivers to unbind, so the
consumer devices will be runtime-resumed.  In turn, resuming each
consumer device will cause the supplier to be resumed and when the
runtime PM references from the given consumer to it are dropped, it
may be suspended.  Then, the runtime-resume of the next consumer
will cause the supplier to resume again and so on.

Update the code accordingly.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Fixes: 9ed9895370ae ("driver core: Functional dependencies tracking support")
Cc: All applicable <stable@vger.kernel.org> # All applicable
Tested-by: Xiang Chen <chenxiang66@hisilicon.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/dd.c

index d3d053ba857c42efab7803028d3f892a7abbb02c..97a93843ad6de73527523b200073b591d613c894 100644 (file)
@@ -1117,6 +1117,8 @@ static void __device_release_driver(struct device *dev, struct device *parent)
 
        drv = dev->driver;
        if (drv) {
+               pm_runtime_get_sync(dev);
+
                while (device_links_busy(dev)) {
                        __device_driver_unlock(dev, parent);
 
@@ -1128,12 +1130,12 @@ static void __device_release_driver(struct device *dev, struct device *parent)
                         * have released the driver successfully while this one
                         * was waiting, so check for that.
                         */
-                       if (dev->driver != drv)
+                       if (dev->driver != drv) {
+                               pm_runtime_put(dev);
                                return;
+                       }
                }
 
-               pm_runtime_get_sync(dev);
-
                driver_sysfs_remove(dev);
 
                if (dev->bus)