Skip to content

Commit

Permalink
net: usb: lan78xx: Fix error handling in MII read/write functions
Browse files Browse the repository at this point in the history
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 <o.rempel@pengutronix.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20241204084142.1152696-6-o.rempel@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
  • Loading branch information
Oleksij Rempel authored and Jakub Kicinski committed Dec 7, 2024
1 parent 9bcdc61 commit 32ee0dc
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion drivers/net/usb/lan78xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -2136,12 +2136,16 @@ static int lan78xx_mdiobus_read(struct mii_bus *bus, int phy_id, int idx)
/* set the address, index & direction (read from PHY) */
addr = mii_access(phy_id, idx, MII_READ);
ret = lan78xx_write_reg(dev, MII_ACC, addr);
if (ret < 0)
goto done;

ret = lan78xx_phy_wait_not_busy(dev);
if (ret < 0)
goto done;

ret = lan78xx_read_reg(dev, MII_DATA, &val);
if (ret < 0)
goto done;

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

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

val = (u32)regval;
ret = lan78xx_write_reg(dev, MII_DATA, val);
if (ret < 0)
goto done;

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

ret = lan78xx_phy_wait_not_busy(dev);
if (ret < 0)
Expand All @@ -2184,7 +2192,7 @@ static int lan78xx_mdiobus_write(struct mii_bus *bus, int phy_id, int idx,
done:
mutex_unlock(&dev->phy_mutex);
usb_autopm_put_interface(dev->intf);
return 0;
return ret;
}

static int lan78xx_mdio_init(struct lan78xx_net *dev)
Expand Down

0 comments on commit 32ee0dc

Please sign in to comment.