diff options
author | Guenter Roeck <linux@roeck-us.net> | 2012-06-02 14:20:22 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2012-09-24 00:08:32 -0400 |
commit | 38fe7560a391cba81ec7fc5b169b764819632060 (patch) | |
tree | 4164b687bfe62278cf2cdfdcec4ed748e2bcfad5 /drivers/hwmon | |
parent | 9220f1e4a284667a813ca4428fbbd5a3cbc6295d (diff) |
hwmon: (sht15) Convert to use devm_ functions
Convert to use devm_ functions to reduce code size and simplify the code.
Cc: Jonathan Cameron <jic23@cam.ac.uk>
Cc: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Jonathan Cameron <jic23@cam.ac.uk>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/sht15.c | 58 |
1 files changed, 20 insertions, 38 deletions
diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c index 8b011d016621..e4614644408b 100644 --- a/drivers/hwmon/sht15.c +++ b/drivers/hwmon/sht15.c | |||
@@ -884,14 +884,12 @@ static int sht15_invalidate_voltage(struct notifier_block *nb, | |||
884 | static int __devinit sht15_probe(struct platform_device *pdev) | 884 | static int __devinit sht15_probe(struct platform_device *pdev) |
885 | { | 885 | { |
886 | int ret; | 886 | int ret; |
887 | struct sht15_data *data = kzalloc(sizeof(*data), GFP_KERNEL); | 887 | struct sht15_data *data; |
888 | u8 status = 0; | 888 | u8 status = 0; |
889 | 889 | ||
890 | if (!data) { | 890 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
891 | ret = -ENOMEM; | 891 | if (!data) |
892 | dev_err(&pdev->dev, "kzalloc failed\n"); | 892 | return -ENOMEM; |
893 | goto error_ret; | ||
894 | } | ||
895 | 893 | ||
896 | INIT_WORK(&data->read_work, sht15_bh_read_data); | 894 | INIT_WORK(&data->read_work, sht15_bh_read_data); |
897 | INIT_WORK(&data->update_supply_work, sht15_update_voltage); | 895 | INIT_WORK(&data->update_supply_work, sht15_update_voltage); |
@@ -901,9 +899,8 @@ static int __devinit sht15_probe(struct platform_device *pdev) | |||
901 | init_waitqueue_head(&data->wait_queue); | 899 | init_waitqueue_head(&data->wait_queue); |
902 | 900 | ||
903 | if (pdev->dev.platform_data == NULL) { | 901 | if (pdev->dev.platform_data == NULL) { |
904 | ret = -EINVAL; | ||
905 | dev_err(&pdev->dev, "no platform data supplied\n"); | 902 | dev_err(&pdev->dev, "no platform data supplied\n"); |
906 | goto err_free_data; | 903 | return -EINVAL; |
907 | } | 904 | } |
908 | data->pdata = pdev->dev.platform_data; | 905 | data->pdata = pdev->dev.platform_data; |
909 | data->supply_uV = data->pdata->supply_mv * 1000; | 906 | data->supply_uV = data->pdata->supply_mv * 1000; |
@@ -918,7 +915,7 @@ static int __devinit sht15_probe(struct platform_device *pdev) | |||
918 | * If a regulator is available, | 915 | * If a regulator is available, |
919 | * query what the supply voltage actually is! | 916 | * query what the supply voltage actually is! |
920 | */ | 917 | */ |
921 | data->reg = regulator_get(data->dev, "vcc"); | 918 | data->reg = devm_regulator_get(data->dev, "vcc"); |
922 | if (!IS_ERR(data->reg)) { | 919 | if (!IS_ERR(data->reg)) { |
923 | int voltage; | 920 | int voltage; |
924 | 921 | ||
@@ -937,51 +934,51 @@ static int __devinit sht15_probe(struct platform_device *pdev) | |||
937 | dev_err(&pdev->dev, | 934 | dev_err(&pdev->dev, |
938 | "regulator notifier request failed\n"); | 935 | "regulator notifier request failed\n"); |
939 | regulator_disable(data->reg); | 936 | regulator_disable(data->reg); |
940 | regulator_put(data->reg); | 937 | return ret; |
941 | goto err_free_data; | ||
942 | } | 938 | } |
943 | } | 939 | } |
944 | 940 | ||
945 | /* Try requesting the GPIOs */ | 941 | /* Try requesting the GPIOs */ |
946 | ret = gpio_request(data->pdata->gpio_sck, "SHT15 sck"); | 942 | ret = devm_gpio_request(&pdev->dev, data->pdata->gpio_sck, "SHT15 sck"); |
947 | if (ret) { | 943 | if (ret) { |
948 | dev_err(&pdev->dev, "gpio request failed\n"); | 944 | dev_err(&pdev->dev, "gpio request failed\n"); |
949 | goto err_release_reg; | 945 | goto err_release_reg; |
950 | } | 946 | } |
951 | gpio_direction_output(data->pdata->gpio_sck, 0); | 947 | gpio_direction_output(data->pdata->gpio_sck, 0); |
952 | 948 | ||
953 | ret = gpio_request(data->pdata->gpio_data, "SHT15 data"); | 949 | ret = devm_gpio_request(&pdev->dev, data->pdata->gpio_data, |
950 | "SHT15 data"); | ||
954 | if (ret) { | 951 | if (ret) { |
955 | dev_err(&pdev->dev, "gpio request failed\n"); | 952 | dev_err(&pdev->dev, "gpio request failed\n"); |
956 | goto err_release_gpio_sck; | 953 | goto err_release_reg; |
957 | } | 954 | } |
958 | 955 | ||
959 | ret = request_irq(gpio_to_irq(data->pdata->gpio_data), | 956 | ret = devm_request_irq(&pdev->dev, gpio_to_irq(data->pdata->gpio_data), |
960 | sht15_interrupt_fired, | 957 | sht15_interrupt_fired, |
961 | IRQF_TRIGGER_FALLING, | 958 | IRQF_TRIGGER_FALLING, |
962 | "sht15 data", | 959 | "sht15 data", |
963 | data); | 960 | data); |
964 | if (ret) { | 961 | if (ret) { |
965 | dev_err(&pdev->dev, "failed to get irq for data line\n"); | 962 | dev_err(&pdev->dev, "failed to get irq for data line\n"); |
966 | goto err_release_gpio_data; | 963 | goto err_release_reg; |
967 | } | 964 | } |
968 | disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); | 965 | disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data)); |
969 | sht15_connection_reset(data); | 966 | sht15_connection_reset(data); |
970 | ret = sht15_soft_reset(data); | 967 | ret = sht15_soft_reset(data); |
971 | if (ret) | 968 | if (ret) |
972 | goto err_release_irq; | 969 | goto err_release_reg; |
973 | 970 | ||
974 | /* write status with platform data options */ | 971 | /* write status with platform data options */ |
975 | if (status) { | 972 | if (status) { |
976 | ret = sht15_send_status(data, status); | 973 | ret = sht15_send_status(data, status); |
977 | if (ret) | 974 | if (ret) |
978 | goto err_release_irq; | 975 | goto err_release_reg; |
979 | } | 976 | } |
980 | 977 | ||
981 | ret = sysfs_create_group(&pdev->dev.kobj, &sht15_attr_group); | 978 | ret = sysfs_create_group(&pdev->dev.kobj, &sht15_attr_group); |
982 | if (ret) { | 979 | if (ret) { |
983 | dev_err(&pdev->dev, "sysfs create failed\n"); | 980 | dev_err(&pdev->dev, "sysfs create failed\n"); |
984 | goto err_release_irq; | 981 | goto err_release_reg; |
985 | } | 982 | } |
986 | 983 | ||
987 | data->hwmon_dev = hwmon_device_register(data->dev); | 984 | data->hwmon_dev = hwmon_device_register(data->dev); |
@@ -994,21 +991,11 @@ static int __devinit sht15_probe(struct platform_device *pdev) | |||
994 | 991 | ||
995 | err_release_sysfs_group: | 992 | err_release_sysfs_group: |
996 | sysfs_remove_group(&pdev->dev.kobj, &sht15_attr_group); | 993 | sysfs_remove_group(&pdev->dev.kobj, &sht15_attr_group); |
997 | err_release_irq: | ||
998 | free_irq(gpio_to_irq(data->pdata->gpio_data), data); | ||
999 | err_release_gpio_data: | ||
1000 | gpio_free(data->pdata->gpio_data); | ||
1001 | err_release_gpio_sck: | ||
1002 | gpio_free(data->pdata->gpio_sck); | ||
1003 | err_release_reg: | 994 | err_release_reg: |
1004 | if (!IS_ERR(data->reg)) { | 995 | if (!IS_ERR(data->reg)) { |
1005 | regulator_unregister_notifier(data->reg, &data->nb); | 996 | regulator_unregister_notifier(data->reg, &data->nb); |
1006 | regulator_disable(data->reg); | 997 | regulator_disable(data->reg); |
1007 | regulator_put(data->reg); | ||
1008 | } | 998 | } |
1009 | err_free_data: | ||
1010 | kfree(data); | ||
1011 | error_ret: | ||
1012 | return ret; | 999 | return ret; |
1013 | } | 1000 | } |
1014 | 1001 | ||
@@ -1030,14 +1017,9 @@ static int __devexit sht15_remove(struct platform_device *pdev) | |||
1030 | if (!IS_ERR(data->reg)) { | 1017 | if (!IS_ERR(data->reg)) { |
1031 | regulator_unregister_notifier(data->reg, &data->nb); | 1018 | regulator_unregister_notifier(data->reg, &data->nb); |
1032 | regulator_disable(data->reg); | 1019 | regulator_disable(data->reg); |
1033 | regulator_put(data->reg); | ||
1034 | } | 1020 | } |
1035 | 1021 | ||
1036 | free_irq(gpio_to_irq(data->pdata->gpio_data), data); | ||
1037 | gpio_free(data->pdata->gpio_data); | ||
1038 | gpio_free(data->pdata->gpio_sck); | ||
1039 | mutex_unlock(&data->read_lock); | 1022 | mutex_unlock(&data->read_lock); |
1040 | kfree(data); | ||
1041 | 1023 | ||
1042 | return 0; | 1024 | return 0; |
1043 | } | 1025 | } |