Commit d64132ac authored by Sachin Kamat's avatar Sachin Kamat Committed by Linus Torvalds

drivers/rtc/rtc-at32ap700x.c: use devm_* APIs

devm_* functions are device managed and make cleanup code simpler.
Signed-off-by: default avatarSachin Kamat <sachin.kamat@linaro.org>
Cc: Hans-Christian Egtvedt <hcegtvedt@atmel.com>
Cc: Jingoo 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 3087b3d0
...@@ -202,7 +202,8 @@ static int __init at32_rtc_probe(struct platform_device *pdev) ...@@ -202,7 +202,8 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
int irq; int irq;
int ret; int ret;
rtc = kzalloc(sizeof(struct rtc_at32ap700x), GFP_KERNEL); rtc = devm_kzalloc(&pdev->dev, sizeof(struct rtc_at32ap700x),
GFP_KERNEL);
if (!rtc) { if (!rtc) {
dev_dbg(&pdev->dev, "out of memory\n"); dev_dbg(&pdev->dev, "out of memory\n");
return -ENOMEM; return -ENOMEM;
...@@ -223,7 +224,7 @@ static int __init at32_rtc_probe(struct platform_device *pdev) ...@@ -223,7 +224,7 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
} }
rtc->irq = irq; rtc->irq = irq;
rtc->regs = ioremap(regs->start, resource_size(regs)); rtc->regs = devm_ioremap(&pdev->dev, regs->start, resource_size(regs));
if (!rtc->regs) { if (!rtc->regs) {
ret = -ENOMEM; ret = -ENOMEM;
dev_dbg(&pdev->dev, "could not map I/O memory\n"); dev_dbg(&pdev->dev, "could not map I/O memory\n");
...@@ -244,20 +245,21 @@ static int __init at32_rtc_probe(struct platform_device *pdev) ...@@ -244,20 +245,21 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
| RTC_BIT(CTRL_EN)); | RTC_BIT(CTRL_EN));
} }
ret = request_irq(irq, at32_rtc_interrupt, IRQF_SHARED, "rtc", rtc); ret = devm_request_irq(&pdev->dev, irq, at32_rtc_interrupt, IRQF_SHARED,
"rtc", rtc);
if (ret) { if (ret) {
dev_dbg(&pdev->dev, "could not request irq %d\n", irq); dev_dbg(&pdev->dev, "could not request irq %d\n", irq);
goto out_iounmap; goto out;
} }
platform_set_drvdata(pdev, rtc); platform_set_drvdata(pdev, rtc);
rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
&at32_rtc_ops, THIS_MODULE); &at32_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc->rtc)) { if (IS_ERR(rtc->rtc)) {
dev_dbg(&pdev->dev, "could not register rtc device\n"); dev_dbg(&pdev->dev, "could not register rtc device\n");
ret = PTR_ERR(rtc->rtc); ret = PTR_ERR(rtc->rtc);
goto out_free_irq; goto out;
} }
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
...@@ -267,26 +269,15 @@ static int __init at32_rtc_probe(struct platform_device *pdev) ...@@ -267,26 +269,15 @@ static int __init at32_rtc_probe(struct platform_device *pdev)
return 0; return 0;
out_free_irq:
platform_set_drvdata(pdev, NULL);
free_irq(irq, rtc);
out_iounmap:
iounmap(rtc->regs);
out: out:
kfree(rtc); platform_set_drvdata(pdev, NULL);
return ret; return ret;
} }
static int __exit at32_rtc_remove(struct platform_device *pdev) static int __exit at32_rtc_remove(struct platform_device *pdev)
{ {
struct rtc_at32ap700x *rtc = platform_get_drvdata(pdev);
device_init_wakeup(&pdev->dev, 0); device_init_wakeup(&pdev->dev, 0);
free_irq(rtc->irq, rtc);
iounmap(rtc->regs);
rtc_device_unregister(rtc->rtc);
kfree(rtc);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
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