aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHimangi Saraogi <himangi774@gmail.com>2014-08-01 11:30:03 -0400
committerDavid S. Miller <davem@davemloft.net>2014-08-02 19:40:52 -0400
commitae29223eaf0ecf4c701457a6b40d7b8f19c90413 (patch)
tree2473a7f40b6f9e80adbaf67b2a0b535ef24a948e
parent54789983d14c00c80933beb782205df2a6c59afc (diff)
net: dnet: Use managed interfaces
This patch introduces the use of managed interfaces like devm_ioremap_resource and does away with the calls to free the allocated memory in the probe and remove functions. Also, some labels and variable are done away with. This fixes a bug as there was a missing release_mem_region in the remove function. Signed-off-by: Himangi Saraogi <himangi774@gmail.com> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--drivers/net/ethernet/dnet.c46
1 files changed, 12 insertions, 34 deletions
diff --git a/drivers/net/ethernet/dnet.c b/drivers/net/ethernet/dnet.c
index e9b0faba3078..a379c3e4b57f 100644
--- a/drivers/net/ethernet/dnet.c
+++ b/drivers/net/ethernet/dnet.c
@@ -323,7 +323,8 @@ static int dnet_mii_init(struct dnet *bp)
323 323
324 bp->mii_bus->priv = bp; 324 bp->mii_bus->priv = bp;
325 325
326 bp->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL); 326 bp->mii_bus->irq = devm_kmalloc(&bp->pdev->dev,
327 sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
327 if (!bp->mii_bus->irq) { 328 if (!bp->mii_bus->irq) {
328 err = -ENOMEM; 329 err = -ENOMEM;
329 goto err_out; 330 goto err_out;
@@ -334,7 +335,7 @@ static int dnet_mii_init(struct dnet *bp)
334 335
335 if (mdiobus_register(bp->mii_bus)) { 336 if (mdiobus_register(bp->mii_bus)) {
336 err = -ENXIO; 337 err = -ENXIO;
337 goto err_out_free_mdio_irq; 338 goto err_out;
338 } 339 }
339 340
340 if (dnet_mii_probe(bp->dev) != 0) { 341 if (dnet_mii_probe(bp->dev) != 0) {
@@ -346,8 +347,6 @@ static int dnet_mii_init(struct dnet *bp)
346 347
347err_out_unregister_bus: 348err_out_unregister_bus:
348 mdiobus_unregister(bp->mii_bus); 349 mdiobus_unregister(bp->mii_bus);
349err_out_free_mdio_irq:
350 kfree(bp->mii_bus->irq);
351err_out: 350err_out:
352 mdiobus_free(bp->mii_bus); 351 mdiobus_free(bp->mii_bus);
353 return err; 352 return err;
@@ -825,28 +824,14 @@ static int dnet_probe(struct platform_device *pdev)
825 struct net_device *dev; 824 struct net_device *dev;
826 struct dnet *bp; 825 struct dnet *bp;
827 struct phy_device *phydev; 826 struct phy_device *phydev;
828 int err = -ENXIO; 827 int err;
829 unsigned int mem_base, mem_size, irq; 828 unsigned int irq;
830 829
831 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
832 if (!res) {
833 dev_err(&pdev->dev, "no mmio resource defined\n");
834 goto err_out;
835 }
836 mem_base = res->start;
837 mem_size = resource_size(res);
838 irq = platform_get_irq(pdev, 0); 830 irq = platform_get_irq(pdev, 0);
839 831
840 if (!request_mem_region(mem_base, mem_size, DRV_NAME)) {
841 dev_err(&pdev->dev, "no memory region available\n");
842 err = -EBUSY;
843 goto err_out;
844 }
845
846 err = -ENOMEM;
847 dev = alloc_etherdev(sizeof(*bp)); 832 dev = alloc_etherdev(sizeof(*bp));
848 if (!dev) 833 if (!dev)
849 goto err_out_release_mem; 834 return -ENOMEM;
850 835
851 /* TODO: Actually, we have some interesting features... */ 836 /* TODO: Actually, we have some interesting features... */
852 dev->features |= 0; 837 dev->features |= 0;
@@ -859,10 +844,10 @@ static int dnet_probe(struct platform_device *pdev)
859 844
860 spin_lock_init(&bp->lock); 845 spin_lock_init(&bp->lock);
861 846
862 bp->regs = ioremap(mem_base, mem_size); 847 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
863 if (!bp->regs) { 848 bp->regs = devm_ioremap_resource(&pdev->dev, res);
864 dev_err(&pdev->dev, "failed to map registers, aborting.\n"); 849 if (IS_ERR(bp->regs)) {
865 err = -ENOMEM; 850 err = PTR_ERR(bp->regs);
866 goto err_out_free_dev; 851 goto err_out_free_dev;
867 } 852 }
868 853
@@ -871,7 +856,7 @@ static int dnet_probe(struct platform_device *pdev)
871 if (err) { 856 if (err) {
872 dev_err(&pdev->dev, "Unable to request IRQ %d (error %d)\n", 857 dev_err(&pdev->dev, "Unable to request IRQ %d (error %d)\n",
873 irq, err); 858 irq, err);
874 goto err_out_iounmap; 859 goto err_out_free_dev;
875 } 860 }
876 861
877 dev->netdev_ops = &dnet_netdev_ops; 862 dev->netdev_ops = &dnet_netdev_ops;
@@ -908,7 +893,7 @@ static int dnet_probe(struct platform_device *pdev)
908 goto err_out_unregister_netdev; 893 goto err_out_unregister_netdev;
909 894
910 dev_info(&pdev->dev, "Dave DNET at 0x%p (0x%08x) irq %d %pM\n", 895 dev_info(&pdev->dev, "Dave DNET at 0x%p (0x%08x) irq %d %pM\n",
911 bp->regs, mem_base, dev->irq, dev->dev_addr); 896 bp->regs, (unsigned int)res->start, dev->irq, dev->dev_addr);
912 dev_info(&pdev->dev, "has %smdio, %sirq, %sgigabit, %sdma\n", 897 dev_info(&pdev->dev, "has %smdio, %sirq, %sgigabit, %sdma\n",
913 (bp->capabilities & DNET_HAS_MDIO) ? "" : "no ", 898 (bp->capabilities & DNET_HAS_MDIO) ? "" : "no ",
914 (bp->capabilities & DNET_HAS_IRQ) ? "" : "no ", 899 (bp->capabilities & DNET_HAS_IRQ) ? "" : "no ",
@@ -925,13 +910,8 @@ err_out_unregister_netdev:
925 unregister_netdev(dev); 910 unregister_netdev(dev);
926err_out_free_irq: 911err_out_free_irq:
927 free_irq(dev->irq, dev); 912 free_irq(dev->irq, dev);
928err_out_iounmap:
929 iounmap(bp->regs);
930err_out_free_dev: 913err_out_free_dev:
931 free_netdev(dev); 914 free_netdev(dev);
932err_out_release_mem:
933 release_mem_region(mem_base, mem_size);
934err_out:
935 return err; 915 return err;
936} 916}
937 917
@@ -948,11 +928,9 @@ static int dnet_remove(struct platform_device *pdev)
948 if (bp->phy_dev) 928 if (bp->phy_dev)
949 phy_disconnect(bp->phy_dev); 929 phy_disconnect(bp->phy_dev);
950 mdiobus_unregister(bp->mii_bus); 930 mdiobus_unregister(bp->mii_bus);
951 kfree(bp->mii_bus->irq);
952 mdiobus_free(bp->mii_bus); 931 mdiobus_free(bp->mii_bus);
953 unregister_netdev(dev); 932 unregister_netdev(dev);
954 free_irq(dev->irq, dev); 933 free_irq(dev->irq, dev);
955 iounmap(bp->regs);
956 free_netdev(dev); 934 free_netdev(dev);
957 } 935 }
958 936