Skip to content

Commit

Permalink
rtc: rtc-vt8500: use devm_*() functions
Browse files Browse the repository at this point in the history
Use devm_*() functions to make cleanup paths more simple.

Signed-off-by: Jingoo Han <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Jingoo Han authored and torvalds committed Feb 22, 2013
1 parent 190ab4a commit 0db29c1
Showing 1 changed file with 10 additions and 18 deletions.
28 changes: 10 additions & 18 deletions drivers/rtc/rtc-vt8500.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,20 +231,21 @@ static int vt8500_rtc_probe(struct platform_device *pdev)
return -ENXIO;
}

vt8500_rtc->res = request_mem_region(vt8500_rtc->res->start,
resource_size(vt8500_rtc->res),
"vt8500-rtc");
vt8500_rtc->res = devm_request_mem_region(&pdev->dev,
vt8500_rtc->res->start,
resource_size(vt8500_rtc->res),
"vt8500-rtc");
if (vt8500_rtc->res == NULL) {
dev_err(&pdev->dev, "failed to request I/O memory\n");
return -EBUSY;
}

vt8500_rtc->regbase = ioremap(vt8500_rtc->res->start,
vt8500_rtc->regbase = devm_ioremap(&pdev->dev, vt8500_rtc->res->start,
resource_size(vt8500_rtc->res));
if (!vt8500_rtc->regbase) {
dev_err(&pdev->dev, "Unable to map RTC I/O memory\n");
ret = -EBUSY;
goto err_release;
goto err_return;
}

/* Enable RTC and set it to 24-hour mode */
Expand All @@ -257,11 +258,11 @@ static int vt8500_rtc_probe(struct platform_device *pdev)
ret = PTR_ERR(vt8500_rtc->rtc);
dev_err(&pdev->dev,
"Failed to register RTC device -> %d\n", ret);
goto err_unmap;
goto err_return;
}

ret = request_irq(vt8500_rtc->irq_alarm, vt8500_rtc_irq, 0,
"rtc alarm", vt8500_rtc);
ret = devm_request_irq(&pdev->dev, vt8500_rtc->irq_alarm,
vt8500_rtc_irq, 0, "rtc alarm", vt8500_rtc);
if (ret < 0) {
dev_err(&pdev->dev, "can't get irq %i, err %d\n",
vt8500_rtc->irq_alarm, ret);
Expand All @@ -272,27 +273,18 @@ static int vt8500_rtc_probe(struct platform_device *pdev)

err_unreg:
rtc_device_unregister(vt8500_rtc->rtc);
err_unmap:
iounmap(vt8500_rtc->regbase);
err_release:
release_mem_region(vt8500_rtc->res->start,
resource_size(vt8500_rtc->res));
err_return:
return ret;
}

static int vt8500_rtc_remove(struct platform_device *pdev)
{
struct vt8500_rtc *vt8500_rtc = platform_get_drvdata(pdev);

free_irq(vt8500_rtc->irq_alarm, vt8500_rtc);

rtc_device_unregister(vt8500_rtc->rtc);

/* Disable alarm matching */
writel(0, vt8500_rtc->regbase + VT8500_RTC_IS);
iounmap(vt8500_rtc->regbase);
release_mem_region(vt8500_rtc->res->start,
resource_size(vt8500_rtc->res));

platform_set_drvdata(pdev, NULL);

Expand Down

0 comments on commit 0db29c1

Please sign in to comment.