[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <8e610c04-f21a-a73a-12a9-02b361e26da8@gmail.com>
Date: Wed, 23 Jan 2019 07:30:38 +0100
From: Heiner Kallweit <hkallweit1@...il.com>
To: Andrew Lunn <andrew@...n.ch>,
Florian Fainelli <f.fainelli@...il.com>,
David Miller <davem@...emloft.net>
Cc: "netdev@...r.kernel.org" <netdev@...r.kernel.org>,
"S-k, Shyam-sundar" <Shyam-sundar.S-k@....com>
Subject: [PATCH net-next v3 2/4] net: phy: warn if phy_start is called from
invalid state
phy_start() should be called from states PHY_READY or PHY_HALTED only.
Check for this to detect misbehaving drivers. Also the state machine
should be started only when being called from one of the valid states.
Some more background:
For all invalid states phy_start() basically was a no-op. All it did
was triggering a state machine run, but for all "running" states the
poll loop was active anyway. And if called from PHY_DOWN, the state
machine does nothing.
v3:
- extended commit message
Signed-off-by: Heiner Kallweit <hkallweit1@...il.com>
---
drivers/net/phy/phy.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index 3df6aadc5..fd928979b 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -861,9 +861,16 @@ void phy_start(struct phy_device *phydev)
mutex_lock(&phydev->lock);
+ if (phydev->state != PHY_READY && phydev->state != PHY_HALTED) {
+ WARN(1, "called from state %s\n",
+ phy_state_to_str(phydev->state));
+ goto out;
+ }
+
switch (phydev->state) {
case PHY_READY:
phydev->state = PHY_UP;
+ phy_start_machine(phydev);
break;
case PHY_HALTED:
/* if phy was suspended, bring the physical link up again */
@@ -877,13 +884,13 @@ void phy_start(struct phy_device *phydev)
}
phydev->state = PHY_RESUMING;
+ phy_start_machine(phydev);
break;
default:
break;
}
+out:
mutex_unlock(&phydev->lock);
-
- phy_start_machine(phydev);
}
EXPORT_SYMBOL(phy_start);
--
2.20.1
Powered by blists - more mailing lists