Commit 93b7f9c9 authored by Jingoo Han's avatar Jingoo Han Committed by Herbert Xu

hwrng: timeriomem - Use devm_*() functions

Use devm_*() functions to make cleanup paths simpler.
Signed-off-by: default avatarJingoo Han <jg1.han@samsung.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent 1655c240
...@@ -118,7 +118,8 @@ static int timeriomem_rng_probe(struct platform_device *pdev) ...@@ -118,7 +118,8 @@ static int timeriomem_rng_probe(struct platform_device *pdev)
} }
/* Allocate memory for the device structure (and zero it) */ /* Allocate memory for the device structure (and zero it) */
priv = kzalloc(sizeof(struct timeriomem_rng_private_data), GFP_KERNEL); priv = devm_kzalloc(&pdev->dev,
sizeof(struct timeriomem_rng_private_data), GFP_KERNEL);
if (!priv) { if (!priv) {
dev_err(&pdev->dev, "failed to allocate device structure.\n"); dev_err(&pdev->dev, "failed to allocate device structure.\n");
return -ENOMEM; return -ENOMEM;
...@@ -134,17 +135,16 @@ static int timeriomem_rng_probe(struct platform_device *pdev) ...@@ -134,17 +135,16 @@ static int timeriomem_rng_probe(struct platform_device *pdev)
period = i; period = i;
else { else {
dev_err(&pdev->dev, "missing period\n"); dev_err(&pdev->dev, "missing period\n");
err = -EINVAL; return -EINVAL;
goto out_free;
} }
} else } else {
period = pdata->period; period = pdata->period;
}
priv->period = usecs_to_jiffies(period); priv->period = usecs_to_jiffies(period);
if (priv->period < 1) { if (priv->period < 1) {
dev_err(&pdev->dev, "period is less than one jiffy\n"); dev_err(&pdev->dev, "period is less than one jiffy\n");
err = -EINVAL; return -EINVAL;
goto out_free;
} }
priv->expires = jiffies; priv->expires = jiffies;
...@@ -160,24 +160,16 @@ static int timeriomem_rng_probe(struct platform_device *pdev) ...@@ -160,24 +160,16 @@ static int timeriomem_rng_probe(struct platform_device *pdev)
priv->timeriomem_rng_ops.data_read = timeriomem_rng_data_read; priv->timeriomem_rng_ops.data_read = timeriomem_rng_data_read;
priv->timeriomem_rng_ops.priv = (unsigned long)priv; priv->timeriomem_rng_ops.priv = (unsigned long)priv;
if (!request_mem_region(res->start, resource_size(res), priv->io_base = devm_ioremap_resource(&pdev->dev, res);
dev_name(&pdev->dev))) { if (IS_ERR(priv->io_base)) {
dev_err(&pdev->dev, "request_mem_region failed\n"); err = PTR_ERR(priv->io_base);
err = -EBUSY;
goto out_timer; goto out_timer;
} }
priv->io_base = ioremap(res->start, resource_size(res));
if (priv->io_base == NULL) {
dev_err(&pdev->dev, "ioremap failed\n");
err = -EIO;
goto out_release_io;
}
err = hwrng_register(&priv->timeriomem_rng_ops); err = hwrng_register(&priv->timeriomem_rng_ops);
if (err) { if (err) {
dev_err(&pdev->dev, "problem registering\n"); dev_err(&pdev->dev, "problem registering\n");
goto out; goto out_timer;
} }
dev_info(&pdev->dev, "32bits from 0x%p @ %dus\n", dev_info(&pdev->dev, "32bits from 0x%p @ %dus\n",
...@@ -185,30 +177,18 @@ static int timeriomem_rng_probe(struct platform_device *pdev) ...@@ -185,30 +177,18 @@ static int timeriomem_rng_probe(struct platform_device *pdev)
return 0; return 0;
out:
iounmap(priv->io_base);
out_release_io:
release_mem_region(res->start, resource_size(res));
out_timer: out_timer:
del_timer_sync(&priv->timer); del_timer_sync(&priv->timer);
out_free:
kfree(priv);
return err; return err;
} }
static int timeriomem_rng_remove(struct platform_device *pdev) static int timeriomem_rng_remove(struct platform_device *pdev)
{ {
struct timeriomem_rng_private_data *priv = platform_get_drvdata(pdev); struct timeriomem_rng_private_data *priv = platform_get_drvdata(pdev);
struct resource *res;
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
hwrng_unregister(&priv->timeriomem_rng_ops); hwrng_unregister(&priv->timeriomem_rng_ops);
del_timer_sync(&priv->timer); del_timer_sync(&priv->timer);
iounmap(priv->io_base);
release_mem_region(res->start, resource_size(res));
kfree(priv);
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