rtc: rtc-ds1216: use devm_*() functions

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>
This commit is contained in:
Jingoo Han 2013-04-29 16:20:37 -07:00 committed by Linus Torvalds
parent 26c5f7d93a
commit 15c1567a71

View File

@ -30,8 +30,6 @@ struct ds1216_regs {
struct ds1216_priv { struct ds1216_priv {
struct rtc_device *rtc; struct rtc_device *rtc;
void __iomem *ioaddr; void __iomem *ioaddr;
size_t size;
unsigned long baseaddr;
}; };
static const u8 magic[] = { static const u8 magic[] = {
@ -144,57 +142,33 @@ static int __init ds1216_rtc_probe(struct platform_device *pdev)
{ {
struct resource *res; struct resource *res;
struct ds1216_priv *priv; struct ds1216_priv *priv;
int ret = 0;
u8 dummy[8]; u8 dummy[8];
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) if (!res)
return -ENODEV; return -ENODEV;
priv = kzalloc(sizeof *priv, GFP_KERNEL); priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
platform_set_drvdata(pdev, priv); platform_set_drvdata(pdev, priv);
priv->size = resource_size(res); priv->ioaddr = devm_ioremap_resource(&pdev->dev, res);
if (!request_mem_region(res->start, priv->size, pdev->name)) { if (IS_ERR(priv->ioaddr))
ret = -EBUSY; return PTR_ERR(priv->ioaddr);
goto out;
} priv->rtc = devm_rtc_device_register(&pdev->dev, "ds1216",
priv->baseaddr = res->start;
priv->ioaddr = ioremap(priv->baseaddr, priv->size);
if (!priv->ioaddr) {
ret = -ENOMEM;
goto out;
}
priv->rtc = rtc_device_register("ds1216", &pdev->dev,
&ds1216_rtc_ops, THIS_MODULE); &ds1216_rtc_ops, THIS_MODULE);
if (IS_ERR(priv->rtc)) { if (IS_ERR(priv->rtc))
ret = PTR_ERR(priv->rtc); return PTR_ERR(priv->rtc);
goto out;
}
/* dummy read to get clock into a known state */ /* dummy read to get clock into a known state */
ds1216_read(priv->ioaddr, dummy); ds1216_read(priv->ioaddr, dummy);
return 0; return 0;
out:
if (priv->ioaddr)
iounmap(priv->ioaddr);
if (priv->baseaddr)
release_mem_region(priv->baseaddr, priv->size);
kfree(priv);
return ret;
} }
static int __exit ds1216_rtc_remove(struct platform_device *pdev) static int __exit ds1216_rtc_remove(struct platform_device *pdev)
{ {
struct ds1216_priv *priv = platform_get_drvdata(pdev);
rtc_device_unregister(priv->rtc);
iounmap(priv->ioaddr);
release_mem_region(priv->baseaddr, priv->size);
kfree(priv);
return 0; return 0;
} }