A failed first BMCR read can have BMCR_RESET set in its negative errno.
The reset loop then retries the read, discarding the error if the next
read succeeds.

Poll in a do-while loop so every read, including the first, is checked
before inspecting the reset bit. Return the MDIO error consistently and
finish immediately once reset completes. Keep the initial PHY reset
delay and the budget of 500 one-millisecond waits.

Signed-off-by: James Hilliard <[email protected]>
---
 drivers/net/phy/phy.c | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)

diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
index cb4fba93391..1c894bde7d4 100644
--- a/drivers/net/phy/phy.c
+++ b/drivers/net/phy/phy.c
@@ -742,23 +742,21 @@ int phy_reset(struct phy_device *phydev)
         * auto-clearing).  This should happen within 0.5 seconds per the
         * IEEE spec.
         */
-       reg = phy_read(phydev, devad, MII_BMCR);
-       while ((reg & BMCR_RESET) && timeout--) {
+       do {
                reg = phy_read(phydev, devad, MII_BMCR);
 
                if (reg < 0) {
                        debug("PHY status read failed\n");
-                       return -1;
+                       return reg;
                }
-               udelay(1000);
-       }
+               if (!(reg & BMCR_RESET))
+                       return 0;
 
-       if (reg & BMCR_RESET) {
-               puts("PHY reset timed out\n");
-               return -1;
-       }
+               udelay(1000);
+       } while (--timeout);
 
-       return 0;
+       puts("PHY reset timed out\n");
+       return -1;
 }
 
 int miiphy_reset(const char *devname, unsigned char addr)

-- 
2.53.0

Reply via email to