Skip to contentSkip to conversation

net: phy: fix race in genphy_update_link

PATCH Applied Heiner Kallweit 2 participants 2 messages Jul 31, 2019 – Aug 3, 2019

Subsystems (3)
lore
Share & tools
lore

Heiner Kallweit

author maintainer
#0 lore raw

PATCH 1/1 net: phy: fix race in genphy_update_link

In phy_start_aneg() autoneg is started, and immediately after that link and autoneg status are read. As reported in [0] it can happen that at time of this read the PHY has reset the "aneg complete" bit but not yet the "link up" bit, what can result in a false link-up detection. To fix this don't report link as up if we're in aneg mode and PHY doesn't signal "aneg complete".

[0] https://marc.info/?t=156413509900003&r=1&w=2

Fixes 4950c2ba49cc ("net: phy: fix autoneg mismatch case in genphy_read_status")
---
 drivers/net/phy/phy_device.c | 6 ++++++
 1 file changed, 6 insertions(+)
drivers/net/phy/phy_device.c +6 -0
index 6b5cb87f3..7ddd91df9 100644
@@ -1774,6 +1774,12 @@ int genphy_update_link(struct phy_device *phydev)
 	phydev->link = status & BMSR_LSTATUS ? 1 : 0;
 	phydev->autoneg_complete = status & BMSR_ANEGCOMPLETE ? 1 : 0;
 
+	/* Consider the case that autoneg was started and "aneg complete"
+	 * bit has been reset, but "link up" bit not yet.
+	 */
+	if (phydev->autoneg == AUTONEG_ENABLE && !phydev->autoneg_complete)
+		phydev->link = 0;
+
 	return 0;
 }
 EXPORT_SYMBOL(genphy_update_link);
Signature · 1 line
2.22.0
maintainer Applied
#1 lore raw

From: Heiner Kallweit <[email protected]>
Date: Wed, 31 Jul 2019 23:05:10 +0200

Quoted 7 lines

In phy_start_aneg() autoneg is started, and immediately after that link and autoneg status are read. As reported in [0] it can happen that at time of this read the PHY has reset the "aneg complete" bit but not yet the "link up" bit, what can result in a false link-up detection. To fix this don't report link as up if we're in aneg mode and PHY doesn't signal "aneg complete".

Quoted 6 lines

[0] https://marc.info/?t=156413509900003&r=1&w=2

Fixes 4950c2ba49cc ("net: phy: fix autoneg mismatch case in genphy_read_status")

Applied.