[PATCH] net: phy: Fix premature resume by a PHY driver

From: Abid Ali
Date: Fri Jul 18 2025 - 11:42:43 EST


There are possibilities for phy_resume to be executed when the ethernet
interface is initially taken UP after bootup. This is harmless in most
cases, but the respective PHY driver`s resume callback cannot have any
logic that should only be executed if it was previously suspended.

In stmmac for instance, 2 entry points of phy_resume:
1. stmmac_open->phylink_of_phy_connect->phy_attach_direct->phy_resume
commit 1211ce530771 ("net: phy: resume/suspend PHYs on attach/detach")
This is not needed at the initial interface UP but required if the PHY
may suspend when the interface is taken DOWN.

2. stmmac_open->phylink_start->phy_start->__phy_resume
commit 9e573cfc35c6 ("net: phy: start interrupts in phy_start")
This patch does not introduce the __phy_resume in phy_start but removes
it from being conditional to PHY_HALTED. Now it fails to ensure if it
really needs to resume.

Prevent these duplicate access and provide logic exclusivity for resume
callback in a PHY driver.

Signed-off-by: Abid Ali <dev.nuvorolabs@xxxxxxxxx>
---
drivers/net/phy/phy_device.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c
index 73f9cb2e2844..68583bb74aec 100644
--- a/drivers/net/phy/phy_device.c
+++ b/drivers/net/phy/phy_device.c
@@ -1846,7 +1846,7 @@ int __phy_resume(struct phy_device *phydev)

lockdep_assert_held(&phydev->lock);

- if (!phydrv || !phydrv->resume)
+ if (!phydrv || !phydrv->resume && phydev->suspended)
return 0;

ret = phydrv->resume(phydev);

---
base-commit: 347e9f5043c89695b01e66b3ed111755afcf1911
change-id: 20250718-phy_resume-cc86109396cc

Best regards,
--
Abid Ali <dev.nuvorolabs@xxxxxxxxx>