Signed-off-by: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
---
drivers/net/ethernet/renesas/sh_eth.c | 35 ++++++++++++++++------------------
1 file changed, 17 insertions(+), 18 deletions(-)
===================================================================
@@ -2615,9 +2615,10 @@ static int sh_mdio_init(struct net_devic
int ret, i;
struct bb_info *bitbang;
struct sh_eth_private *mdp = netdev_priv(ndev);
+ struct platform_device *pdev = mdp->pdev;
/* create bit control struct for PHY */
- bitbang = devm_kzalloc(&ndev->dev, sizeof(struct bb_info),
+ bitbang = devm_kzalloc(&pdev->dev, sizeof(struct bb_info),
GFP_KERNEL);
if (!bitbang) {
ret = -ENOMEM;
@@ -2644,10 +2645,10 @@ static int sh_mdio_init(struct net_devic
mdp->mii_bus->name = "sh_mii";
mdp->mii_bus->parent = &ndev->dev;
snprintf(mdp->mii_bus->id, MII_BUS_ID_SIZE, "%s-%x",
- mdp->pdev->name, id);
+ pdev->name, id);
/* PHY IRQ */
- mdp->mii_bus->irq = devm_kzalloc(&ndev->dev,
+ mdp->mii_bus->irq = devm_kzalloc(&pdev->dev,
sizeof(int) * PHY_MAX_ADDR,
GFP_KERNEL);
if (!mdp->mii_bus->irq) {
@@ -2655,10 +2656,9 @@ static int sh_mdio_init(struct net_devic
goto out_free_bus;
}
- /* register mdio bus */
- if (ndev->dev.parent->of_node) {
- ret = of_mdiobus_register(mdp->mii_bus,
- ndev->dev.parent->of_node);
+ /* register MDIO bus */
+ if (pdev->dev.of_node) {
+ ret = of_mdiobus_register(mdp->mii_bus, pdev->dev.of_node);
} else {
for (i = 0; i < PHY_MAX_ADDR; i++)
mdp->mii_bus->irq[i] = PHY_POLL;
@@ -2904,6 +2904,13 @@ static int sh_eth_drv_probe(struct platf
}
}
+ /* MDIO bus init */
+ ret = sh_mdio_init(ndev, pdev->id, pd);
+ if (ret) {
+ dev_err(&ndev->dev, "failed to initialise MDIO\n");
+ goto out_release;
+ }
+
netif_napi_add(ndev, &mdp->napi, sh_eth_poll, 64);
/* network device register */
@@ -2911,13 +2918,6 @@ static int sh_eth_drv_probe(struct platf
if (ret)
goto out_napi_del;
- /* mdio bus init */
- ret = sh_mdio_init(ndev, pdev->id, pd);
- if (ret) {
- dev_err(&ndev->dev, "failed to initialise MDIO\n");
- goto out_unregister;
- }
-
/* print device information */
pr_info("Base address at 0x%x, %pM, IRQ %d.\n",
(u32)ndev->base_addr, ndev->dev_addr, ndev->irq);
@@ -2926,12 +2926,11 @@ static int sh_eth_drv_probe(struct platf
return ret;
-out_unregister:
- unregister_netdev(ndev);
-
out_napi_del:
netif_napi_del(&mdp->napi);
+ sh_mdio_release(ndev);
+
out_release:
/* net_dev free */
if (ndev)
@@ -2946,9 +2945,9 @@ static int sh_eth_drv_remove(struct plat
struct net_device *ndev = platform_get_drvdata(pdev);
struct sh_eth_private *mdp = netdev_priv(ndev);
- sh_mdio_release(ndev);
unregister_netdev(ndev);
netif_napi_del(&mdp->napi);
+ sh_mdio_release(ndev);
pm_runtime_disable(&pdev->dev);
free_netdev(ndev);