Skip to content

Commit a200490

Browse files
hkallweitdavem330
authored andcommitted
net: phy: fix potential race in the phylib state machine
Russell reported the following race in the phylib state machine (quoting from his mail): if (phy_polling_mode(phydev) && phy_is_started(phydev)) phy_queue_state_machine(phydev, PHY_STATE_TIME); state = PHY_UP thread 0 thread 1 phy_disconnect() +-phy_is_started() phy_is_started() | `-phy_stop() +-phydev->state = PHY_HALTED `-phy_stop_machine() `-cancel_delayed_work_sync() phy_queue_state_machine() `-mod_delayed_work() At this point, the phydev->state_queue() has been added back onto the system workqueue despite phy_stop_machine() having been called and cancel_delayed_work_sync() called on it. Fix this by protecting the complete operation in thread 0. Fixes: 2b3e88e ("net: phy: improve phy state checking") Reported-by: Russell King - ARM Linux admin <linux@armlinux.org.uk> Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent a2fc9d7 commit a200490

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/net/phy/phy.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,10 @@ void phy_state_machine(struct work_struct *work)
985985
* state machine would be pointless and possibly error prone when
986986
* called from phy_disconnect() synchronously.
987987
*/
988+
mutex_lock(&phydev->lock);
988989
if (phy_polling_mode(phydev) && phy_is_started(phydev))
989990
phy_queue_state_machine(phydev, PHY_STATE_TIME);
991+
mutex_unlock(&phydev->lock);
990992
}
991993

992994
/**

0 commit comments

Comments
 (0)