Netdev List
 help / color / mirror / Atom feed
* [PATCH V2] mdio_bus: Fix MDIO bus scanning in __mdiobus_register()
@ 2016-05-02  0:47 Marek Vasut
  2016-05-02  0:50 ` David Miller
  0 siblings, 1 reply; 2+ messages in thread
From: Marek Vasut @ 2016-05-02  0:47 UTC (permalink / raw)
  To: netdev
  Cc: Marek Vasut, Arnd Bergmann, David S . Miller, Dinh Nguyen,
	Florian Fainelli, Sergei Shtylyov

Since commit b74766a0a0fe ("phylib: don't return NULL
from get_phy_device()") in linux-next, phy_get_device() will return
ERR_PTR(-ENODEV) instead of NULL if the PHY device ID is all ones.

This causes problem with stmmac driver and likely some other drivers
which call mdiobus_register(). I triggered this bug on SoCFPGA MCVEVK
board with linux-next 20160427 and 20160428. In case of the stmmac, if
there is no PHY node specified in the DT for the stmmac block, the stmmac
driver ( drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c function
stmmac_mdio_register() ) will call mdiobus_register() , which will
register the MDIO bus and probe for the PHY.

The mdiobus_register() resp. __mdiobus_register() iterates over all of
the addresses on the MDIO bus and calls mdiobus_scan() for each of them,
which invokes get_phy_device(). Before the aforementioned patch, the
mdiobus_scan() would return NULL if no PHY was found on a given address
and mdiobus_register() would continue and try the next PHY address. Now,
mdiobus_scan() returns ERR_PTR(-ENODEV), which is caught by the
'if (IS_ERR(phydev))' condition and the loop exits immediately if the
PHY address does not contain PHY.

Repair this by explicitly checking for the ERR_PTR(-ENODEV) and if this
error comes around, continue with the next PHY address.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: David S. Miller <davem@davemloft.net>
Cc: Dinh Nguyen <dinguyen@opensource.altera.com>
Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Acked-by: Florian Fainelli <f.fainelli@gmail.com>
---
V2: Fixed checkpatch warning in the commit message
    Added Ack from Florian
---
 drivers/net/phy/mdio_bus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 499003ee..388f992 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -333,7 +333,7 @@ int __mdiobus_register(struct mii_bus *bus, struct module *owner)
 			struct phy_device *phydev;
 
 			phydev = mdiobus_scan(bus, i);
-			if (IS_ERR(phydev)) {
+			if (IS_ERR(phydev) && (PTR_ERR(phydev) != -ENODEV)) {
 				err = PTR_ERR(phydev);
 				goto error;
 			}
-- 
2.7.0

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH V2] mdio_bus: Fix MDIO bus scanning in __mdiobus_register()
  2016-05-02  0:47 [PATCH V2] mdio_bus: Fix MDIO bus scanning in __mdiobus_register() Marek Vasut
@ 2016-05-02  0:50 ` David Miller
  0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2016-05-02  0:50 UTC (permalink / raw)
  To: marex; +Cc: netdev, arnd, dinguyen, f.fainelli, sergei.shtylyov

From: Marek Vasut <marex@denx.de>
Date: Mon,  2 May 2016 02:47:31 +0200

> Since commit b74766a0a0fe ("phylib: don't return NULL
> from get_phy_device()") in linux-next, phy_get_device() will return
> ERR_PTR(-ENODEV) instead of NULL if the PHY device ID is all ones.
> 
> This causes problem with stmmac driver and likely some other drivers
> which call mdiobus_register(). I triggered this bug on SoCFPGA MCVEVK
> board with linux-next 20160427 and 20160428. In case of the stmmac, if
> there is no PHY node specified in the DT for the stmmac block, the stmmac
> driver ( drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c function
> stmmac_mdio_register() ) will call mdiobus_register() , which will
> register the MDIO bus and probe for the PHY.
> 
> The mdiobus_register() resp. __mdiobus_register() iterates over all of
> the addresses on the MDIO bus and calls mdiobus_scan() for each of them,
> which invokes get_phy_device(). Before the aforementioned patch, the
> mdiobus_scan() would return NULL if no PHY was found on a given address
> and mdiobus_register() would continue and try the next PHY address. Now,
> mdiobus_scan() returns ERR_PTR(-ENODEV), which is caught by the
> 'if (IS_ERR(phydev))' condition and the loop exits immediately if the
> PHY address does not contain PHY.
> 
> Repair this by explicitly checking for the ERR_PTR(-ENODEV) and if this
> error comes around, continue with the next PHY address.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Acked-by: Florian Fainelli <f.fainelli@gmail.com>

Applied, thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-05-02  0:50 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-02  0:47 [PATCH V2] mdio_bus: Fix MDIO bus scanning in __mdiobus_register() Marek Vasut
2016-05-02  0:50 ` David Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox