driver core: Do not call rpm_put_suppliers() in pm_runtime_drop_link()
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 1 Feb 2019 00:52:45 +0000 (01:52 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 1 Feb 2019 09:04:08 +0000 (10:04 +0100)
Calling rpm_put_suppliers() from pm_runtime_drop_link() is excessive
as it affects all suppliers of the consumer device and not just the
one pointed to by the device link being dropped.  Worst case it may
cause the consumer device to stop working unexpectedly.  Moreover, in
principle it is racy with respect to runtime PM of the consumer
device.

To avoid these problems drop runtime PM references on the particular
supplier pointed to by the link in question only and do that after
the link has been dropped from the consumer device's list of links to
suppliers, which is in device_link_free().

Fixes: a0504aecba76 ("PM / runtime: Drop usage count for suppliers at device link removal")
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/base/core.c
drivers/base/power/runtime.c

index d58ea075f807362cc5415c0268a0c14afde017ae..8c7327d4540655a92b1fc0ce406721e7187ad36d 100644 (file)
@@ -374,6 +374,9 @@ EXPORT_SYMBOL_GPL(device_link_add);
 
 static void device_link_free(struct device_link *link)
 {
+       while (refcount_dec_not_one(&link->rpm_active))
+               pm_runtime_put(link->supplier);
+
        put_device(link->consumer);
        put_device(link->supplier);
        kfree(link);
index 8bc9a432de7086db1746c63db2f75d7118254332..fd5c4a7b96f0dbb020976b41c72cf60b62b01129 100644 (file)
@@ -1611,8 +1611,6 @@ void pm_runtime_new_link(struct device *dev)
 
 void pm_runtime_drop_link(struct device *dev)
 {
-       rpm_put_suppliers(dev);
-
        spin_lock_irq(&dev->power.lock);
        WARN_ON(dev->power.links_count == 0);
        dev->power.links_count--;