* [RFC/RFT][PATCH 1/2] regulator: max8997: Properly handle gpio_request failure
@ 2012-07-05 15:06 Axel Lin
2012-07-05 15:12 ` [RFC/RFT][PATCH 2/2] regulator: s5m8767: " Axel Lin
2012-07-15 20:50 ` [RFC/RFT][PATCH 1/2] regulator: max8997: " Mark Brown
0 siblings, 2 replies; 3+ messages in thread
From: Axel Lin @ 2012-07-05 15:06 UTC (permalink / raw)
To: Mark Brown; +Cc: Kyungmin Park, MyungJoo Ham, Liam Girdwood, linux-kernel
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>
---
drivers/regulator/max8997.c | 40 +++++++++-------------------------------
1 file changed, 9 insertions(+), 31 deletions(-)
diff --git a/drivers/regulator/max8997.c b/drivers/regulator/max8997.c
index 704cd49..e39a0c7 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)
*/
if (pdata->buck1_gpiodvs || pdata->buck2_gpiodvs ||
pdata->buck5_gpiodvs) {
- bool gpio1set = false, gpio2set = false;
if (!gpio_is_valid(pdata->buck125_gpios[0]) ||
!gpio_is_valid(pdata->buck125_gpios[1]) ||
@@ -1035,40 +1034,20 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
goto err_out;
}
- ret = gpio_request(pdata->buck125_gpios[0],
- "MAX8997 SET1");
- if (ret == -EBUSY)
- dev_warn(&pdev->dev, "Duplicated gpio request"
- " on SET1\n");
- else if (ret)
+ ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[0],
+ "MAX8997 SET1");
+ if (ret)
goto err_out;
- else
- gpio1set = true;
-
- ret = gpio_request(pdata->buck125_gpios[1],
- "MAX8997 SET2");
- if (ret == -EBUSY)
- dev_warn(&pdev->dev, "Duplicated gpio request"
- " on SET2\n");
- else if (ret) {
- if (gpio1set)
- gpio_free(pdata->buck125_gpios[0]);
+
+ ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[1],
+ "MAX8997 SET2");
+ if (ret)
goto err_out;
- } else
- gpio2set = true;
- ret = gpio_request(pdata->buck125_gpios[2],
+ ret = devm_gpio_request(&pdev->dev, pdata->buck125_gpios[2],
"MAX8997 SET3");
- if (ret == -EBUSY)
- dev_warn(&pdev->dev, "Duplicated gpio request"
- " on SET3\n");
- else if (ret) {
- if (gpio1set)
- gpio_free(pdata->buck125_gpios[0]);
- if (gpio2set)
- gpio_free(pdata->buck125_gpios[1]);
+ if (ret)
goto err_out;
- }
gpio_direction_output(pdata->buck125_gpios[0],
(max8997->buck125_gpioindex >> 2)
@@ -1079,7 +1058,6 @@ static __devinit int max8997_pmic_probe(struct platform_device *pdev)
gpio_direction_output(pdata->buck125_gpios[2],
(max8997->buck125_gpioindex >> 0)
& 0x1); /* SET3 */
- ret = 0;
}
/* DVS-GPIO disabled */
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [RFC/RFT][PATCH 2/2] regulator: s5m8767: Properly handle gpio_request failure
2012-07-05 15:06 [RFC/RFT][PATCH 1/2] regulator: max8997: Properly handle gpio_request failure Axel Lin
@ 2012-07-05 15:12 ` Axel Lin
2012-07-15 20:50 ` [RFC/RFT][PATCH 1/2] regulator: max8997: " Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Axel Lin @ 2012-07-05 15:12 UTC (permalink / raw)
To: Mark Brown; +Cc: Sangbeom Kim, Liam Girdwood, linux-kernel
Convert to devm_gpio_request to save a few error handling code.
This patch properly handle the gpio_request failure, we should return error
when gpio_request fails rather than just show warning.
I think one of the reason we got -EBUSY is because current code does not free
gpios in s5m8767_pmic_remove(). So it got -EBUSY when reload the module.
Yest another reason is in current code if gpio_request() returns error,
the rest of the code still calls gpio_direction_output to config buck_gpios
and buck_ds gpios. This looks wrong to me.
Signed-off-by: Axel Lin <axel.lin@gmail.com>
---
drivers/regulator/s5m8767.c | 49 +++++++++++++++++++++----------------------
1 file changed, 24 insertions(+), 25 deletions(-)
diff --git a/drivers/regulator/s5m8767.c b/drivers/regulator/s5m8767.c
index 5df3358..297f696 100644
--- a/drivers/regulator/s5m8767.c
+++ b/drivers/regulator/s5m8767.c
@@ -559,20 +559,21 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
if (gpio_is_valid(pdata->buck_gpios[0]) &&
gpio_is_valid(pdata->buck_gpios[1]) &&
gpio_is_valid(pdata->buck_gpios[2])) {
- ret = gpio_request(pdata->buck_gpios[0], "S5M8767 SET1");
- if (ret == -EBUSY)
- dev_warn(&pdev->dev, "Duplicated gpio request"
- " for SET1\n");
-
- ret = gpio_request(pdata->buck_gpios[1], "S5M8767 SET2");
- if (ret == -EBUSY)
- dev_warn(&pdev->dev, "Duplicated gpio request"
- " for SET2\n");
-
- ret = gpio_request(pdata->buck_gpios[2], "S5M8767 SET3");
- if (ret == -EBUSY)
- dev_warn(&pdev->dev, "Duplicated gpio request"
- " for SET3\n");
+ ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[0],
+ "S5M8767 SET1");
+ if (ret)
+ return ret;
+
+ ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[1],
+ "S5M8767 SET2");
+ if (ret)
+ return ret;
+
+ ret = devm_gpio_request(&pdev->dev, pdata->buck_gpios[2],
+ "S5M8767 SET3");
+ if (ret)
+ return ret;
+
/* SET1 GPIO */
gpio_direction_output(pdata->buck_gpios[0],
(s5m8767->buck_gpioindex >> 2) & 0x1);
@@ -582,25 +583,23 @@ static __devinit int s5m8767_pmic_probe(struct platform_device *pdev)
/* SET3 GPIO */
gpio_direction_output(pdata->buck_gpios[2],
(s5m8767->buck_gpioindex >> 0) & 0x1);
- ret = 0;
-
} else {
dev_err(&pdev->dev, "GPIO NOT VALID\n");
ret = -EINVAL;
return ret;
}
- ret = gpio_request(pdata->buck_ds[0], "S5M8767 DS2");
- if (ret == -EBUSY)
- dev_warn(&pdev->dev, "Duplicated gpio request for DS2\n");
+ ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[0], "S5M8767 DS2");
+ if (ret)
+ return ret;
- ret = gpio_request(pdata->buck_ds[1], "S5M8767 DS3");
- if (ret == -EBUSY)
- dev_warn(&pdev->dev, "Duplicated gpio request for DS3\n");
+ ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[1], "S5M8767 DS3");
+ if (ret)
+ return ret;
- ret = gpio_request(pdata->buck_ds[2], "S5M8767 DS4");
- if (ret == -EBUSY)
- dev_warn(&pdev->dev, "Duplicated gpio request for DS4\n");
+ ret = devm_gpio_request(&pdev->dev, pdata->buck_ds[2], "S5M8767 DS4");
+ if (ret)
+ return ret;
/* DS2 GPIO */
gpio_direction_output(pdata->buck_ds[0], 0x0);
--
1.7.9.5
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [RFC/RFT][PATCH 1/2] regulator: max8997: Properly handle gpio_request failure
2012-07-05 15:06 [RFC/RFT][PATCH 1/2] regulator: max8997: Properly handle gpio_request failure Axel Lin
2012-07-05 15:12 ` [RFC/RFT][PATCH 2/2] regulator: s5m8767: " Axel Lin
@ 2012-07-15 20:50 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2012-07-15 20:50 UTC (permalink / raw)
To: Axel Lin; +Cc: Kyungmin Park, MyungJoo Ham, Liam Girdwood, linux-kernel
[-- Attachment #1: Type: text/plain, Size: 147 bytes --]
On Thu, Jul 05, 2012 at 11:06:57PM +0800, Axel Lin wrote:
> Convert to devm_gpio_request to save a few error handling code.
Applied both, thanks.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2012-07-15 20:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-07-05 15:06 [RFC/RFT][PATCH 1/2] regulator: max8997: Properly handle gpio_request failure Axel Lin
2012-07-05 15:12 ` [RFC/RFT][PATCH 2/2] regulator: s5m8767: " Axel Lin
2012-07-15 20:50 ` [RFC/RFT][PATCH 1/2] regulator: max8997: " Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).