Commit cf669660 authored by Florian Fainelli's avatar Florian Fainelli Committed by David S. Miller

net: macb: Probe MDIO bus before registering netdev

The current sequence makes us register for a network device prior to
registering and probing the MDIO bus which could lead to some unwanted
consequences, like a thread of execution calling into ndo_open before
register_netdev() returns, while the MDIO bus is not ready yet.

Rework the sequence to register for the MDIO bus, and therefore attach
to a PHY prior to calling register_netdev(), which implies reworking the
error path a bit.
Signed-off-by: default avatarFlorian Fainelli <f.fainelli@gmail.com>
Acked-by: default avatarNicolas Ferre <nicolas.ferre@atmel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent b365d955
...@@ -441,7 +441,7 @@ static int macb_mii_init(struct macb *bp) ...@@ -441,7 +441,7 @@ static int macb_mii_init(struct macb *bp)
snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x", snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
bp->pdev->name, bp->pdev->id); bp->pdev->name, bp->pdev->id);
bp->mii_bus->priv = bp; bp->mii_bus->priv = bp;
bp->mii_bus->parent = &bp->dev->dev; bp->mii_bus->parent = &bp->pdev->dev;
pdata = dev_get_platdata(&bp->pdev->dev); pdata = dev_get_platdata(&bp->pdev->dev);
dev_set_drvdata(&bp->dev->dev, bp->mii_bus); dev_set_drvdata(&bp->dev->dev, bp->mii_bus);
...@@ -3020,29 +3020,36 @@ static int macb_probe(struct platform_device *pdev) ...@@ -3020,29 +3020,36 @@ static int macb_probe(struct platform_device *pdev)
if (err) if (err)
goto err_out_free_netdev; goto err_out_free_netdev;
err = macb_mii_init(bp);
if (err)
goto err_out_free_netdev;
phydev = bp->phy_dev;
netif_carrier_off(dev);
err = register_netdev(dev); err = register_netdev(dev);
if (err) { if (err) {
dev_err(&pdev->dev, "Cannot register net device, aborting.\n"); dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
goto err_out_unregister_netdev; goto err_out_unregister_mdio;
} }
err = macb_mii_init(bp); phy_attached_info(phydev);
if (err)
goto err_out_unregister_netdev;
netif_carrier_off(dev);
netdev_info(dev, "Cadence %s rev 0x%08x at 0x%08lx irq %d (%pM)\n", netdev_info(dev, "Cadence %s rev 0x%08x at 0x%08lx irq %d (%pM)\n",
macb_is_gem(bp) ? "GEM" : "MACB", macb_readl(bp, MID), macb_is_gem(bp) ? "GEM" : "MACB", macb_readl(bp, MID),
dev->base_addr, dev->irq, dev->dev_addr); dev->base_addr, dev->irq, dev->dev_addr);
phydev = bp->phy_dev;
phy_attached_info(phydev);
return 0; return 0;
err_out_unregister_netdev: err_out_unregister_mdio:
unregister_netdev(dev); phy_disconnect(bp->phy_dev);
mdiobus_unregister(bp->mii_bus);
mdiobus_free(bp->mii_bus);
/* Shutdown the PHY if there is a GPIO reset */
if (bp->reset_gpio)
gpiod_set_value(bp->reset_gpio, 0);
err_out_free_netdev: err_out_free_netdev:
free_netdev(dev); free_netdev(dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment