Skip to content

Commit

Permalink
net: davinci_mdio: use devm_* api
Browse files Browse the repository at this point in the history
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: Lad, Prabhakar <prabhakar.csengg@gmail.com>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Grygorii Strashko authored and David S. Miller committed May 2, 2014
1 parent 6d48f44 commit 50d0636
Showing 1 changed file with 5 additions and 19 deletions.
24 changes: 5 additions & 19 deletions drivers/net/ethernet/ti/davinci_mdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -321,15 +321,14 @@ static int davinci_mdio_probe(struct platform_device *pdev)
struct phy_device *phy;
int ret, addr;

data = kzalloc(sizeof(*data), GFP_KERNEL);
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
if (!data)
return -ENOMEM;

data->bus = mdiobus_alloc();
data->bus = devm_mdiobus_alloc(dev);
if (!data->bus) {
dev_err(dev, "failed to alloc mii bus\n");
ret = -ENOMEM;
goto bail_out;
return -ENOMEM;
}

if (dev->of_node) {
Expand All @@ -354,7 +353,7 @@ static int davinci_mdio_probe(struct platform_device *pdev)

pm_runtime_enable(&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)) {
dev_err(dev, "failed to get device clock\n");
ret = PTR_ERR(data->clk);
Expand Down Expand Up @@ -406,35 +405,22 @@ static int davinci_mdio_probe(struct platform_device *pdev)
return 0;

bail_out:
if (data->bus)
mdiobus_free(data->bus);

if (data->clk)
clk_put(data->clk);
pm_runtime_put_sync(&pdev->dev);
pm_runtime_disable(&pdev->dev);

kfree(data);

return ret;
}

static int davinci_mdio_remove(struct platform_device *pdev)
{
struct davinci_mdio_data *data = platform_get_drvdata(pdev);

if (data->bus) {
if (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_disable(&pdev->dev);

kfree(data);

return 0;
}

Expand Down

0 comments on commit 50d0636

Please sign in to comment.