Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Axel Lin and committed by
Mark Brown
8ae5767b 6c9eeb0f

+15 -25
+15 -25
drivers/regulator/max8997.c
··· 949 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 954 if (!max8997) 954 955 return -ENOMEM; 955 956 956 957 size = sizeof(struct regulator_dev *) * pdata->num_regulators; 957 - max8997->rdev = kzalloc(size, GFP_KERNEL); 958 - if (!max8997->rdev) { 959 - kfree(max8997); 958 + max8997->rdev = devm_kzalloc(&pdev->dev, size, GFP_KERNEL); 959 + if (!max8997->rdev) 960 960 return -ENOMEM; 961 - } 962 961 963 962 rdev = max8997->rdev; 964 963 max8997->dev = &pdev->dev; ··· 981 982 pdata->buck1_voltage[i] / 1000 + 982 983 buck1245_voltage_map_desc.step); 983 984 if (ret < 0) 984 - goto err_alloc; 985 + goto err_out; 985 986 986 987 max8997->buck2_vol[i] = ret = 987 988 max8997_get_voltage_proper_val( ··· 990 991 pdata->buck2_voltage[i] / 1000 + 991 992 buck1245_voltage_map_desc.step); 992 993 if (ret < 0) 993 - goto err_alloc; 994 + goto err_out; 994 995 995 996 max8997->buck5_vol[i] = ret = 996 997 max8997_get_voltage_proper_val( ··· 999 1000 pdata->buck5_voltage[i] / 1000 + 1000 1001 buck1245_voltage_map_desc.step); 1001 1002 if (ret < 0) 1002 - goto err_alloc; 1003 + goto err_out; 1003 1004 1004 1005 if (max_buck1 < max8997->buck1_vol[i]) 1005 1006 max_buck1 = max8997->buck1_vol[i]; ··· 1032 1033 !gpio_is_valid(pdata->buck125_gpios[2])) { 1033 1034 dev_err(&pdev->dev, "GPIO NOT VALID\n"); 1034 1035 ret = -EINVAL; 1035 - goto err_alloc; 1036 + goto err_out; 1036 1037 } 1037 1038 1038 1039 ret = gpio_request(pdata->buck125_gpios[0], ··· 1041 1042 dev_warn(&pdev->dev, "Duplicated gpio request" 1042 1043 " on SET1\n"); 1043 1044 else if (ret) 1044 - goto err_alloc; 1045 + goto err_out; 1045 1046 else 1046 1047 gpio1set = true; 1047 1048 ··· 1053 1054 else if (ret) { 1054 1055 if (gpio1set) 1055 1056 gpio_free(pdata->buck125_gpios[0]); 1056 - goto err_alloc; 1057 + goto err_out; 1057 1058 } else 1058 1059 gpio2set = true; 1059 1060 ··· 1067 1068 gpio_free(pdata->buck125_gpios[0]); 1068 1069 if (gpio2set) 1069 1070 gpio_free(pdata->buck125_gpios[1]); 1070 - goto err_alloc; 1071 + goto err_out; 1071 1072 } 1072 1073 1073 1074 gpio_direction_output(pdata->buck125_gpios[0], ··· 1136 1137 1137 1138 return 0; 1138 1139 err: 1139 - for (i = 0; i < max8997->num_regulators; i++) 1140 - if (rdev[i]) 1141 - regulator_unregister(rdev[i]); 1142 - err_alloc: 1143 - kfree(max8997->rdev); 1144 - kfree(max8997); 1145 - 1140 + while (--i >= 0) 1141 + regulator_unregister(rdev[i]); 1142 + err_out: 1146 1143 return ret; 1147 1144 } 1148 1145 ··· 1149 1154 int i; 1150 1155 1151 1156 for (i = 0; i < max8997->num_regulators; i++) 1152 - if (rdev[i]) 1153 - regulator_unregister(rdev[i]); 1154 - 1155 - kfree(max8997->rdev); 1156 - kfree(max8997); 1157 - 1157 + regulator_unregister(rdev[i]); 1158 1158 return 0; 1159 1159 } 1160 1160