Thread (18 messages) 18 messages, 5 authors, 2017-12-04

[RFC net-next 3/4] net: phy: Force PHY_HALTED during phy_disconnect()

From: Florian Fainelli <f.fainelli@gmail.com>
Date: 2017-10-25 23:21:45
Subsystem: ethernet phy library, networking drivers, the rest · Maintainers: Andrew Lunn, Heiner Kallweit, "David S. Miller", Eric Dumazet, Jakub Kicinski, Paolo Abeni, Linus Torvalds

While debugging a crash reported by David Daney, we discovered that the
offending driver was calling phy_disconnect() without a prior call to
phy_stop() although it should have.

Add a WARN_ON() to catch such drivers, in order to invite their
maintainers to fix them, and also force the PHY state machine to
PHY_HALTED since we are about to disconnect anyway, there is nothing we
will be doing.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
 drivers/net/phy/phy_device.c | 5 +++++
 1 file changed, 5 insertions(+)
diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 67f25ac29025..69eb985c26fe 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -797,6 +797,11 @@ void phy_disconnect(struct phy_device *phydev)
 	if (phydev->irq > 0)
 		phy_stop_interrupts(phydev);
 
+	mutex_lock(&phydev->lock);
+	WARN_ON(phydev->state != PHY_HALTED);
+	phydev->state = PHY_HALTED;
+	mutex_unlock(&phydev->lock);
+
 	phy_stop_machine(phydev);
 
 	phydev->adjust_link = NULL;
-- 
2.9.3
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help