diff options
author | Sachin Kamat <sachin.kamat@linaro.org> | 2013-04-29 19:20:29 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-04-29 21:28:35 -0400 |
commit | 0529bf4673a05ca688fa42a14917069278d88103 (patch) | |
tree | 7a7607a59ad8e32094503cad64bf5f31ec967c5a | |
parent | d64132ac0083d97f0a8b63f3c1759b2e9b5ed7b1 (diff) |
drivers/rtc/rtc-ds1305.c: use devm_* APIs
devm_* functions are device managed and make cleanup code simpler.
Signed-off-by: Sachin Kamat <sachin.kamat@linaro.org>
Cc: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r-- | drivers/rtc/rtc-ds1305.c | 35 |
1 files changed, 12 insertions, 23 deletions
diff --git a/drivers/rtc/rtc-ds1305.c b/drivers/rtc/rtc-ds1305.c index b05a6dc96405..bb5f13f63630 100644 --- a/drivers/rtc/rtc-ds1305.c +++ b/drivers/rtc/rtc-ds1305.c | |||
@@ -619,7 +619,7 @@ static int ds1305_probe(struct spi_device *spi) | |||
619 | return -EINVAL; | 619 | return -EINVAL; |
620 | 620 | ||
621 | /* set up driver data */ | 621 | /* set up driver data */ |
622 | ds1305 = kzalloc(sizeof *ds1305, GFP_KERNEL); | 622 | ds1305 = devm_kzalloc(&spi->dev, sizeof(*ds1305), GFP_KERNEL); |
623 | if (!ds1305) | 623 | if (!ds1305) |
624 | return -ENOMEM; | 624 | return -ENOMEM; |
625 | ds1305->spi = spi; | 625 | ds1305->spi = spi; |
@@ -632,7 +632,7 @@ static int ds1305_probe(struct spi_device *spi) | |||
632 | if (status < 0) { | 632 | if (status < 0) { |
633 | dev_dbg(&spi->dev, "can't %s, %d\n", | 633 | dev_dbg(&spi->dev, "can't %s, %d\n", |
634 | "read", status); | 634 | "read", status); |
635 | goto fail0; | 635 | return status; |
636 | } | 636 | } |
637 | 637 | ||
638 | dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "read", ds1305->ctrl); | 638 | dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "read", ds1305->ctrl); |
@@ -644,8 +644,7 @@ static int ds1305_probe(struct spi_device *spi) | |||
644 | */ | 644 | */ |
645 | if ((ds1305->ctrl[0] & 0x38) != 0 || (ds1305->ctrl[1] & 0xfc) != 0) { | 645 | if ((ds1305->ctrl[0] & 0x38) != 0 || (ds1305->ctrl[1] & 0xfc) != 0) { |
646 | dev_dbg(&spi->dev, "RTC chip is not present\n"); | 646 | dev_dbg(&spi->dev, "RTC chip is not present\n"); |
647 | status = -ENODEV; | 647 | return -ENODEV; |
648 | goto fail0; | ||
649 | } | 648 | } |
650 | if (ds1305->ctrl[2] == 0) | 649 | if (ds1305->ctrl[2] == 0) |
651 | dev_dbg(&spi->dev, "chip may not be present\n"); | 650 | dev_dbg(&spi->dev, "chip may not be present\n"); |
@@ -664,7 +663,7 @@ static int ds1305_probe(struct spi_device *spi) | |||
664 | 663 | ||
665 | dev_dbg(&spi->dev, "clear WP --> %d\n", status); | 664 | dev_dbg(&spi->dev, "clear WP --> %d\n", status); |
666 | if (status < 0) | 665 | if (status < 0) |
667 | goto fail0; | 666 | return status; |
668 | } | 667 | } |
669 | 668 | ||
670 | /* on DS1305, maybe start oscillator; like most low power | 669 | /* on DS1305, maybe start oscillator; like most low power |
@@ -718,7 +717,7 @@ static int ds1305_probe(struct spi_device *spi) | |||
718 | if (status < 0) { | 717 | if (status < 0) { |
719 | dev_dbg(&spi->dev, "can't %s, %d\n", | 718 | dev_dbg(&spi->dev, "can't %s, %d\n", |
720 | "write", status); | 719 | "write", status); |
721 | goto fail0; | 720 | return status; |
722 | } | 721 | } |
723 | 722 | ||
724 | dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "write", ds1305->ctrl); | 723 | dev_dbg(&spi->dev, "ctrl %s: %3ph\n", "write", ds1305->ctrl); |
@@ -730,7 +729,7 @@ static int ds1305_probe(struct spi_device *spi) | |||
730 | &value, sizeof value); | 729 | &value, sizeof value); |
731 | if (status < 0) { | 730 | if (status < 0) { |
732 | dev_dbg(&spi->dev, "read HOUR --> %d\n", status); | 731 | dev_dbg(&spi->dev, "read HOUR --> %d\n", status); |
733 | goto fail0; | 732 | return status; |
734 | } | 733 | } |
735 | 734 | ||
736 | ds1305->hr12 = (DS1305_HR_12 & value) != 0; | 735 | ds1305->hr12 = (DS1305_HR_12 & value) != 0; |
@@ -738,12 +737,12 @@ static int ds1305_probe(struct spi_device *spi) | |||
738 | dev_dbg(&spi->dev, "AM/PM\n"); | 737 | dev_dbg(&spi->dev, "AM/PM\n"); |
739 | 738 | ||
740 | /* register RTC ... from here on, ds1305->ctrl needs locking */ | 739 | /* register RTC ... from here on, ds1305->ctrl needs locking */ |
741 | ds1305->rtc = rtc_device_register("ds1305", &spi->dev, | 740 | ds1305->rtc = devm_rtc_device_register(&spi->dev, "ds1305", |
742 | &ds1305_ops, THIS_MODULE); | 741 | &ds1305_ops, THIS_MODULE); |
743 | if (IS_ERR(ds1305->rtc)) { | 742 | if (IS_ERR(ds1305->rtc)) { |
744 | status = PTR_ERR(ds1305->rtc); | 743 | status = PTR_ERR(ds1305->rtc); |
745 | dev_dbg(&spi->dev, "register rtc --> %d\n", status); | 744 | dev_dbg(&spi->dev, "register rtc --> %d\n", status); |
746 | goto fail0; | 745 | return status; |
747 | } | 746 | } |
748 | 747 | ||
749 | /* Maybe set up alarm IRQ; be ready to handle it triggering right | 748 | /* Maybe set up alarm IRQ; be ready to handle it triggering right |
@@ -754,12 +753,12 @@ static int ds1305_probe(struct spi_device *spi) | |||
754 | */ | 753 | */ |
755 | if (spi->irq) { | 754 | if (spi->irq) { |
756 | INIT_WORK(&ds1305->work, ds1305_work); | 755 | INIT_WORK(&ds1305->work, ds1305_work); |
757 | status = request_irq(spi->irq, ds1305_irq, | 756 | status = devm_request_irq(&spi->dev, spi->irq, ds1305_irq, |
758 | 0, dev_name(&ds1305->rtc->dev), ds1305); | 757 | 0, dev_name(&ds1305->rtc->dev), ds1305); |
759 | if (status < 0) { | 758 | if (status < 0) { |
760 | dev_dbg(&spi->dev, "request_irq %d --> %d\n", | 759 | dev_dbg(&spi->dev, "request_irq %d --> %d\n", |
761 | spi->irq, status); | 760 | spi->irq, status); |
762 | goto fail1; | 761 | return status; |
763 | } | 762 | } |
764 | 763 | ||
765 | device_set_wakeup_capable(&spi->dev, 1); | 764 | device_set_wakeup_capable(&spi->dev, 1); |
@@ -769,18 +768,10 @@ static int ds1305_probe(struct spi_device *spi) | |||
769 | status = sysfs_create_bin_file(&spi->dev.kobj, &nvram); | 768 | status = sysfs_create_bin_file(&spi->dev.kobj, &nvram); |
770 | if (status < 0) { | 769 | if (status < 0) { |
771 | dev_dbg(&spi->dev, "register nvram --> %d\n", status); | 770 | dev_dbg(&spi->dev, "register nvram --> %d\n", status); |
772 | goto fail2; | 771 | return status; |
773 | } | 772 | } |
774 | 773 | ||
775 | return 0; | 774 | return 0; |
776 | |||
777 | fail2: | ||
778 | free_irq(spi->irq, ds1305); | ||
779 | fail1: | ||
780 | rtc_device_unregister(ds1305->rtc); | ||
781 | fail0: | ||
782 | kfree(ds1305); | ||
783 | return status; | ||
784 | } | 775 | } |
785 | 776 | ||
786 | static int ds1305_remove(struct spi_device *spi) | 777 | static int ds1305_remove(struct spi_device *spi) |
@@ -792,13 +783,11 @@ static int ds1305_remove(struct spi_device *spi) | |||
792 | /* carefully shut down irq and workqueue, if present */ | 783 | /* carefully shut down irq and workqueue, if present */ |
793 | if (spi->irq) { | 784 | if (spi->irq) { |
794 | set_bit(FLAG_EXITING, &ds1305->flags); | 785 | set_bit(FLAG_EXITING, &ds1305->flags); |
795 | free_irq(spi->irq, ds1305); | 786 | devm_free_irq(&spi->dev, spi->irq, ds1305); |
796 | cancel_work_sync(&ds1305->work); | 787 | cancel_work_sync(&ds1305->work); |
797 | } | 788 | } |
798 | 789 | ||
799 | rtc_device_unregister(ds1305->rtc); | ||
800 | spi_set_drvdata(spi, NULL); | 790 | spi_set_drvdata(spi, NULL); |
801 | kfree(ds1305); | ||
802 | return 0; | 791 | return 0; |
803 | } | 792 | } |
804 | 793 | ||