Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

of: of_mdio: Correct loop scanning logic

Commit 209c65b61d94 ("drivers/of/of_mdio.c:fix of_mdiobus_register()")
introduced a break of the loop on the premise that a successful
registration should exit the loop. The premise is correct but not to
code, because rc && rc != -ENODEV is just a special error condition,
that means we would exit the loop even with rc == -ENODEV which is
absolutely not correct since this is the error code to indicate to the
MDIO bus layer that scanning should continue.

Fix this by explicitly checking for rc = 0 as the only valid condition
to break out of the loop.

Fixes: 209c65b61d94 ("drivers/of/of_mdio.c:fix of_mdiobus_register()")
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Florian Fainelli and committed by
David S. Miller
5a8d7f12 6564cfef

+7 -2
+7 -2
drivers/of/of_mdio.c
··· 314 314 child, addr); 315 315 316 316 if (of_mdiobus_child_is_phy(child)) { 317 + /* -ENODEV is the return code that PHYLIB has 318 + * standardized on to indicate that bus 319 + * scanning should continue. 320 + */ 317 321 rc = of_mdiobus_register_phy(mdio, child, addr); 318 - if (rc && rc != -ENODEV) 322 + if (!rc) 323 + break; 324 + if (rc != -ENODEV) 319 325 goto unregister; 320 - break; 321 326 } 322 327 } 323 328 }