hwrng: bcm63xx - use devm_* helpers

Simplify the driver's probe function and error handling by using the
device managed allocators, while at it, drop the redundant "out of
memory" messages since these are already printed by the allocator.

Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
This commit is contained in:
Florian Fainelli 2015-02-16 18:09:16 -08:00 committed by Herbert Xu
parent aeb9624f96
commit 0052a65413
1 changed files with 6 additions and 14 deletions

View File

@ -83,18 +83,16 @@ static int bcm63xx_rng_probe(struct platform_device *pdev)
goto out; goto out;
} }
priv = kzalloc(sizeof(*priv), GFP_KERNEL); priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv) { if (!priv) {
dev_err(&pdev->dev, "no memory for private structure\n");
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
rng = kzalloc(sizeof(*rng), GFP_KERNEL); rng = devm_kzalloc(&pdev->dev, sizeof(*rng), GFP_KERNEL);
if (!rng) { if (!rng) {
dev_err(&pdev->dev, "no memory for rng structure\n");
ret = -ENOMEM; ret = -ENOMEM;
goto out_free_priv; goto out;
} }
platform_set_drvdata(pdev, rng); platform_set_drvdata(pdev, rng);
@ -109,7 +107,7 @@ static int bcm63xx_rng_probe(struct platform_device *pdev)
if (IS_ERR(clk)) { if (IS_ERR(clk)) {
dev_err(&pdev->dev, "no clock for device\n"); dev_err(&pdev->dev, "no clock for device\n");
ret = PTR_ERR(clk); ret = PTR_ERR(clk);
goto out_free_rng; goto out;
} }
priv->clk = clk; priv->clk = clk;
@ -118,7 +116,7 @@ static int bcm63xx_rng_probe(struct platform_device *pdev)
resource_size(r), pdev->name)) { resource_size(r), pdev->name)) {
dev_err(&pdev->dev, "request mem failed"); dev_err(&pdev->dev, "request mem failed");
ret = -ENOMEM; ret = -ENOMEM;
goto out_free_rng; goto out;
} }
priv->regs = devm_ioremap_nocache(&pdev->dev, r->start, priv->regs = devm_ioremap_nocache(&pdev->dev, r->start,
@ -126,7 +124,7 @@ static int bcm63xx_rng_probe(struct platform_device *pdev)
if (!priv->regs) { if (!priv->regs) {
dev_err(&pdev->dev, "ioremap failed"); dev_err(&pdev->dev, "ioremap failed");
ret = -ENOMEM; ret = -ENOMEM;
goto out_free_rng; goto out;
} }
clk_enable(clk); clk_enable(clk);
@ -143,10 +141,6 @@ static int bcm63xx_rng_probe(struct platform_device *pdev)
out_clk_disable: out_clk_disable:
clk_disable(clk); clk_disable(clk);
out_free_rng:
kfree(rng);
out_free_priv:
kfree(priv);
out: out:
return ret; return ret;
} }
@ -158,8 +152,6 @@ static int bcm63xx_rng_remove(struct platform_device *pdev)
hwrng_unregister(rng); hwrng_unregister(rng);
clk_disable(priv->clk); clk_disable(priv->clk);
kfree(priv);
kfree(rng);
return 0; return 0;
} }