Skip to content

Commit 32ee0dc

Browse files
oleremkuba-moo
authored andcommitted
net: usb: lan78xx: Fix error handling in MII read/write functions
Ensure proper error handling in `lan78xx_mdiobus_read` and `lan78xx_mdiobus_write` by checking return values of register read/write operations and returning errors to the caller. Signed-off-by: Oleksij Rempel <[email protected]> Reviewed-by: Andrew Lunn <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 9bcdc61 commit 32ee0dc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

drivers/net/usb/lan78xx.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2136,12 +2136,16 @@ static int lan78xx_mdiobus_read(struct mii_bus *bus, int phy_id, int idx)
21362136
/* set the address, index & direction (read from PHY) */
21372137
addr = mii_access(phy_id, idx, MII_READ);
21382138
ret = lan78xx_write_reg(dev, MII_ACC, addr);
2139+
if (ret < 0)
2140+
goto done;
21392141

21402142
ret = lan78xx_phy_wait_not_busy(dev);
21412143
if (ret < 0)
21422144
goto done;
21432145

21442146
ret = lan78xx_read_reg(dev, MII_DATA, &val);
2147+
if (ret < 0)
2148+
goto done;
21452149

21462150
ret = (int)(val & 0xFFFF);
21472151

@@ -2172,10 +2176,14 @@ static int lan78xx_mdiobus_write(struct mii_bus *bus, int phy_id, int idx,
21722176

21732177
val = (u32)regval;
21742178
ret = lan78xx_write_reg(dev, MII_DATA, val);
2179+
if (ret < 0)
2180+
goto done;
21752181

21762182
/* set the address, index & direction (write to PHY) */
21772183
addr = mii_access(phy_id, idx, MII_WRITE);
21782184
ret = lan78xx_write_reg(dev, MII_ACC, addr);
2185+
if (ret < 0)
2186+
goto done;
21792187

21802188
ret = lan78xx_phy_wait_not_busy(dev);
21812189
if (ret < 0)
@@ -2184,7 +2192,7 @@ static int lan78xx_mdiobus_write(struct mii_bus *bus, int phy_id, int idx,
21842192
done:
21852193
mutex_unlock(&dev->phy_mutex);
21862194
usb_autopm_put_interface(dev->intf);
2187-
return 0;
2195+
return ret;
21882196
}
21892197

21902198
static int lan78xx_mdio_init(struct lan78xx_net *dev)

0 commit comments

Comments
 (0)