aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-m48t59.c
diff options
context:
space:
mode:
authorJingoo Han <jg1.han@samsung.com>2013-07-03 18:07:08 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 19:07:55 -0400
commit19b8d8875fd5f231135a55bfe53337859ec73a4a (patch)
tree0e6a2558763ba6fcd1501143b1881dab515d0df4 /drivers/rtc/rtc-m48t59.c
parent073bf424602992427e3dbf83a1dca47ed119326a (diff)
rtc: rtc-m48t59: 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-m48t59.c')
-rw-r--r--drivers/rtc/rtc-m48t59.c53
1 files changed, 17 insertions, 36 deletions
diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
index d4d31fa19244..fcb03291f145 100644
--- a/drivers/rtc/rtc-m48t59.c
+++ b/drivers/rtc/rtc-m48t59.c
@@ -409,7 +409,8 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
409 } else if (res->flags & IORESOURCE_MEM) { 409 } else if (res->flags & IORESOURCE_MEM) {
410 /* we are memory-mapped */ 410 /* we are memory-mapped */
411 if (!pdata) { 411 if (!pdata) {
412 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL); 412 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata),
413 GFP_KERNEL);
413 if (!pdata) 414 if (!pdata)
414 return -ENOMEM; 415 return -ENOMEM;
415 /* Ensure we only kmalloc platform data once */ 416 /* Ensure we only kmalloc platform data once */
@@ -425,7 +426,7 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
425 pdata->read_byte = m48t59_mem_readb; 426 pdata->read_byte = m48t59_mem_readb;
426 } 427 }
427 428
428 m48t59 = kzalloc(sizeof(*m48t59), GFP_KERNEL); 429 m48t59 = devm_kzalloc(&pdev->dev, sizeof(*m48t59), GFP_KERNEL);
429 if (!m48t59) 430 if (!m48t59)
430 return -ENOMEM; 431 return -ENOMEM;
431 432
@@ -433,9 +434,10 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
433 434
434 if (!m48t59->ioaddr) { 435 if (!m48t59->ioaddr) {
435 /* ioaddr not mapped externally */ 436 /* ioaddr not mapped externally */
436 m48t59->ioaddr = ioremap(res->start, resource_size(res)); 437 m48t59->ioaddr = devm_ioremap(&pdev->dev, res->start,
438 resource_size(res));
437 if (!m48t59->ioaddr) 439 if (!m48t59->ioaddr)
438 goto out; 440 return ret;
439 } 441 }
440 442
441 /* Try to get irq number. We also can work in 443 /* Try to get irq number. We also can work in
@@ -446,10 +448,11 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
446 m48t59->irq = NO_IRQ; 448 m48t59->irq = NO_IRQ;
447 449
448 if (m48t59->irq != NO_IRQ) { 450 if (m48t59->irq != NO_IRQ) {
449 ret = request_irq(m48t59->irq, m48t59_rtc_interrupt, 451 ret = devm_request_irq(&pdev->dev, m48t59->irq,
450 IRQF_SHARED, "rtc-m48t59", &pdev->dev); 452 m48t59_rtc_interrupt, IRQF_SHARED,
453 "rtc-m48t59", &pdev->dev);
451 if (ret) 454 if (ret)
452 goto out; 455 return ret;
453 } 456 }
454 switch (pdata->type) { 457 switch (pdata->type) {
455 case M48T59RTC_TYPE_M48T59: 458 case M48T59RTC_TYPE_M48T59:
@@ -469,51 +472,29 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
469 break; 472 break;
470 default: 473 default:
471 dev_err(&pdev->dev, "Unknown RTC type\n"); 474 dev_err(&pdev->dev, "Unknown RTC type\n");
472 ret = -ENODEV; 475 return -ENODEV;
473 goto out;
474 } 476 }
475 477
476 spin_lock_init(&m48t59->lock); 478 spin_lock_init(&m48t59->lock);
477 platform_set_drvdata(pdev, m48t59); 479 platform_set_drvdata(pdev, m48t59);
478 480
479 m48t59->rtc = rtc_device_register(name, &pdev->dev, ops, THIS_MODULE); 481 m48t59->rtc = devm_rtc_device_register(&pdev->dev, name, ops,
480 if (IS_ERR(m48t59->rtc)) { 482 THIS_MODULE);
481 ret = PTR_ERR(m48t59->rtc); 483 if (IS_ERR(m48t59->rtc))
482 goto out; 484 return PTR_ERR(m48t59->rtc);
483 }
484 485
485 m48t59_nvram_attr.size = pdata->offset; 486 m48t59_nvram_attr.size = pdata->offset;
486 487
487 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr); 488 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
488 if (ret) { 489 if (ret)
489 rtc_device_unregister(m48t59->rtc); 490 return ret;
490 goto out;
491 }
492 491
493 return 0; 492 return 0;
494
495out:
496 if (m48t59->irq != NO_IRQ)
497 free_irq(m48t59->irq, &pdev->dev);
498 if (m48t59->ioaddr)
499 iounmap(m48t59->ioaddr);
500 kfree(m48t59);
501 return ret;
502} 493}
503 494
504static int m48t59_rtc_remove(struct platform_device *pdev) 495static int m48t59_rtc_remove(struct platform_device *pdev)
505{ 496{
506 struct m48t59_private *m48t59 = platform_get_drvdata(pdev);
507 struct m48t59_plat_data *pdata = pdev->dev.platform_data;
508
509 sysfs_remove_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr); 497 sysfs_remove_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
510 if (!IS_ERR(m48t59->rtc))
511 rtc_device_unregister(m48t59->rtc);
512 if (m48t59->ioaddr && !pdata->ioaddr)
513 iounmap(m48t59->ioaddr);
514 if (m48t59->irq != NO_IRQ)
515 free_irq(m48t59->irq, &pdev->dev);
516 kfree(m48t59);
517 return 0; 498 return 0;
518} 499}
519 500