ath79: ag71xx: replace alloc_etherdev with devm_alloc_etherdev

using the devm api makes the code simpler.
also drop unneeded memory free from ag71xx_remove since they are
allocated using devm apis.

Signed-off-by: Chuanhong Guo <gch981213@gmail.com>
master
Chuanhong Guo 6 years ago committed by Daniel Golle
parent f73b2d64ed
commit a4eef43a12
  1. 33
      target/linux/ath79/files/drivers/net/ethernet/atheros/ag71xx/ag71xx_main.c

@ -1332,7 +1332,7 @@ static int ag71xx_probe(struct platform_device *pdev)
if (!np) if (!np)
return -ENODEV; return -ENODEV;
dev = alloc_etherdev(sizeof(*ag)); dev = devm_alloc_etherdev(&pdev->dev, sizeof(*ag));
if (!dev) if (!dev)
return -ENOMEM; return -ENOMEM;
@ -1356,8 +1356,7 @@ static int ag71xx_probe(struct platform_device *pdev)
ag->mac_reset = devm_reset_control_get(&pdev->dev, "mac"); ag->mac_reset = devm_reset_control_get(&pdev->dev, "mac");
if (IS_ERR(ag->mac_reset)) { if (IS_ERR(ag->mac_reset)) {
dev_err(&pdev->dev, "missing mac reset\n"); dev_err(&pdev->dev, "missing mac reset\n");
err = PTR_ERR(ag->mac_reset); return PTR_ERR(ag->mac_reset);
goto err_free;
} }
if (of_property_read_u32_array(np, "fifo-data", ag->fifodata, 3)) { if (of_property_read_u32_array(np, "fifo-data", ag->fifodata, 3)) {
@ -1390,18 +1389,15 @@ static int ag71xx_probe(struct platform_device *pdev)
ag->mac_base = devm_ioremap_nocache(&pdev->dev, res->start, ag->mac_base = devm_ioremap_nocache(&pdev->dev, res->start,
res->end - res->start + 1); res->end - res->start + 1);
if (!ag->mac_base) { if (!ag->mac_base)
err = -ENOMEM; return -ENOMEM;
goto err_free;
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 1); res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
if (res) { if (res) {
ag->mii_base = devm_ioremap_nocache(&pdev->dev, res->start, ag->mii_base = devm_ioremap_nocache(&pdev->dev, res->start,
res->end - res->start + 1); res->end - res->start + 1);
if (!ag->mii_base) { if (!ag->mii_base)
err = -ENOMEM; return -ENOMEM;
goto err_free;
}
} }
dev->irq = platform_get_irq(pdev, 0); dev->irq = platform_get_irq(pdev, 0);
@ -1409,7 +1405,7 @@ static int ag71xx_probe(struct platform_device *pdev)
0x0, dev_name(&pdev->dev), dev); 0x0, dev_name(&pdev->dev), dev);
if (err) { if (err) {
dev_err(&pdev->dev, "unable to request IRQ %d\n", dev->irq); dev_err(&pdev->dev, "unable to request IRQ %d\n", dev->irq);
goto err_free; return err;
} }
dev->netdev_ops = &ag71xx_netdev_ops; dev->netdev_ops = &ag71xx_netdev_ops;
@ -1460,7 +1456,7 @@ static int ag71xx_probe(struct platform_device *pdev)
sizeof(struct ag71xx_desc), sizeof(struct ag71xx_desc),
&ag->stop_desc_dma, GFP_KERNEL); &ag->stop_desc_dma, GFP_KERNEL);
if (!ag->stop_desc) if (!ag->stop_desc)
goto err_free; return -ENOMEM;
ag->stop_desc->data = 0; ag->stop_desc->data = 0;
ag->stop_desc->ctrl = 0; ag->stop_desc->ctrl = 0;
@ -1477,8 +1473,7 @@ static int ag71xx_probe(struct platform_device *pdev)
ag->phy_if_mode = of_get_phy_mode(np); ag->phy_if_mode = of_get_phy_mode(np);
if (ag->phy_if_mode < 0) { if (ag->phy_if_mode < 0) {
dev_err(&pdev->dev, "missing phy-mode property in DT\n"); dev_err(&pdev->dev, "missing phy-mode property in DT\n");
err = ag->phy_if_mode; return ag->phy_if_mode;
goto err_free;
} }
if (of_property_read_u32(np, "qca,mac-idx", &ag->mac_idx)) if (of_property_read_u32(np, "qca,mac-idx", &ag->mac_idx))
@ -1513,7 +1508,7 @@ static int ag71xx_probe(struct platform_device *pdev)
err = ag71xx_phy_connect(ag); err = ag71xx_phy_connect(ag);
if (err) if (err)
goto err_free; return err;
err = ag71xx_debugfs_init(ag); err = ag71xx_debugfs_init(ag);
if (err) if (err)
@ -1537,8 +1532,6 @@ static int ag71xx_probe(struct platform_device *pdev)
err_phy_disconnect: err_phy_disconnect:
ag71xx_phy_disconnect(ag); ag71xx_phy_disconnect(ag);
err_free:
free_netdev(dev);
return err; return err;
} }
@ -1554,11 +1547,7 @@ static int ag71xx_remove(struct platform_device *pdev)
ag71xx_debugfs_exit(ag); ag71xx_debugfs_exit(ag);
ag71xx_phy_disconnect(ag); ag71xx_phy_disconnect(ag);
unregister_netdev(dev); unregister_netdev(dev);
free_irq(dev->irq, dev);
iounmap(ag->mac_base);
kfree(dev);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
return 0; return 0;
} }

Loading…
Cancel
Save