summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRussell King <rmk+kernel@armlinux.org.uk>2016-12-27 20:59:30 +0000
committerRussell King <rmk+kernel@armlinux.org.uk>2019-07-09 12:20:56 +0100
commit7f9a440a12a1cf16549d91f341922c2741f2091a (patch)
tree3f3bb2fdeb04c0e166336f734fc7959669b89378
parent0ecfebd2b52404ae0c54a878c872bb93363ada36 (diff)
phy: warn if phy_power_off() is called before PHY has been powered
Calling phy_power_off() before the PHY has been powered results in the phy's power_count going negative, which causes a subsequent call to phy_power_on() to be ignored. Moreover, we end up calling phy_pm_runtime_put() and potentially regulator_disable() unbalancing the runtime PM count and the regulator subsystems as well. Avoid this, and print a warning when it happens. This is an alternative solution to Marvell's "phy: update power_count only if phy actually was powered off/on" commit, which IMHO is papering over the bug. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk>
-rw-r--r--drivers/phy/phy-core.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index e3880c4a15f2..e64390e4a3ed 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -337,6 +337,11 @@ int phy_power_off(struct phy *phy)
return 0;
mutex_lock(&phy->mutex);
+ if (WARN_ON(phy->power_count == 0)) {
+ mutex_unlock(&phy->mutex);
+ return -EINVAL;
+ }
+
if (phy->power_count == 1 && phy->ops->power_off) {
ret = phy->ops->power_off(phy);
if (ret < 0) {