phy_mii_ioctl() ignores MDIO write failures and can report success after a
failed write. It also updates the cached link settings and may restart
auto-negotiation or reinitialize the PHY even though the requested write
failed.
Check the write result before updating the cached settings or invoking
those follow-up operations, and return the MDIO error to the caller.
Fixes: 00db8189d984 ("This patch adds a PHY Abstraction Layer to the Linux Kernel, enabling ethernet drivers to remain as ignorant as is reasonable of the connected PHY's design and operation details.")
Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
---
drivers/net/phy/phy.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index fce9bc7be330..4ac72a1b4f42 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -350,6 +350,15 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
prtad = mii_data->phy_id;
devad = mii_data->reg_num;
}
+
+ if (mdio_phy_id_is_c45(mii_data->phy_id))
+ ret = mdiobus_c45_write(phydev->mdio.bus, prtad, devad,
+ mii_data->reg_num, val);
+ else
+ ret = mdiobus_write(phydev->mdio.bus, prtad, devad, val);
+ if (ret < 0)
+ return ret;
+
if (prtad == phydev->mdio.addr) {
switch (devad) {
case MII_BMCR:@@ -388,12 +397,6 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd)
}
}
- if (mdio_phy_id_is_c45(mii_data->phy_id))
- mdiobus_c45_write(phydev->mdio.bus, prtad, devad,
- mii_data->reg_num, val);
- else
- mdiobus_write(phydev->mdio.bus, prtad, devad, val);
-
if (prtad == phydev->mdio.addr &&
devad == MII_BMCR &&
val & BMCR_RESET)
--
2.53.0