Commit 50d0636e authored by Grygorii Strashko's avatar Grygorii Strashko Committed by David S. Miller

net: davinci_mdio: use devm_* api

Use devm_* API for memory allocation and to get device's clock
to simplify driver's code.

Cc: Florian Fainelli <f.fainelli@gmail.com>
Cc: Sergei Shtylyov <sergei.shtylyov@cogentembedded.com>
Acked-and-tested-by: default avatarLad, Prabhakar <prabhakar.csengg@gmail.com>
Signed-off-by: default avatarGrygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 6d48f44b
...@@ -321,15 +321,14 @@ static int davinci_mdio_probe(struct platform_device *pdev) ...@@ -321,15 +321,14 @@ static int davinci_mdio_probe(struct platform_device *pdev)
struct phy_device *phy; struct phy_device *phy;
int ret, addr; int ret, addr;
data = kzalloc(sizeof(*data), GFP_KERNEL); data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data) if (!data)
return -ENOMEM; return -ENOMEM;
data->bus = mdiobus_alloc(); data->bus = devm_mdiobus_alloc(dev);
if (!data->bus) { if (!data->bus) {
dev_err(dev, "failed to alloc mii bus\n"); dev_err(dev, "failed to alloc mii bus\n");
ret = -ENOMEM; return -ENOMEM;
goto bail_out;
} }
if (dev->of_node) { if (dev->of_node) {
...@@ -354,7 +353,7 @@ static int davinci_mdio_probe(struct platform_device *pdev) ...@@ -354,7 +353,7 @@ static int davinci_mdio_probe(struct platform_device *pdev)
pm_runtime_enable(&pdev->dev); pm_runtime_enable(&pdev->dev);
pm_runtime_get_sync(&pdev->dev); pm_runtime_get_sync(&pdev->dev);
data->clk = clk_get(&pdev->dev, "fck"); data->clk = devm_clk_get(dev, "fck");
if (IS_ERR(data->clk)) { if (IS_ERR(data->clk)) {
dev_err(dev, "failed to get device clock\n"); dev_err(dev, "failed to get device clock\n");
ret = PTR_ERR(data->clk); ret = PTR_ERR(data->clk);
...@@ -406,16 +405,9 @@ static int davinci_mdio_probe(struct platform_device *pdev) ...@@ -406,16 +405,9 @@ static int davinci_mdio_probe(struct platform_device *pdev)
return 0; return 0;
bail_out: bail_out:
if (data->bus)
mdiobus_free(data->bus);
if (data->clk)
clk_put(data->clk);
pm_runtime_put_sync(&pdev->dev); pm_runtime_put_sync(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
kfree(data);
return ret; return ret;
} }
...@@ -423,18 +415,12 @@ static int davinci_mdio_remove(struct platform_device *pdev) ...@@ -423,18 +415,12 @@ static int davinci_mdio_remove(struct platform_device *pdev)
{ {
struct davinci_mdio_data *data = platform_get_drvdata(pdev); struct davinci_mdio_data *data = platform_get_drvdata(pdev);
if (data->bus) { if (data->bus)
mdiobus_unregister(data->bus); mdiobus_unregister(data->bus);
mdiobus_free(data->bus);
}
if (data->clk)
clk_put(data->clk);
pm_runtime_put_sync(&pdev->dev); pm_runtime_put_sync(&pdev->dev);
pm_runtime_disable(&pdev->dev); pm_runtime_disable(&pdev->dev);
kfree(data);
return 0; return 0;
} }
......
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