diff options
author | Axel Lin <axel.lin@gmail.com> | 2012-04-18 21:44:13 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-04-23 08:20:26 -0400 |
commit | 8ae5767ba1c4e149ee9970aa7a4e9bf6b251bb77 (patch) | |
tree | eeb5fae803f580dd5dad722fb5c71dbff29e2d8b /drivers/regulator/max8997.c | |
parent | 6c9eeb0f5cac0d9fd05c138f1eec86a7f70630ce (diff) |
regulator: max8997: Convert ot use devm_kzalloc
Also simplify the error handling to start unwind from the place
regulator_register fails.
No need to check rdev[i] is NULL or not before calling regulator_unregister.
regulator_unregister is safe if rdev is NULL,
Signed-off-by: Axel Lin <axel.lin@gmail.com>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
Diffstat (limited to 'drivers/regulator/max8997.c')
-rw-r--r-- | drivers/regulator/max8997.c | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c index 90e2112f7e65..b88551be4521 100644 --- a/drivers/regulator/max8997.c +++ b/drivers/regulator/max8997.c | |||
@@ -949,16 +949,15 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
949 | return -ENODEV; | 949 | return -ENODEV; |
950 | } | 950 | } |
951 | 951 | ||
952 | max8997 = kzalloc(sizeof(struct max8997_data), GFP_KERNEL); | 952 | max8997 = devm_kzalloc(&pdev->dev, sizeof(struct max8997_data), |
953 | GFP_KERNEL); | ||
953 | if (!max8997) | 954 | if (!max8997) |
954 | return -ENOMEM; | 955 | return -ENOMEM; |
955 | 956 | ||
956 | size = sizeof(struct regulator_dev *) * pdata->num_regulators; | 957 | size = sizeof(struct regulator_dev *) * pdata->num_regulators; |
957 | max8997->rdev = kzalloc(size, GFP_KERNEL); | 958 | max8997->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); |
958 | if (!max8997->rdev) { | 959 | if (!max8997->rdev) |
959 | kfree(max8997); | ||
960 | return -ENOMEM; | 960 | return -ENOMEM; |
961 | } | ||
962 | 961 | ||
963 | rdev = max8997->rdev; | 962 | rdev = max8997->rdev; |
964 | max8997->dev = &pdev->dev; | 963 | max8997->dev = &pdev->dev; |
@@ -982,7 +981,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
982 | pdata->buck1_voltage[i] / 1000 + | 981 | pdata->buck1_voltage[i] / 1000 + |
983 | buck1245_voltage_map_desc.step); | 982 | buck1245_voltage_map_desc.step); |
984 | if (ret < 0) | 983 | if (ret < 0) |
985 | goto err_alloc; | 984 | goto err_out; |
986 | 985 | ||
987 | max8997->buck2_vol[i] = ret = | 986 | max8997->buck2_vol[i] = ret = |
988 | max8997_get_voltage_proper_val( | 987 | max8997_get_voltage_proper_val( |
@@ -991,7 +990,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
991 | pdata->buck2_voltage[i] / 1000 + | 990 | pdata->buck2_voltage[i] / 1000 + |
992 | buck1245_voltage_map_desc.step); | 991 | buck1245_voltage_map_desc.step); |
993 | if (ret < 0) | 992 | if (ret < 0) |
994 | goto err_alloc; | 993 | goto err_out; |
995 | 994 | ||
996 | max8997->buck5_vol[i] = ret = | 995 | max8997->buck5_vol[i] = ret = |
997 | max8997_get_voltage_proper_val( | 996 | max8997_get_voltage_proper_val( |
@@ -1000,7 +999,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1000 | pdata->buck5_voltage[i] / 1000 + | 999 | pdata->buck5_voltage[i] / 1000 + |
1001 | buck1245_voltage_map_desc.step); | 1000 | buck1245_voltage_map_desc.step); |
1002 | if (ret < 0) | 1001 | if (ret < 0) |
1003 | goto err_alloc; | 1002 | goto err_out; |
1004 | 1003 | ||
1005 | if (max_buck1 < max8997->buck1_vol[i]) | 1004 | if (max_buck1 < max8997->buck1_vol[i]) |
1006 | max_buck1 = max8997->buck1_vol[i]; | 1005 | max_buck1 = max8997->buck1_vol[i]; |
@@ -1033,7 +1032,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1033 | !gpio_is_valid(pdata->buck125_gpios[2])) { | 1032 | !gpio_is_valid(pdata->buck125_gpios[2])) { |
1034 | dev_err(&pdev->dev, "GPIO NOT VALID\n"); | 1033 | dev_err(&pdev->dev, "GPIO NOT VALID\n"); |
1035 | ret = -EINVAL; | 1034 | ret = -EINVAL; |
1036 | goto err_alloc; | 1035 | goto err_out; |
1037 | } | 1036 | } |
1038 | 1037 | ||
1039 | ret = gpio_request(pdata->buck125_gpios[0], | 1038 | ret = gpio_request(pdata->buck125_gpios[0], |
@@ -1042,7 +1041,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1042 | dev_warn(&pdev->dev, "Duplicated gpio request" | 1041 | dev_warn(&pdev->dev, "Duplicated gpio request" |
1043 | " on SET1\n"); | 1042 | " on SET1\n"); |
1044 | else if (ret) | 1043 | else if (ret) |
1045 | goto err_alloc; | 1044 | goto err_out; |
1046 | else | 1045 | else |
1047 | gpio1set = true; | 1046 | gpio1set = true; |
1048 | 1047 | ||
@@ -1054,7 +1053,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1054 | else if (ret) { | 1053 | else if (ret) { |
1055 | if (gpio1set) | 1054 | if (gpio1set) |
1056 | gpio_free(pdata->buck125_gpios[0]); | 1055 | gpio_free(pdata->buck125_gpios[0]); |
1057 | goto err_alloc; | 1056 | goto err_out; |
1058 | } else | 1057 | } else |
1059 | gpio2set = true; | 1058 | gpio2set = true; |
1060 | 1059 | ||
@@ -1068,7 +1067,7 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1068 | gpio_free(pdata->buck125_gpios[0]); | 1067 | gpio_free(pdata->buck125_gpios[0]); |
1069 | if (gpio2set) | 1068 | if (gpio2set) |
1070 | gpio_free(pdata->buck125_gpios[1]); | 1069 | gpio_free(pdata->buck125_gpios[1]); |
1071 | goto err_alloc; | 1070 | goto err_out; |
1072 | } | 1071 | } |
1073 | 1072 | ||
1074 | gpio_direction_output(pdata->buck125_gpios[0], | 1073 | gpio_direction_output(pdata->buck125_gpios[0], |
@@ -1137,13 +1136,9 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1137 | 1136 | ||
1138 | return 0; | 1137 | return 0; |
1139 | err: | 1138 | err: |
1140 | for (i = 0; i < max8997->num_regulators; i++) | 1139 | while (--i >= 0) |
1141 | if (rdev[i]) | 1140 | regulator_unregister(rdev[i]); |
1142 | regulator_unregister(rdev[i]); | 1141 | err_out: |
1143 | err_alloc: | ||
1144 | kfree(max8997->rdev); | ||
1145 | kfree(max8997); | ||
1146 | |||
1147 | return ret; | 1142 | return ret; |
1148 | } | 1143 | } |
1149 | 1144 | ||
@@ -1154,12 +1149,7 @@ static int __devexit max8997_pmic_remove(struct platform_device *pdev) | |||
1154 | int i; | 1149 | int i; |
1155 | 1150 | ||
1156 | for (i = 0; i < max8997->num_regulators; i++) | 1151 | for (i = 0; i < max8997->num_regulators; i++) |
1157 | if (rdev[i]) | 1152 | regulator_unregister(rdev[i]); |
1158 | regulator_unregister(rdev[i]); | ||
1159 | |||
1160 | kfree(max8997->rdev); | ||
1161 | kfree(max8997); | ||
1162 | |||
1163 | return 0; | 1153 | return 0; |
1164 | } | 1154 | } |
1165 | 1155 | ||