[PATCH RFC net-next v2 4/8] net: phy: add error handling for __phy_{read,write}_mmd

From: Michael Walle
Date: Fri Mar 25 2022 - 17:35:56 EST


Now that __phy_mmd_indirect() returns an error code, check it and
additionally check the error code of the last read or write access.

Signed-off-by: Michael Walle <michael@xxxxxxxx>
---
drivers/net/phy/phy-core.c | 13 ++++++++-----
1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/net/phy/phy-core.c b/drivers/net/phy/phy-core.c
index dd9b6b64757d..2a300c58d1e5 100644
--- a/drivers/net/phy/phy-core.c
+++ b/drivers/net/phy/phy-core.c
@@ -493,8 +493,11 @@ int __phy_read_mmd(struct phy_device *phydev, int devad, u32 regnum)
} else {
struct mii_bus *bus = phydev->mdio.bus;
int phy_addr = phydev->mdio.addr;
+ int ret;

- __phy_mmd_indirect(bus, phy_addr, devad, regnum);
+ ret = __phy_mmd_indirect(bus, phy_addr, devad, regnum);
+ if (ret)
+ return ret;

/* Read the content of the MMD's selected register */
val = __mdiobus_read(bus, phy_addr, MII_MMD_DATA);
@@ -550,12 +553,12 @@ int __phy_write_mmd(struct phy_device *phydev, int devad, u32 regnum, u16 val)
struct mii_bus *bus = phydev->mdio.bus;
int phy_addr = phydev->mdio.addr;

- __phy_mmd_indirect(bus, phy_addr, devad, regnum);
+ ret = __phy_mmd_indirect(bus, phy_addr, devad, regnum);
+ if (ret)
+ return ret;

/* Write the data into MMD's selected register */
- __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val);
-
- ret = 0;
+ ret = __mdiobus_write(bus, phy_addr, MII_MMD_DATA, val);
}
return ret;
}
--
2.30.2