Commit a63794fefd850a97fe07cfc017f52ea1bb777e75

Authored by Jingoo Han
Committed by Linus Torvalds
1 parent c40dcf6e8c

rtc: rtc-nuc900: 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>

Showing 1 changed file with 11 additions and 42 deletions Side-by-side Diff

drivers/rtc/rtc-nuc900.c
... ... @@ -226,9 +226,9 @@
226 226 {
227 227 struct resource *res;
228 228 struct nuc900_rtc *nuc900_rtc;
229   - int err = 0;
230 229  
231   - nuc900_rtc = kzalloc(sizeof(struct nuc900_rtc), GFP_KERNEL);
  230 + nuc900_rtc = devm_kzalloc(&pdev->dev, sizeof(struct nuc900_rtc),
  231 + GFP_KERNEL);
232 232 if (!nuc900_rtc) {
233 233 dev_err(&pdev->dev, "kzalloc nuc900_rtc failed\n");
234 234 return -ENOMEM;
235 235  
236 236  
237 237  
238 238  
239 239  
240 240  
241 241  
242 242  
... ... @@ -236,68 +236,37 @@
236 236 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
237 237 if (!res) {
238 238 dev_err(&pdev->dev, "platform_get_resource failed\n");
239   - err = -ENXIO;
240   - goto fail1;
  239 + return -ENXIO;
241 240 }
242 241  
243   - if (!request_mem_region(res->start, resource_size(res),
244   - pdev->name)) {
245   - dev_err(&pdev->dev, "request_mem_region failed\n");
246   - err = -EBUSY;
247   - goto fail1;
248   - }
  242 + nuc900_rtc->rtc_reg = devm_ioremap_resource(&pdev->dev, res);
  243 + if (IS_ERR(nuc900_rtc->rtc_reg))
  244 + return PTR_ERR(nuc900_rtc->rtc_reg);
249 245  
250   - nuc900_rtc->rtc_reg = ioremap(res->start, resource_size(res));
251   - if (!nuc900_rtc->rtc_reg) {
252   - dev_err(&pdev->dev, "ioremap rtc_reg failed\n");
253   - err = -ENOMEM;
254   - goto fail2;
255   - }
256   -
257 246 platform_set_drvdata(pdev, nuc900_rtc);
258 247  
259   - nuc900_rtc->rtcdev = rtc_device_register(pdev->name, &pdev->dev,
  248 + nuc900_rtc->rtcdev = devm_rtc_device_register(&pdev->dev, pdev->name,
260 249 &nuc900_rtc_ops, THIS_MODULE);
261 250 if (IS_ERR(nuc900_rtc->rtcdev)) {
262 251 dev_err(&pdev->dev, "rtc device register failed\n");
263   - err = PTR_ERR(nuc900_rtc->rtcdev);
264   - goto fail3;
  252 + return PTR_ERR(nuc900_rtc->rtcdev);
265 253 }
266 254  
267 255 __raw_writel(__raw_readl(nuc900_rtc->rtc_reg + REG_RTC_TSSR) | MODE24,
268 256 nuc900_rtc->rtc_reg + REG_RTC_TSSR);
269 257  
270 258 nuc900_rtc->irq_num = platform_get_irq(pdev, 0);
271   - if (request_irq(nuc900_rtc->irq_num, nuc900_rtc_interrupt,
272   - 0, "nuc900rtc", nuc900_rtc)) {
  259 + if (devm_request_irq(&pdev->dev, nuc900_rtc->irq_num,
  260 + nuc900_rtc_interrupt, 0, "nuc900rtc", nuc900_rtc)) {
273 261 dev_err(&pdev->dev, "NUC900 RTC request irq failed\n");
274   - err = -EBUSY;
275   - goto fail4;
  262 + return -EBUSY;
276 263 }
277 264  
278 265 return 0;
279   -
280   -fail4: rtc_device_unregister(nuc900_rtc->rtcdev);
281   -fail3: iounmap(nuc900_rtc->rtc_reg);
282   -fail2: release_mem_region(res->start, resource_size(res));
283   -fail1: kfree(nuc900_rtc);
284   - return err;
285 266 }
286 267  
287 268 static int __exit nuc900_rtc_remove(struct platform_device *pdev)
288 269 {
289   - struct nuc900_rtc *nuc900_rtc = platform_get_drvdata(pdev);
290   - struct resource *res;
291   -
292   - free_irq(nuc900_rtc->irq_num, nuc900_rtc);
293   - rtc_device_unregister(nuc900_rtc->rtcdev);
294   - iounmap(nuc900_rtc->rtc_reg);
295   -
296   - res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
297   - release_mem_region(res->start, resource_size(res));
298   -
299   - kfree(nuc900_rtc);
300   -
301 270 platform_set_drvdata(pdev, NULL);
302 271  
303 272 return 0;