Commit 0209affa authored by Jingoo Han's avatar Jingoo Han Committed by Linus Torvalds

rtc: rtc-sh: 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 avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent fac42b41
...@@ -593,7 +593,7 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -593,7 +593,7 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
char clk_name[6]; char clk_name[6];
int clk_id, ret; int clk_id, ret;
rtc = kzalloc(sizeof(struct sh_rtc), GFP_KERNEL); rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
if (unlikely(!rtc)) if (unlikely(!rtc))
return -ENOMEM; return -ENOMEM;
...@@ -602,9 +602,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -602,9 +602,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
/* get periodic/carry/alarm irqs */ /* get periodic/carry/alarm irqs */
ret = platform_get_irq(pdev, 0); ret = platform_get_irq(pdev, 0);
if (unlikely(ret <= 0)) { if (unlikely(ret <= 0)) {
ret = -ENOENT;
dev_err(&pdev->dev, "No IRQ resource\n"); dev_err(&pdev->dev, "No IRQ resource\n");
goto err_badres; return -ENOENT;
} }
rtc->periodic_irq = ret; rtc->periodic_irq = ret;
...@@ -613,24 +612,21 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -613,24 +612,21 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_IO, 0); res = platform_get_resource(pdev, IORESOURCE_IO, 0);
if (unlikely(res == NULL)) { if (unlikely(res == NULL)) {
ret = -ENOENT;
dev_err(&pdev->dev, "No IO resource\n"); dev_err(&pdev->dev, "No IO resource\n");
goto err_badres; return -ENOENT;
} }
rtc->regsize = resource_size(res); rtc->regsize = resource_size(res);
rtc->res = request_mem_region(res->start, rtc->regsize, pdev->name); rtc->res = devm_request_mem_region(&pdev->dev, res->start,
if (unlikely(!rtc->res)) { rtc->regsize, pdev->name);
ret = -EBUSY; if (unlikely(!rtc->res))
goto err_badres; return -EBUSY;
}
rtc->regbase = ioremap_nocache(rtc->res->start, rtc->regsize); rtc->regbase = devm_ioremap_nocache(&pdev->dev, rtc->res->start,
if (unlikely(!rtc->regbase)) { rtc->regsize);
ret = -EINVAL; if (unlikely(!rtc->regbase))
goto err_badmap; return -EINVAL;
}
clk_id = pdev->id; clk_id = pdev->id;
/* With a single device, the clock id is still "rtc0" */ /* With a single device, the clock id is still "rtc0" */
...@@ -639,7 +635,7 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -639,7 +635,7 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
snprintf(clk_name, sizeof(clk_name), "rtc%d", clk_id); snprintf(clk_name, sizeof(clk_name), "rtc%d", clk_id);
rtc->clk = clk_get(&pdev->dev, clk_name); rtc->clk = devm_clk_get(&pdev->dev, clk_name);
if (IS_ERR(rtc->clk)) { if (IS_ERR(rtc->clk)) {
/* /*
* No error handling for rtc->clk intentionally, not all * No error handling for rtc->clk intentionally, not all
...@@ -665,8 +661,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -665,8 +661,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
if (rtc->carry_irq <= 0) { if (rtc->carry_irq <= 0) {
/* register shared periodic/carry/alarm irq */ /* register shared periodic/carry/alarm irq */
ret = request_irq(rtc->periodic_irq, sh_rtc_shared, ret = devm_request_irq(&pdev->dev, rtc->periodic_irq,
0, "sh-rtc", rtc); sh_rtc_shared, 0, "sh-rtc", rtc);
if (unlikely(ret)) { if (unlikely(ret)) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"request IRQ failed with %d, IRQ %d\n", ret, "request IRQ failed with %d, IRQ %d\n", ret,
...@@ -675,8 +671,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -675,8 +671,8 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
} }
} else { } else {
/* register periodic/carry/alarm irqs */ /* register periodic/carry/alarm irqs */
ret = request_irq(rtc->periodic_irq, sh_rtc_periodic, ret = devm_request_irq(&pdev->dev, rtc->periodic_irq,
0, "sh-rtc period", rtc); sh_rtc_periodic, 0, "sh-rtc period", rtc);
if (unlikely(ret)) { if (unlikely(ret)) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"request period IRQ failed with %d, IRQ %d\n", "request period IRQ failed with %d, IRQ %d\n",
...@@ -684,24 +680,21 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -684,24 +680,21 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
goto err_unmap; goto err_unmap;
} }
ret = request_irq(rtc->carry_irq, sh_rtc_interrupt, ret = devm_request_irq(&pdev->dev, rtc->carry_irq,
0, "sh-rtc carry", rtc); sh_rtc_interrupt, 0, "sh-rtc carry", rtc);
if (unlikely(ret)) { if (unlikely(ret)) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"request carry IRQ failed with %d, IRQ %d\n", "request carry IRQ failed with %d, IRQ %d\n",
ret, rtc->carry_irq); ret, rtc->carry_irq);
free_irq(rtc->periodic_irq, rtc);
goto err_unmap; goto err_unmap;
} }
ret = request_irq(rtc->alarm_irq, sh_rtc_alarm, ret = devm_request_irq(&pdev->dev, rtc->alarm_irq,
0, "sh-rtc alarm", rtc); sh_rtc_alarm, 0, "sh-rtc alarm", rtc);
if (unlikely(ret)) { if (unlikely(ret)) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"request alarm IRQ failed with %d, IRQ %d\n", "request alarm IRQ failed with %d, IRQ %d\n",
ret, rtc->alarm_irq); ret, rtc->alarm_irq);
free_irq(rtc->carry_irq, rtc);
free_irq(rtc->periodic_irq, rtc);
goto err_unmap; goto err_unmap;
} }
} }
...@@ -714,13 +707,10 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -714,13 +707,10 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
sh_rtc_setaie(&pdev->dev, 0); sh_rtc_setaie(&pdev->dev, 0);
sh_rtc_setcie(&pdev->dev, 0); sh_rtc_setcie(&pdev->dev, 0);
rtc->rtc_dev = rtc_device_register("sh", &pdev->dev, rtc->rtc_dev = devm_rtc_device_register(&pdev->dev, "sh",
&sh_rtc_ops, THIS_MODULE); &sh_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc->rtc_dev)) { if (IS_ERR(rtc->rtc_dev)) {
ret = PTR_ERR(rtc->rtc_dev); ret = PTR_ERR(rtc->rtc_dev);
free_irq(rtc->periodic_irq, rtc);
free_irq(rtc->carry_irq, rtc);
free_irq(rtc->alarm_irq, rtc);
goto err_unmap; goto err_unmap;
} }
...@@ -737,12 +727,6 @@ static int __init sh_rtc_probe(struct platform_device *pdev) ...@@ -737,12 +727,6 @@ static int __init sh_rtc_probe(struct platform_device *pdev)
err_unmap: err_unmap:
clk_disable(rtc->clk); clk_disable(rtc->clk);
clk_put(rtc->clk);
iounmap(rtc->regbase);
err_badmap:
release_mem_region(rtc->res->start, rtc->regsize);
err_badres:
kfree(rtc);
return ret; return ret;
} }
...@@ -751,26 +735,12 @@ static int __exit sh_rtc_remove(struct platform_device *pdev) ...@@ -751,26 +735,12 @@ static int __exit sh_rtc_remove(struct platform_device *pdev)
{ {
struct sh_rtc *rtc = platform_get_drvdata(pdev); struct sh_rtc *rtc = platform_get_drvdata(pdev);
rtc_device_unregister(rtc->rtc_dev);
sh_rtc_irq_set_state(&pdev->dev, 0); sh_rtc_irq_set_state(&pdev->dev, 0);
sh_rtc_setaie(&pdev->dev, 0); sh_rtc_setaie(&pdev->dev, 0);
sh_rtc_setcie(&pdev->dev, 0); sh_rtc_setcie(&pdev->dev, 0);
free_irq(rtc->periodic_irq, rtc);
if (rtc->carry_irq > 0) {
free_irq(rtc->carry_irq, rtc);
free_irq(rtc->alarm_irq, rtc);
}
iounmap(rtc->regbase);
release_mem_region(rtc->res->start, rtc->regsize);
clk_disable(rtc->clk); clk_disable(rtc->clk);
clk_put(rtc->clk);
kfree(rtc);
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