PM: runtime: Add safety net to supplier device release
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 10 Dec 2021 16:10:13 +0000 (17:10 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 27 Jan 2022 10:04:44 +0000 (11:04 +0100)
commitfddbdd20c8e0bbc813bebebf82216a9bef22d29a
tree22d0b6e133b7e9b58b6b689e9e39c3a9675b33fe
parent4586d164c319a81aa98169bb863de5c3112f13e5
PM: runtime: Add safety net to supplier device release

[ Upstream commit d1579e61192e0e686faa4208500ef4c3b529b16c ]

Because refcount_dec_not_one() returns true if the target refcount
becomes saturated, it is generally unsafe to use its return value as
a loop termination condition, but that is what happens when a device
link's supplier device is released during runtime PM suspend
operations and on device link removal.

To address this, introduce pm_runtime_release_supplier() to be used
in the above cases which will check the supplier device's runtime
PM usage counter in addition to the refcount_dec_not_one() return
value, so the loop can be terminated in case the rpm_active refcount
value becomes invalid, and update the code in question to use it as
appropriate.

This change is not expected to have any visible functional impact.

Reported-by: Peter Zijlstra <peterz@infradead.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/base/core.c
drivers/base/power/runtime.c
include/linux/pm_runtime.h