rtc: rtc-stmp3xxx: use devm_*() functions
authorJingoo Han <jg1.han@samsung.com>
Mon, 29 Apr 2013 23:20:55 +0000 (16:20 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 30 Apr 2013 01:28:39 +0000 (18:28 -0700)
Use devm_*() functions to make cleanup paths simpler.

Signed-off-by: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
drivers/rtc/rtc-stmp3xxx.c

index 98f0d3c30738bb2cc48238613af255fbdf6789a2..0930f275b2dd0f19140f548a9355cb14576c96ee 100644 (file)
@@ -227,11 +227,7 @@ static int stmp3xxx_rtc_remove(struct platform_device *pdev)
 
        writel(STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
                        rtc_data->io + STMP3XXX_RTC_CTRL_CLR);
-       free_irq(rtc_data->irq_alarm, &pdev->dev);
-       rtc_device_unregister(rtc_data->rtc);
        platform_set_drvdata(pdev, NULL);
-       iounmap(rtc_data->io);
-       kfree(rtc_data);
 
        return 0;
 }
@@ -242,22 +238,20 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
        struct resource *r;
        int err;
 
-       rtc_data = kzalloc(sizeof *rtc_data, GFP_KERNEL);
+       rtc_data = devm_kzalloc(&pdev->dev, sizeof(*rtc_data), GFP_KERNEL);
        if (!rtc_data)
                return -ENOMEM;
 
        r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
        if (!r) {
                dev_err(&pdev->dev, "failed to get resource\n");
-               err = -ENXIO;
-               goto out_free;
+               return -ENXIO;
        }
 
-       rtc_data->io = ioremap(r->start, resource_size(r));
+       rtc_data->io = devm_ioremap(&pdev->dev, r->start, resource_size(r));
        if (!rtc_data->io) {
                dev_err(&pdev->dev, "ioremap failed\n");
-               err = -EIO;
-               goto out_free;
+               return -EIO;
        }
 
        rtc_data->irq_alarm = platform_get_irq(pdev, 0);
@@ -265,8 +259,7 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
        if (!(readl(STMP3XXX_RTC_STAT + rtc_data->io) &
                        STMP3XXX_RTC_STAT_RTC_PRESENT)) {
                dev_err(&pdev->dev, "no device onboard\n");
-               err = -ENODEV;
-               goto out_remap;
+               return -ENODEV;
        }
 
        platform_set_drvdata(pdev, rtc_data);
@@ -281,31 +274,26 @@ static int stmp3xxx_rtc_probe(struct platform_device *pdev)
                        STMP3XXX_RTC_CTRL_ALARM_IRQ_EN,
                        rtc_data->io + STMP3XXX_RTC_CTRL_CLR);
 
-       rtc_data->rtc = rtc_device_register(pdev->name, &pdev->dev,
+       rtc_data->rtc = devm_rtc_device_register(&pdev->dev, pdev->name,
                                &stmp3xxx_rtc_ops, THIS_MODULE);
        if (IS_ERR(rtc_data->rtc)) {
                err = PTR_ERR(rtc_data->rtc);
-               goto out_remap;
+               goto out;
        }
 
-       err = request_irq(rtc_data->irq_alarm, stmp3xxx_rtc_interrupt, 0,
-                       "RTC alarm", &pdev->dev);
+       err = devm_request_irq(&pdev->dev, rtc_data->irq_alarm,
+                       stmp3xxx_rtc_interrupt, 0, "RTC alarm", &pdev->dev);
        if (err) {
                dev_err(&pdev->dev, "Cannot claim IRQ%d\n",
                        rtc_data->irq_alarm);
-               goto out_irq_alarm;
+               goto out;
        }
 
        stmp3xxx_wdt_register(pdev);
        return 0;
 
-out_irq_alarm:
-       rtc_device_unregister(rtc_data->rtc);
-out_remap:
+out:
        platform_set_drvdata(pdev, NULL);
-       iounmap(rtc_data->io);
-out_free:
-       kfree(rtc_data);
        return err;
 }