diff options
author | Jingoo Han <jg1.han@samsung.com> | 2013-07-03 18:07:05 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2013-07-03 19:07:54 -0400 |
commit | edca66d2ceae6ba426b9250ffcad5bca820b146f (patch) | |
tree | 55eba0de94e2188f8c88abc476c45af5ea722bbb /drivers/rtc/rtc-ds1307.c | |
parent | 812f147853a14812b260620b19e0764cdeb71b4c (diff) |
rtc: rtc-ds1307: 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-ds1307.c')
-rw-r--r-- | drivers/rtc/rtc-ds1307.c | 43 |
1 files changed, 17 insertions, 26 deletions
diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c index b53992ab3090..ca18fd1433b3 100644 --- a/drivers/rtc/rtc-ds1307.c +++ b/drivers/rtc/rtc-ds1307.c | |||
@@ -683,7 +683,7 @@ static int ds1307_probe(struct i2c_client *client, | |||
683 | && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) | 683 | && !i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK)) |
684 | return -EIO; | 684 | return -EIO; |
685 | 685 | ||
686 | ds1307 = kzalloc(sizeof(struct ds1307), GFP_KERNEL); | 686 | ds1307 = devm_kzalloc(&client->dev, sizeof(struct ds1307), GFP_KERNEL); |
687 | if (!ds1307) | 687 | if (!ds1307) |
688 | return -ENOMEM; | 688 | return -ENOMEM; |
689 | 689 | ||
@@ -715,7 +715,7 @@ static int ds1307_probe(struct i2c_client *client, | |||
715 | if (tmp != 2) { | 715 | if (tmp != 2) { |
716 | dev_dbg(&client->dev, "read error %d\n", tmp); | 716 | dev_dbg(&client->dev, "read error %d\n", tmp); |
717 | err = -EIO; | 717 | err = -EIO; |
718 | goto exit_free; | 718 | goto exit; |
719 | } | 719 | } |
720 | 720 | ||
721 | /* oscillator off? turn it on, so clock can tick. */ | 721 | /* oscillator off? turn it on, so clock can tick. */ |
@@ -754,7 +754,7 @@ static int ds1307_probe(struct i2c_client *client, | |||
754 | if (tmp != 2) { | 754 | if (tmp != 2) { |
755 | dev_dbg(&client->dev, "read error %d\n", tmp); | 755 | dev_dbg(&client->dev, "read error %d\n", tmp); |
756 | err = -EIO; | 756 | err = -EIO; |
757 | goto exit_free; | 757 | goto exit; |
758 | } | 758 | } |
759 | 759 | ||
760 | /* oscillator off? turn it on, so clock can tick. */ | 760 | /* oscillator off? turn it on, so clock can tick. */ |
@@ -798,7 +798,7 @@ static int ds1307_probe(struct i2c_client *client, | |||
798 | if (tmp != 2) { | 798 | if (tmp != 2) { |
799 | dev_dbg(&client->dev, "read error %d\n", tmp); | 799 | dev_dbg(&client->dev, "read error %d\n", tmp); |
800 | err = -EIO; | 800 | err = -EIO; |
801 | goto exit_free; | 801 | goto exit; |
802 | } | 802 | } |
803 | 803 | ||
804 | /* correct hour */ | 804 | /* correct hour */ |
@@ -826,7 +826,7 @@ read_rtc: | |||
826 | if (tmp != 8) { | 826 | if (tmp != 8) { |
827 | dev_dbg(&client->dev, "read error %d\n", tmp); | 827 | dev_dbg(&client->dev, "read error %d\n", tmp); |
828 | err = -EIO; | 828 | err = -EIO; |
829 | goto exit_free; | 829 | goto exit; |
830 | } | 830 | } |
831 | 831 | ||
832 | /* | 832 | /* |
@@ -868,7 +868,7 @@ read_rtc: | |||
868 | if (tmp < 0) { | 868 | if (tmp < 0) { |
869 | dev_dbg(&client->dev, "read error %d\n", tmp); | 869 | dev_dbg(&client->dev, "read error %d\n", tmp); |
870 | err = -EIO; | 870 | err = -EIO; |
871 | goto exit_free; | 871 | goto exit; |
872 | } | 872 | } |
873 | 873 | ||
874 | /* oscillator fault? clear flag, and warn */ | 874 | /* oscillator fault? clear flag, and warn */ |
@@ -927,13 +927,13 @@ read_rtc: | |||
927 | bin2bcd(tmp)); | 927 | bin2bcd(tmp)); |
928 | } | 928 | } |
929 | 929 | ||
930 | ds1307->rtc = rtc_device_register(client->name, &client->dev, | 930 | ds1307->rtc = devm_rtc_device_register(&client->dev, client->name, |
931 | &ds13xx_rtc_ops, THIS_MODULE); | 931 | &ds13xx_rtc_ops, THIS_MODULE); |
932 | if (IS_ERR(ds1307->rtc)) { | 932 | if (IS_ERR(ds1307->rtc)) { |
933 | err = PTR_ERR(ds1307->rtc); | 933 | err = PTR_ERR(ds1307->rtc); |
934 | dev_err(&client->dev, | 934 | dev_err(&client->dev, |
935 | "unable to register the class device\n"); | 935 | "unable to register the class device\n"); |
936 | goto exit_free; | 936 | goto exit; |
937 | } | 937 | } |
938 | 938 | ||
939 | if (want_irq) { | 939 | if (want_irq) { |
@@ -942,7 +942,7 @@ read_rtc: | |||
942 | if (err) { | 942 | if (err) { |
943 | dev_err(&client->dev, | 943 | dev_err(&client->dev, |
944 | "unable to request IRQ!\n"); | 944 | "unable to request IRQ!\n"); |
945 | goto exit_irq; | 945 | goto exit; |
946 | } | 946 | } |
947 | 947 | ||
948 | device_set_wakeup_capable(&client->dev, 1); | 948 | device_set_wakeup_capable(&client->dev, 1); |
@@ -951,11 +951,12 @@ read_rtc: | |||
951 | } | 951 | } |
952 | 952 | ||
953 | if (chip->nvram_size) { | 953 | if (chip->nvram_size) { |
954 | ds1307->nvram = kzalloc(sizeof(struct bin_attribute), | 954 | ds1307->nvram = devm_kzalloc(&client->dev, |
955 | GFP_KERNEL); | 955 | sizeof(struct bin_attribute), |
956 | GFP_KERNEL); | ||
956 | if (!ds1307->nvram) { | 957 | if (!ds1307->nvram) { |
957 | err = -ENOMEM; | 958 | err = -ENOMEM; |
958 | goto exit_nvram; | 959 | goto exit; |
959 | } | 960 | } |
960 | ds1307->nvram->attr.name = "nvram"; | 961 | ds1307->nvram->attr.name = "nvram"; |
961 | ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR; | 962 | ds1307->nvram->attr.mode = S_IRUGO | S_IWUSR; |
@@ -965,21 +966,15 @@ read_rtc: | |||
965 | ds1307->nvram->size = chip->nvram_size; | 966 | ds1307->nvram->size = chip->nvram_size; |
966 | ds1307->nvram_offset = chip->nvram_offset; | 967 | ds1307->nvram_offset = chip->nvram_offset; |
967 | err = sysfs_create_bin_file(&client->dev.kobj, ds1307->nvram); | 968 | err = sysfs_create_bin_file(&client->dev.kobj, ds1307->nvram); |
968 | if (err) { | 969 | if (err) |
969 | kfree(ds1307->nvram); | 970 | goto exit; |
970 | goto exit_nvram; | ||
971 | } | ||
972 | set_bit(HAS_NVRAM, &ds1307->flags); | 971 | set_bit(HAS_NVRAM, &ds1307->flags); |
973 | dev_info(&client->dev, "%zu bytes nvram\n", ds1307->nvram->size); | 972 | dev_info(&client->dev, "%zu bytes nvram\n", ds1307->nvram->size); |
974 | } | 973 | } |
975 | 974 | ||
976 | return 0; | 975 | return 0; |
977 | 976 | ||
978 | exit_nvram: | 977 | exit: |
979 | exit_irq: | ||
980 | rtc_device_unregister(ds1307->rtc); | ||
981 | exit_free: | ||
982 | kfree(ds1307); | ||
983 | return err; | 978 | return err; |
984 | } | 979 | } |
985 | 980 | ||
@@ -992,13 +987,9 @@ static int ds1307_remove(struct i2c_client *client) | |||
992 | cancel_work_sync(&ds1307->work); | 987 | cancel_work_sync(&ds1307->work); |
993 | } | 988 | } |
994 | 989 | ||
995 | if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags)) { | 990 | if (test_and_clear_bit(HAS_NVRAM, &ds1307->flags)) |
996 | sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram); | 991 | sysfs_remove_bin_file(&client->dev.kobj, ds1307->nvram); |
997 | kfree(ds1307->nvram); | ||
998 | } | ||
999 | 992 | ||
1000 | rtc_device_unregister(ds1307->rtc); | ||
1001 | kfree(ds1307); | ||
1002 | return 0; | 993 | return 0; |
1003 | } | 994 | } |
1004 | 995 | ||