Commit c08ac489 authored by Jingoo Han's avatar Jingoo Han Committed by Linus Torvalds

rtc: rtc-jz4740: 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 edca66d2
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
* *
*/ */
#include <linux/io.h>
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
...@@ -216,37 +217,34 @@ static int jz4740_rtc_probe(struct platform_device *pdev) ...@@ -216,37 +217,34 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
struct jz4740_rtc *rtc; struct jz4740_rtc *rtc;
uint32_t scratchpad; uint32_t scratchpad;
rtc = kzalloc(sizeof(*rtc), GFP_KERNEL); rtc = devm_kzalloc(&pdev->dev, sizeof(*rtc), GFP_KERNEL);
if (!rtc) if (!rtc)
return -ENOMEM; return -ENOMEM;
rtc->irq = platform_get_irq(pdev, 0); rtc->irq = platform_get_irq(pdev, 0);
if (rtc->irq < 0) { if (rtc->irq < 0) {
ret = -ENOENT;
dev_err(&pdev->dev, "Failed to get platform irq\n"); dev_err(&pdev->dev, "Failed to get platform irq\n");
goto err_free; return -ENOENT;
} }
rtc->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); rtc->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!rtc->mem) { if (!rtc->mem) {
ret = -ENOENT;
dev_err(&pdev->dev, "Failed to get platform mmio memory\n"); dev_err(&pdev->dev, "Failed to get platform mmio memory\n");
goto err_free; return -ENOENT;
} }
rtc->mem = request_mem_region(rtc->mem->start, resource_size(rtc->mem), rtc->mem = devm_request_mem_region(&pdev->dev, rtc->mem->start,
pdev->name); resource_size(rtc->mem), pdev->name);
if (!rtc->mem) { if (!rtc->mem) {
ret = -EBUSY;
dev_err(&pdev->dev, "Failed to request mmio memory region\n"); dev_err(&pdev->dev, "Failed to request mmio memory region\n");
goto err_free; return -EBUSY;
} }
rtc->base = ioremap_nocache(rtc->mem->start, resource_size(rtc->mem)); rtc->base = devm_ioremap_nocache(&pdev->dev, rtc->mem->start,
resource_size(rtc->mem));
if (!rtc->base) { if (!rtc->base) {
ret = -EBUSY;
dev_err(&pdev->dev, "Failed to ioremap mmio memory\n"); dev_err(&pdev->dev, "Failed to ioremap mmio memory\n");
goto err_release_mem_region; return -EBUSY;
} }
spin_lock_init(&rtc->lock); spin_lock_init(&rtc->lock);
...@@ -255,19 +253,19 @@ static int jz4740_rtc_probe(struct platform_device *pdev) ...@@ -255,19 +253,19 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
device_init_wakeup(&pdev->dev, 1); device_init_wakeup(&pdev->dev, 1);
rtc->rtc = rtc_device_register(pdev->name, &pdev->dev, &jz4740_rtc_ops, rtc->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
THIS_MODULE); &jz4740_rtc_ops, THIS_MODULE);
if (IS_ERR(rtc->rtc)) { if (IS_ERR(rtc->rtc)) {
ret = PTR_ERR(rtc->rtc); ret = PTR_ERR(rtc->rtc);
dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret); dev_err(&pdev->dev, "Failed to register rtc device: %d\n", ret);
goto err_iounmap; return ret;
} }
ret = request_irq(rtc->irq, jz4740_rtc_irq, 0, ret = devm_request_irq(&pdev->dev, rtc->irq, jz4740_rtc_irq, 0,
pdev->name, rtc); pdev->name, rtc);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Failed to request rtc irq: %d\n", ret); dev_err(&pdev->dev, "Failed to request rtc irq: %d\n", ret);
goto err_unregister_rtc; return ret;
} }
scratchpad = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD); scratchpad = jz4740_rtc_reg_read(rtc, JZ_REG_RTC_SCRATCHPAD);
...@@ -276,43 +274,13 @@ static int jz4740_rtc_probe(struct platform_device *pdev) ...@@ -276,43 +274,13 @@ static int jz4740_rtc_probe(struct platform_device *pdev)
ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, 0); ret = jz4740_rtc_reg_write(rtc, JZ_REG_RTC_SEC, 0);
if (ret) { if (ret) {
dev_err(&pdev->dev, "Could not write write to RTC registers\n"); dev_err(&pdev->dev, "Could not write write to RTC registers\n");
goto err_free_irq; return ret;
} }
} }
return 0; return 0;
err_free_irq:
free_irq(rtc->irq, rtc);
err_unregister_rtc:
rtc_device_unregister(rtc->rtc);
err_iounmap:
iounmap(rtc->base);
err_release_mem_region:
release_mem_region(rtc->mem->start, resource_size(rtc->mem));
err_free:
kfree(rtc);
return ret;
} }
static int jz4740_rtc_remove(struct platform_device *pdev)
{
struct jz4740_rtc *rtc = platform_get_drvdata(pdev);
free_irq(rtc->irq, rtc);
rtc_device_unregister(rtc->rtc);
iounmap(rtc->base);
release_mem_region(rtc->mem->start, resource_size(rtc->mem));
kfree(rtc);
return 0;
}
#ifdef CONFIG_PM #ifdef CONFIG_PM
static int jz4740_rtc_suspend(struct device *dev) static int jz4740_rtc_suspend(struct device *dev)
{ {
...@@ -344,7 +312,6 @@ static const struct dev_pm_ops jz4740_pm_ops = { ...@@ -344,7 +312,6 @@ static const struct dev_pm_ops jz4740_pm_ops = {
static struct platform_driver jz4740_rtc_driver = { static struct platform_driver jz4740_rtc_driver = {
.probe = jz4740_rtc_probe, .probe = jz4740_rtc_probe,
.remove = jz4740_rtc_remove,
.driver = { .driver = {
.name = "jz4740-rtc", .name = "jz4740-rtc",
.owner = THIS_MODULE, .owner = THIS_MODULE,
......
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