aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-ds1216.c
diff options
context:
space:
mode:
authorJingoo Han <jg1.han@samsung.com>2013-04-29 19:20:37 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 21:28:36 -0400
commit15c1567a71ee4690586780c261ebedc03bb774e5 (patch)
tree46a349f1c3afaf63509b123eba300671fefe7dcd /drivers/rtc/rtc-ds1216.c
parent26c5f7d93adbe440bc7db95c1e4f1b1820e403a1 (diff)
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>
Diffstat (limited to 'drivers/rtc/rtc-ds1216.c')
-rw-r--r--drivers/rtc/rtc-ds1216.c44
1 files changed, 9 insertions, 35 deletions
diff --git a/drivers/rtc/rtc-ds1216.c b/drivers/rtc/rtc-ds1216.c
index 45cd8c9f5a39..c7702b7269f7 100644
--- a/drivers/rtc/rtc-ds1216.c
+++ b/drivers/rtc/rtc-ds1216.c
@@ -30,8 +30,6 @@ struct ds1216_regs {
30struct ds1216_priv { 30struct ds1216_priv {
31 struct rtc_device *rtc; 31 struct rtc_device *rtc;
32 void __iomem *ioaddr; 32 void __iomem *ioaddr;
33 size_t size;
34 unsigned long baseaddr;
35}; 33};
36 34
37static const u8 magic[] = { 35static const u8 magic[] = {
@@ -144,57 +142,33 @@ static int __init ds1216_rtc_probe(struct platform_device *pdev)
144{ 142{
145 struct resource *res; 143 struct resource *res;
146 struct ds1216_priv *priv; 144 struct ds1216_priv *priv;
147 int ret = 0;
148 u8 dummy[8]; 145 u8 dummy[8];
149 146
150 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 147 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
151 if (!res) 148 if (!res)
152 return -ENODEV; 149 return -ENODEV;
153 priv = kzalloc(sizeof *priv, GFP_KERNEL); 150 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL);
154 if (!priv) 151 if (!priv)
155 return -ENOMEM; 152 return -ENOMEM;
156 153
157 platform_set_drvdata(pdev, priv); 154 platform_set_drvdata(pdev, priv);
158 155
159 priv->size = resource_size(res); 156 priv->ioaddr = devm_ioremap_resource(&pdev->dev, res);
160 if (!request_mem_region(res->start, priv->size, pdev->name)) { 157 if (IS_ERR(priv->ioaddr))
161 ret = -EBUSY; 158 return PTR_ERR(priv->ioaddr);
162 goto out; 159
163 } 160 priv->rtc = devm_rtc_device_register(&pdev->dev, "ds1216",
164 priv->baseaddr = res->start; 161 &ds1216_rtc_ops, THIS_MODULE);
165 priv->ioaddr = ioremap(priv->baseaddr, priv->size); 162 if (IS_ERR(priv->rtc))
166 if (!priv->ioaddr) { 163 return PTR_ERR(priv->rtc);
167 ret = -ENOMEM;
168 goto out;
169 }
170 priv->rtc = rtc_device_register("ds1216", &pdev->dev,
171 &ds1216_rtc_ops, THIS_MODULE);
172 if (IS_ERR(priv->rtc)) {
173 ret = PTR_ERR(priv->rtc);
174 goto out;
175 }
176 164
177 /* dummy read to get clock into a known state */ 165 /* dummy read to get clock into a known state */
178 ds1216_read(priv->ioaddr, dummy); 166 ds1216_read(priv->ioaddr, dummy);
179 return 0; 167 return 0;
180
181out:
182 if (priv->ioaddr)
183 iounmap(priv->ioaddr);
184 if (priv->baseaddr)
185 release_mem_region(priv->baseaddr, priv->size);
186 kfree(priv);
187 return ret;
188} 168}
189 169
190static int __exit ds1216_rtc_remove(struct platform_device *pdev) 170static int __exit ds1216_rtc_remove(struct platform_device *pdev)
191{ 171{
192 struct ds1216_priv *priv = platform_get_drvdata(pdev);
193
194 rtc_device_unregister(priv->rtc);
195 iounmap(priv->ioaddr);
196 release_mem_region(priv->baseaddr, priv->size);
197 kfree(priv);
198 return 0; 172 return 0;
199} 173}
200 174