History

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.

Florian Fainelli committed 10 years ago

Commit cf669661 parent b365d951 file · +19 −12Browse files

Unified · Split

drivers/net/ethernet/cadence/macb.c+19−12
@@ -441,7 +441,7 @@ static int macb_mii_init(struct macb *bp) · 440 unmodified lines
441441 snprintf(bp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
442442 bp->pdev->name, bp->pdev->id);
443443 bp->mii_bus->priv = bp;
444− bp->mii_bus->parent = &bp->dev->dev;
444+ bp->mii_bus->parent = &bp->pdev->dev;
445445 pdata = dev_get_platdata(&bp->pdev->dev);
446446
447447 dev_set_drvdata(&bp->dev->dev, bp->mii_bus);
@@ -3020,29 +3020,36 @@ static int macb_probe(struct platform_device *pdev) · 2572 unmodified lines
30203020 if (err)
30213021 goto err_out_free_netdev;
30223022
3023+ err = macb_mii_init(bp);
3024+ if (err)
3025+ goto err_out_free_netdev;
3026+
3027+ phydev = bp->phy_dev;
3028+
3029+ netif_carrier_off(dev);
3030+
30233031 err = register_netdev(dev);
30243032 if (err) {
30253033 dev_err(&pdev->dev, "Cannot register net device, aborting.\n");
3026− goto err_out_unregister_netdev;
3034+ goto err_out_unregister_mdio;
30273035 }
30283036
3029− err = macb_mii_init(bp);
3030− if (err)
3031− goto err_out_unregister_netdev;
3032−
3033− netif_carrier_off(dev);
3037+ phy_attached_info(phydev);
30343038
30353039 netdev_info(dev, "Cadence %s rev 0x%08x at 0x%08lx irq %d (%pM)\n",
30363040 macb_is_gem(bp) ? "GEM" : "MACB", macb_readl(bp, MID),
30373041 dev->base_addr, dev->irq, dev->dev_addr);
30383042
3039− phydev = bp->phy_dev;
3040− phy_attached_info(phydev);
3041−
30423043 return 0;
30433044
3044−err_out_unregister_netdev:
3045− unregister_netdev(dev);
3045+err_out_unregister_mdio:
3046+ phy_disconnect(bp->phy_dev);
3047+ mdiobus_unregister(bp->mii_bus);
3048+ mdiobus_free(bp->mii_bus);
3049+
3050+ /* Shutdown the PHY if there is a GPIO reset */
3051+ if (bp->reset_gpio)
3052+ gpiod_set_value(bp->reset_gpio, 0);
30463053
30473054 err_out_free_netdev:
30483055 free_netdev(dev);