Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: dsa: mv88e6xxx: Avoid uninitialized value on MDIO read error
@ 2026-08-15 15:17 Ruoyu Wang
  0 siblings, 0 replies; only message in thread
From: Ruoyu Wang @ 2026-08-15 15:17 UTC (permalink / raw)
  To: Andrew Lunn, Vladimir Oltean, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni
  Cc: netdev, linux-kernel, Ruoyu Wang

mv88e6xxx_mdio_read() applies the internal PHY model-number workaround
before returning a Clause 22 read error. Since the PHY read may leave
val untouched on failure, the workaround can consume an uninitialized
value.

Return the PHY read error immediately after dropping the register lock.
Successful reads continue through the workaround and return val as
before.

This issue was found by a static analysis checker and confirmed by
manual source review.

Assisted-by: unnamed:deepseek-v4-pro typestate
Signed-off-by: Ruoyu Wang <ruoyuw560@gmail.com>

---
Changes in v2:
- Return immediately on PHY read errors.
- Target net-next and drop the Fixes tag, as requested.
- Add the Assisted-by tag.

v1: https://lore.kernel.org/r/20260814134006.1386372-1-ruoyuw560@gmail.com/
---
 drivers/net/dsa/mv88e6xxx/chip.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c
index 80b877c74513d6..432285e2881715 100644
--- a/drivers/net/dsa/mv88e6xxx/chip.c
+++ b/drivers/net/dsa/mv88e6xxx/chip.c
@@ -3769,6 +3769,9 @@ static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
 	err = chip->info->ops->phy_read(chip, bus, phy, reg, &val);
 	mv88e6xxx_reg_unlock(chip);
 
+	if (err)
+		return err;
+
 	/* Some internal PHYs don't have a model number. */
 	if (reg == MII_PHYSID2 && !(val & 0x3f0) &&
 	    chip->info->family < ARRAY_SIZE(family_prod_id_table)) {
@@ -3777,7 +3780,7 @@ static int mv88e6xxx_mdio_read(struct mii_bus *bus, int phy, int reg)
 			val |= prod_id >> 4;
 	}
 
-	return err ? err : val;
+	return val;
 }
 
 static int mv88e6xxx_mdio_read_c45(struct mii_bus *bus, int phy, int devad,
-- 
2.51.0


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2026-08-15 15:17 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-15 15:17 [PATCH net-next v2] net: dsa: mv88e6xxx: Avoid uninitialized value on MDIO read error Ruoyu Wang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox