bp->mii_bus->priv = bp;
- bp->mii_bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
+ bp->mii_bus->irq = devm_kmalloc(&bp->pdev->dev,
+ sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL);
if (!bp->mii_bus->irq) {
err = -ENOMEM;
goto err_out;
if (mdiobus_register(bp->mii_bus)) {
err = -ENXIO;
- goto err_out_free_mdio_irq;
+ goto err_out;
}
if (dnet_mii_probe(bp->dev) != 0) {
err_out_unregister_bus:
mdiobus_unregister(bp->mii_bus);
-err_out_free_mdio_irq:
- kfree(bp->mii_bus->irq);
err_out:
mdiobus_free(bp->mii_bus);
return err;
struct net_device *dev;
struct dnet *bp;
struct phy_device *phydev;
- int err = -ENXIO;
- unsigned int mem_base, mem_size, irq;
+ int err;
+ unsigned int irq;
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!res) {
- dev_err(&pdev->dev, "no mmio resource defined\n");
- goto err_out;
- }
- mem_base = res->start;
- mem_size = resource_size(res);
irq = platform_get_irq(pdev, 0);
- if (!request_mem_region(mem_base, mem_size, DRV_NAME)) {
- dev_err(&pdev->dev, "no memory region available\n");
- err = -EBUSY;
- goto err_out;
- }
-
- err = -ENOMEM;
dev = alloc_etherdev(sizeof(*bp));
if (!dev)
- goto err_out_release_mem;
+ return -ENOMEM;
/* TODO: Actually, we have some interesting features... */
dev->features |= 0;
spin_lock_init(&bp->lock);
- bp->regs = ioremap(mem_base, mem_size);
- if (!bp->regs) {
- dev_err(&pdev->dev, "failed to map registers, aborting.\n");
- err = -ENOMEM;
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ bp->regs = devm_ioremap_resource(&pdev->dev, res);
+ if (IS_ERR(bp->regs)) {
+ err = PTR_ERR(bp->regs);
goto err_out_free_dev;
}
if (err) {
dev_err(&pdev->dev, "Unable to request IRQ %d (error %d)\n",
irq, err);
- goto err_out_iounmap;
+ goto err_out_free_dev;
}
dev->netdev_ops = &dnet_netdev_ops;
goto err_out_unregister_netdev;
dev_info(&pdev->dev, "Dave DNET at 0x%p (0x%08x) irq %d %pM\n",
- bp->regs, mem_base, dev->irq, dev->dev_addr);
+ bp->regs, (unsigned int)res->start, dev->irq, dev->dev_addr);
dev_info(&pdev->dev, "has %smdio, %sirq, %sgigabit, %sdma\n",
(bp->capabilities & DNET_HAS_MDIO) ? "" : "no ",
(bp->capabilities & DNET_HAS_IRQ) ? "" : "no ",
unregister_netdev(dev);
err_out_free_irq:
free_irq(dev->irq, dev);
-err_out_iounmap:
- iounmap(bp->regs);
err_out_free_dev:
free_netdev(dev);
-err_out_release_mem:
- release_mem_region(mem_base, mem_size);
-err_out:
return err;
}
if (bp->phy_dev)
phy_disconnect(bp->phy_dev);
mdiobus_unregister(bp->mii_bus);
- kfree(bp->mii_bus->irq);
mdiobus_free(bp->mii_bus);
unregister_netdev(dev);
free_irq(dev->irq, dev);
- iounmap(bp->regs);
free_netdev(dev);
}