Commit 56ecd2cc authored by Ezequiel Garcia's avatar Ezequiel Garcia Committed by David S. Miller

net: mvmdio: Use devm_* API to simplify the code

This commit makes use of devm_kmalloc_array() for memory allocation and the
recently introduced devm_mdiobus_alloc() API to simplify driver's code.
While here, remove a redundant out of memory error message.
Acked-by: default avatarSebastian Hesselbarth <sebastian.hesselbarth@gmail.com>
Signed-off-by: default avatarEzequiel Garcia <ezequiel.garcia@free-electrons.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent edadb7fa
...@@ -195,11 +195,10 @@ static int orion_mdio_probe(struct platform_device *pdev) ...@@ -195,11 +195,10 @@ static int orion_mdio_probe(struct platform_device *pdev)
return -ENODEV; return -ENODEV;
} }
bus = mdiobus_alloc_size(sizeof(struct orion_mdio_dev)); bus = devm_mdiobus_alloc_size(&pdev->dev,
if (!bus) { sizeof(struct orion_mdio_dev));
dev_err(&pdev->dev, "Cannot allocate MDIO bus\n"); if (!bus)
return -ENOMEM; return -ENOMEM;
}
bus->name = "orion_mdio_bus"; bus->name = "orion_mdio_bus";
bus->read = orion_mdio_read; bus->read = orion_mdio_read;
...@@ -208,11 +207,10 @@ static int orion_mdio_probe(struct platform_device *pdev) ...@@ -208,11 +207,10 @@ static int orion_mdio_probe(struct platform_device *pdev)
dev_name(&pdev->dev)); dev_name(&pdev->dev));
bus->parent = &pdev->dev; bus->parent = &pdev->dev;
bus->irq = kmalloc(sizeof(int) * PHY_MAX_ADDR, GFP_KERNEL); bus->irq = devm_kmalloc_array(&pdev->dev, PHY_MAX_ADDR, sizeof(int),
if (!bus->irq) { GFP_KERNEL);
mdiobus_free(bus); if (!bus->irq)
return -ENOMEM; return -ENOMEM;
}
for (i = 0; i < PHY_MAX_ADDR; i++) for (i = 0; i < PHY_MAX_ADDR; i++)
bus->irq[i] = PHY_POLL; bus->irq[i] = PHY_POLL;
...@@ -264,8 +262,6 @@ static int orion_mdio_probe(struct platform_device *pdev) ...@@ -264,8 +262,6 @@ static int orion_mdio_probe(struct platform_device *pdev)
out_mdio: out_mdio:
if (!IS_ERR(dev->clk)) if (!IS_ERR(dev->clk))
clk_disable_unprepare(dev->clk); clk_disable_unprepare(dev->clk);
kfree(bus->irq);
mdiobus_free(bus);
return ret; return ret;
} }
...@@ -276,8 +272,6 @@ static int orion_mdio_remove(struct platform_device *pdev) ...@@ -276,8 +272,6 @@ static int orion_mdio_remove(struct platform_device *pdev)
writel(0, dev->regs + MVMDIO_ERR_INT_MASK); writel(0, dev->regs + MVMDIO_ERR_INT_MASK);
mdiobus_unregister(bus); mdiobus_unregister(bus);
kfree(bus->irq);
mdiobus_free(bus);
if (!IS_ERR(dev->clk)) if (!IS_ERR(dev->clk))
clk_disable_unprepare(dev->clk); clk_disable_unprepare(dev->clk);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment