]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
net: dsa: mt7530: check bus->read() errors in the MDIO regmap backend
authorDaniel Golle <daniel@makrotopia.org>
Tue, 28 Jul 2026 04:52:14 +0000 (05:52 +0100)
committerJakub Kicinski <kuba@kernel.org>
Thu, 30 Jul 2026 00:30:14 +0000 (17:30 -0700)
bus->read() returns a negative errno on failure, but
mt7530_regmap_read() assigns it to a u16, truncating e.g. -ETIMEDOUT
into 0xff92, and returns success. The garbage word is then consumed as
register data, and read-modify-write cycles write it back to the
switch. Check both reads and propagate their errors.

The same defect existed in mt7530_mii_read() since the driver was
introduced and moved into the regmap backend unchanged.

Fixes: b8f126a8d543 ("net-next: dsa: add dsa support for Mediatek MT7530 switch")
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/3c628e48276c2e5522c8795a6be60d11c7a76a7d.1785213071.git.daniel@makrotopia.org
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/dsa/mt7530-mdio.c

index 11ea924a9f3577708413e19742859135360aa171..784dd58a71589f2f0fc08b979cfdf68cdafec641 100644 (file)
@@ -55,8 +55,15 @@ mt7530_regmap_read(void *context, unsigned int reg, unsigned int *val)
        if (ret < 0)
                return ret;
 
-       lo = bus->read(bus, priv->mdiodev->addr, r);
-       hi = bus->read(bus, priv->mdiodev->addr, 0x10);
+       ret = bus->read(bus, priv->mdiodev->addr, r);
+       if (ret < 0)
+               return ret;
+       lo = ret;
+
+       ret = bus->read(bus, priv->mdiodev->addr, 0x10);
+       if (ret < 0)
+               return ret;
+       hi = ret;
 
        *val = (hi << 16) | (lo & 0xffff);