Skip to content

Commit e0d1c55

Browse files
Russell King (Oracle)kuba-moo
authored andcommitted
net: phy: fix phy_uses_state_machine()
The blamed commit changed the conditions which phylib uses to stop and start the state machine in the suspend and resume paths, and while improving it, has caused two issues. The original code used this test: phydev->attached_dev && phydev->adjust_link and if true, the paths would handle the PHY state machine. This test evaluates true for normal drivers that are using phylib directly while the PHY is attached to the network device, but false in all other cases, which include the following cases: - when the PHY has never been attached to a network device. - when the PHY has been detached from a network device (as phy_detach() sets phydev->attached_dev to NULL, phy_disconnect() calls phy_detach() and additionally sets phydev->adjust_link NULL.) - when phylink is using the driver (as phydev->adjust_link is NULL.) Only the third case was incorrect, and the blamed commit attempted to fix this by changing this test to (simplified for brevity, see phy_uses_state_machine()): phydev->phy_link_change == phy_link_change ? phydev->attached_dev && phydev->adjust_link : true However, this also incorrectly evaluates true in the first two cases. Fix the first case by ensuring that phy_uses_state_machine() returns false when phydev->phy_link_change is NULL. Fix the second case by ensuring that phydev->phy_link_change is set to NULL when phy_detach() is called. Reported-by: Xu Yang <xu.yang_2@nxp.com> Link: https://lore.kernel.org/r/20250806082931.3289134-1-xu.yang_2@nxp.com Fixes: fc75ea2 ("net: phy: allow MDIO bus PM ops to start/stop state machine for phylink-controlled PHY") Signed-off-by: Russell King (Oracle) <rmk+kernel@armlinux.org.uk> Reviewed-by: Vladimir Oltean <vladimir.oltean@nxp.com> Link: https://patch.msgid.link/E1uvMEz-00000003Aoe-3qWe@rmk-PC.armlinux.org.uk Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent e3c674d commit e0d1c55

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

drivers/net/phy/phy_device.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ static bool phy_uses_state_machine(struct phy_device *phydev)
287287
if (phydev->phy_link_change == phy_link_change)
288288
return phydev->attached_dev && phydev->adjust_link;
289289

290-
/* phydev->phy_link_change is implicitly phylink_phy_change() */
291-
return true;
290+
return !!phydev->phy_link_change;
292291
}
293292

294293
static bool mdio_bus_phy_may_suspend(struct phy_device *phydev)
@@ -1864,6 +1863,8 @@ void phy_detach(struct phy_device *phydev)
18641863
phydev->attached_dev = NULL;
18651864
phy_link_topo_del_phy(dev, phydev);
18661865
}
1866+
1867+
phydev->phy_link_change = NULL;
18671868
phydev->phylink = NULL;
18681869

18691870
if (!phydev->is_on_sfp_module)

0 commit comments

Comments
 (0)