net: phy: et1011c: don't write an error code to the config register
Subsystems (3)
PATCH v2 1/1 net: phy: et1011c: don't write an error code to the config register
phy_read() can return a negative error code. Use an int and check both reads before using their results.
Found with LLM help; fake-MDIO KUnit error-injection tests passed (6/6, KASAN). No hardware testing.
---
v2: Drop Fixes and shorten the commit message; no code changes.
v1: https://lore.kernel.org/netdev/[email protected]/
drivers/net/phy/et1011c.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/phy/et1011c.c +7 -1
@@ -62,16 +62,22 @@ static int et1011c_read_status(struct phy_device *phydev) {static int speed;int ret; -u32 val; +int val; ret =genphy_read_status (phydev);if (speed != phydev->speed) { speed = phydev->speed; val =phy_read (phydev,ET1011C_STATUS_REG ); +if (val <0 ) +return val; +if ((val &ET1011C_SPEED_MASK ) ==ET1011C_GIGABIT_SPEED ) { val =phy_read (phydev,ET1011C_CONFIG_REG ); +if (val <0 ) +return val; + val &= ~ET1011C_TX_FIFO_MASK ; phy_write(phydev, ET1011C_CONFIG_REG, val | ET1011C_GMII_INTERFACE |
base-commit: d1f4b7c6b997c29de67ad7178ababac2328cb1b4
Quoted 6 lines · Elias Pukari
phy_read()can return a negative error code. Use an int and check both reads before using their results.Found with LLM help; fake-MDIO KUnit error-injection tests passed (6/6, KASAN). No hardware testing.
Signed-off-by Elias Pukari <[email protected]>
Andrew
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).
- [Medium] net: phy: et1011c: premature speed update in et1011c_read_status()
--
Quoted 19 lines
drivers/net/phy/et1011c.c +3
-1@@ -62,16 +62,22 @@ static int et1011c_read_status(struct phy_device *phydev) {static int speed;int ret; -u32 val; +int val; ret =genphy_read_status (phydev);if (speed != phydev->speed) { speed = phydev->speed; val =phy_read (phydev,ET1011C_STATUS_REG ); +if (val <0 ) +return val;
drivers/net/phy/et1011c.c static int et1011c_read_status(struct phy_device *phydev) · line 83
Quoted 10 lines
drivers/net/phy/et1011c.c +4
-0+if ((val &ET1011C_SPEED_MASK ) ==ET1011C_GIGABIT_SPEED ) { val =phy_read (phydev,ET1011C_CONFIG_REG ); +if (val <0 ) +return val; + val &= ~ET1011C_TX_FIFO_MASK ; phy_write(phydev, ET1011C_CONFIG_REG, val | ET1011C_GMII_INTERFACE |
[Severity: Medium]
With the new early returns, et1011c_read_status() updates the static speed cache to phydev->speed before either phy_read() is attempted.
Suppose the read of ET1011C_STATUS_REG or ET1011C_CONFIG_REG fails while the link comes up at 1000Mbps. We return the error without programming ET1011C_CONFIG_REG, but speed already equals phydev->speed. On the next poll the speed != phydev->speed test is false, so the block is skipped. ET1011C_GMII_INTERFACE, ET1011C_SYS_CLK_EN and ET1011C_TX_FIFO_DEPTH_16 are then never applied for that gigabit link.
The error path in _phy_state_machine() does not help either. Entering PHY_ERROR clears phydev->link but leaves phydev->speed alone, so a link that comes back at the same speed will not retrigger the write.
Could speed be updated only after the reads (and ideally the phy_write()) have succeeded, so that a transient MDIO error is retried on the next poll? Or is there a reason the cache has to be set before the register accesses?
Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261115180735.649299-1-elias.pukari%40gmail.com
On v2, an injected MDIO read error put the PHY in PHY_ERROR, and a restart at the same speed skipped the configuration write. I'll send v3 to cache the speed only after configuration succeeds.
pw-bot: cr