diff options
author | Axel Lin <axel.lin@gmail.com> | 2012-07-05 11:06:57 -0400 |
---|---|---|
committer | Mark Brown <broonie@opensource.wolfsonmicro.com> | 2012-07-15 16:49:53 -0400 |
commit | 8fa25eda86b1a149fd19b5ce80d8cf7b6c8fb566 (patch) | |
tree | 6d55a3d26f23d85ca2a4da11d66a2f86db77b53b /drivers/regulator/max8997.c | |
parent | 8a8e3d5915b3b40a64a5e7dc5aeb208594917a15 (diff) |
regulator: max8997: Properly handle gpio_request failure
Convert to devm_gpio_request to save a few error handling code.
This patch properly handle the gpio_request failure with -EBUSY, we should
return error rather than ommit the gpio_request failure with -EBUSY.
I think one of the reason we got -EBUSY is because current code does not free
gpios in max8997_pmic_remove(). So it got -EBUSY when reload the module.
Yest another reason is in current code if gpio_request() returns -EBUSY,
the rest of the code still calls gpio_direction_output to config buck125_gpios
and set gpio value in max8997_set_gpio(). This looks wrong to me.
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, 9 insertions, 31 deletions
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c index 704cd49ef375..e39a0c7260dc 100644 --- a/drivers/regulator/max8997.c +++ b/drivers/regulator/max8997.c | |||
@@ -1025,7 +1025,6 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1025 | */ | 1025 | */ |
1026 | if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || | 1026 | if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs || |
1027 | pdata->buck5_gpiodvs) { | 1027 | pdata->buck5_gpiodvs) { |
1028 | bool gpio1set = false, gpio2set = false; | ||
1029 | 1028 | ||
1030 | if (!gpio_is_valid(pdata->buck125_gpios[0]) || | 1029 | if (!gpio_is_valid(pdata->buck125_gpios[0]) || |
1031 | !gpio_is_valid(pdata->buck125_gpios[1]) || | 1030 | !gpio_is_valid(pdata->buck125_gpios[1]) || |
@@ -1035,40 +1034,20 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1035 | goto err_out; | 1034 | goto err_out; |
1036 | } | 1035 | } |
1037 | 1036 | ||
1038 | ret = gpio_request(pdata->buck125_gpios[0], | 1037 | ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[0], |
1039 | "MAX8997 SET1"); | 1038 | "MAX8997 SET1"); |
1040 | if (ret == -EBUSY) | 1039 | if (ret) |
1041 | dev_warn(&pdev->dev, "Duplicated gpio request" | ||
1042 | " on SET1\n"); | ||
1043 | else if (ret) | ||
1044 | goto err_out; | 1040 | goto err_out; |
1045 | else | 1041 | |
1046 | gpio1set = true; | 1042 | ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[1], |
1047 | 1043 | "MAX8997 SET2"); | |
1048 | ret = gpio_request(pdata->buck125_gpios[1], | 1044 | if (ret) |
1049 | "MAX8997 SET2"); | ||
1050 | if (ret == -EBUSY) | ||
1051 | dev_warn(&pdev->dev, "Duplicated gpio request" | ||
1052 | " on SET2\n"); | ||
1053 | else if (ret) { | ||
1054 | if (gpio1set) | ||
1055 | gpio_free(pdata->buck125_gpios[0]); | ||
1056 | goto err_out; | 1045 | goto err_out; |
1057 | } else | ||
1058 | gpio2set = true; | ||
1059 | 1046 | ||
1060 | ret = gpio_request(pdata->buck125_gpios[2], | 1047 | ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[2], |
1061 | "MAX8997 SET3"); | 1048 | "MAX8997 SET3"); |
1062 | if (ret == -EBUSY) | 1049 | if (ret) |
1063 | dev_warn(&pdev->dev, "Duplicated gpio request" | ||
1064 | " on SET3\n"); | ||
1065 | else if (ret) { | ||
1066 | if (gpio1set) | ||
1067 | gpio_free(pdata->buck125_gpios[0]); | ||
1068 | if (gpio2set) | ||
1069 | gpio_free(pdata->buck125_gpios[1]); | ||
1070 | goto err_out; | 1050 | goto err_out; |
1071 | } | ||
1072 | 1051 | ||
1073 | gpio_direction_output(pdata->buck125_gpios[0], | 1052 | gpio_direction_output(pdata->buck125_gpios[0], |
1074 | (max8997->buck125_gpioindex >> 2) | 1053 | (max8997->buck125_gpioindex >> 2) |
@@ -1079,7 +1058,6 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev) | |||
1079 | gpio_direction_output(pdata->buck125_gpios[2], | 1058 | gpio_direction_output(pdata->buck125_gpios[2], |
1080 | (max8997->buck125_gpioindex >> 0) | 1059 | (max8997->buck125_gpioindex >> 0) |
1081 | & 0x1); /* SET3 */ | 1060 | & 0x1); /* SET3 */ |
1082 | ret = 0; | ||
1083 | } | 1061 | } |
1084 | 1062 | ||
1085 | /* DVS-GPIO disabled */ | 1063 | /* DVS-GPIO disabled */ |