Skip to contentSkip to conversation

iio: adc: twl4030: Fix some error handling issues in 'twl4030_madc_probe()'

PATCH Applied Christophe JAILLET 2 participants 7 messages Sep 23, 2017 – Sep 24, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover iio: adc: twl4030: Fix some error handling issues in 'twl4030_madc_probe()'

These 3 patches are all related to error hangling in 'twl4030_madc_probe()'. They are also all related to commit 7cc97d77ee8a
("iio: adc: twl4030: Fix ADC[3:6] readings")

The semantic of the patches behing slighly different:
- direct return instead of going through the error handling path
- missing function in the error handling path
- spurious pattern (IMO) if unable to enable a regulator
I have splitted them in 3 parts.

Christophe JAILLET (3):
iio: adc: twl4030: Fix an error handling path in

    'twl4030_madc_probe()'
  iio: adc: twl4030: Disable the vusb3v1 rugulator in the error handling
    path of 'twl4030_madc_probe()'
  iio: adc: twl4030: Return an error if we can not enable the vusb3v1
    regulator in 'twl4030_madc_probe()'
 drivers/iio/adc/twl4030-madc.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH 1/3 iio: adc: twl4030: Fix an error handling path in 'twl4030_madc_probe()'

If 'devm_regulator_get()' fails, we should go through the existing error handling path instead of returning directly, as done is all the other error handling paths in this function.

Fixes 7cc97d77ee8a ("iio: adc: twl4030: Fix ADC[3:6] readings")
---
 drivers/iio/adc/twl4030-madc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/adc/twl4030-madc.c +4 -2
index 1edd99f0c5e5..80ab2ed70b85 100644
@@ -887,8 +887,10 @@ static int twl4030_madc_probe(struct platform_device *pdev)
 
 	/* Enable 3v1 bias regulator for MADC[3:6] */
 	madc->usb3v1 = devm_regulator_get(madc->dev, "vusb3v1");
-	if (IS_ERR(madc->usb3v1))
-		return -ENODEV;
+	if (IS_ERR(madc->usb3v1)) {
+		ret = -ENODEV;
+		goto err_i2c;
+	}
 
 	ret = regulator_enable(madc->usb3v1);
 	if (ret)
Signature · 1 line
2.11.0
#2 lore raw

PATCH 2/3 iio: adc: twl4030: Disable the vusb3v1 rugulator in the error handling path of 'twl4030_madc_probe()'

Commit 7cc97d77ee8a has introduced a call to 'regulator_disable()' in the .remove function.
So we should also have such a call in the .probe function in case of error after a successful 'regulator_enable()' call.

Add a new label for that and use it.

Fixes 7cc97d77ee8a ("iio: adc: twl4030: Fix ADC[3:6] readings")
---
 drivers/iio/adc/twl4030-madc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/twl4030-madc.c +3 -1
index 80ab2ed70b85..32db23d9a483 100644
@@ -899,11 +899,13 @@ static int twl4030_madc_probe(struct platform_device *pdev)
 	ret = iio_device_register(iio_dev);
 	if (ret) {
 		dev_err(&pdev->dev, "could not register iio device\n");
-		goto err_i2c;
+		goto err_usb3v1;
 	}
 
 	return 0;
 
+err_usb3v1:
+	regulator_disable(madc->usb3v1);
 err_i2c:
 	twl4030_madc_set_current_generator(madc, 0, 0);
 err_current_generator:
Signature · 1 line
2.11.0
maintainer Applied
#3 lore raw

Re: [PATCH 2/3] iio: adc: twl4030: Disable the vusb3v1 rugulator in the error handling path of 'twl4030_madc_probe()'

Quoted 9 lines · On Sat, 23 Sep 2017 08:06:19 +0200 Christophe JAILLET…

Commit 7cc97d77ee8a has introduced a call to 'regulator_disable()' in the .remove function.
So we should also have such a call in the .probe function in case of error after a successful 'regulator_enable()' call.

Add a new label for that and use it.

Fixes 7cc97d77ee8a ("iio: adc: twl4030: Fix ADC[3:6] readings")

Applied to the fixes-togreg-post-rc1 branch of iio.git and marked for stable.

Thanks,

Jonathan

Quoted 23 lines
---
 drivers/iio/adc/twl4030-madc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/twl4030-madc.c +3 -1
index 80ab2ed70b85..32db23d9a483 100644
@@ -899,11 +899,13 @@ static int twl4030_madc_probe(struct platform_device *pdev)
 	ret = iio_device_register(iio_dev);
 	if (ret) {
 		dev_err(&pdev->dev, "could not register iio device\n");
-		goto err_i2c;
+		goto err_usb3v1;
 	}
 
 	return 0;
 
+err_usb3v1:
+	regulator_disable(madc->usb3v1);
 err_i2c:
 	twl4030_madc_set_current_generator(madc, 0, 0);
 err_current_generator:
#4 lore raw

PATCH 3/3 iio: adc: twl4030: Return an error if we can not enable the vusb3v1 regulator in 'twl4030_madc_probe()'

In reply to Christophe JAILLET

If we can not enable the regulator, go through the error handling path instead of silently continuing.

Fixes 7cc97d77ee8a ("iio: adc: twl4030: Fix ADC[3:6] readings")

---
This patch is highly speculative.
I don't find logical to return an error if we don't find the 'vusb3v1' regulator, but continue if we find it, but can't enable it. Returning an error if both cases (i.e. failing 'devm_regulator_get()' or 'regulator_enable)' seems the usual pattern in all the .probe functions with a 'regulator_enable()' call have looked at (~ 10 of them taken randomly)

---
 drivers/iio/adc/twl4030-madc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/twl4030-madc.c +3 -1
index 32db23d9a483..e3cfb91bffc6 100644
@@ -893,8 +893,10 @@ static int twl4030_madc_probe(struct platform_device *pdev)
 	}
 
 	ret = regulator_enable(madc->usb3v1);
-	if (ret)
+	if (ret) {
 		dev_err(madc->dev, "could not enable 3v1 bias regulator\n");
+		goto err_i2c;
+	}
 
 	ret = iio_device_register(iio_dev);
 	if (ret) {
Signature · 1 line
2.11.0
maintainer Applied
#5 lore raw

Re: [PATCH 3/3] iio: adc: twl4030: Return an error if we can not enable the vusb3v1 regulator in 'twl4030_madc_probe()'

Quoted 5 lines · On Sat, 23 Sep 2017 08:06:20 +0200 Christophe JAILLET…

If we can not enable the regulator, go through the error handling path instead of silently continuing.

Fixes 7cc97d77ee8a ("iio: adc: twl4030: Fix ADC[3:6] readings")

Applied to the fixes-togreg-post-rc1 branch of iio.git.

I haven't explicitly marked this one for stable as it isn't broken as such, just inconsistent.

Thanks,

Jonathan

Quoted 28 lines

---
This patch is highly speculative.
I don't find logical to return an error if we don't find the 'vusb3v1' regulator, but continue if we find it, but can't enable it. Returning an error if both cases (i.e. failing 'devm_regulator_get()' or 'regulator_enable)' seems the usual pattern in all the .probe functions with a 'regulator_enable()' call have looked at (~ 10 of them taken randomly)

---
 drivers/iio/adc/twl4030-madc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/iio/adc/twl4030-madc.c +3 -1
index 32db23d9a483..e3cfb91bffc6 100644
@@ -893,8 +893,10 @@ static int twl4030_madc_probe(struct platform_device *pdev)
 	}
 
 	ret = regulator_enable(madc->usb3v1);
-	if (ret)
+	if (ret) {
 		dev_err(madc->dev, "could not enable 3v1 bias regulator\n");
+		goto err_i2c;
+	}
 
 	ret = iio_device_register(iio_dev);
 	if (ret) {
maintainer Applied
#6 lore raw

Re: [PATCH 1/3] iio: adc: twl4030: Fix an error handling path in 'twl4030_madc_probe()'

In reply to Christophe JAILLET
Quoted 6 lines · On Sat, 23 Sep 2017 08:06:18 +0200 Christophe JAILLET…

If 'devm_regulator_get()' fails, we should go through the existing error handling path instead of returning directly, as done is all the other error handling paths in this function.

Fixes 7cc97d77ee8a ("iio: adc: twl4030: Fix ADC[3:6] readings")

Applied to the fixes-togreg-post-rc1 branch of iio.git and marked for stable.

Thanks,

Jonathan

Quoted 21 lines
---
 drivers/iio/adc/twl4030-madc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/iio/adc/twl4030-madc.c +4 -2
index 1edd99f0c5e5..80ab2ed70b85 100644
@@ -887,8 +887,10 @@ static int twl4030_madc_probe(struct platform_device *pdev)
 
 	/* Enable 3v1 bias regulator for MADC[3:6] */
 	madc->usb3v1 = devm_regulator_get(madc->dev, "vusb3v1");
-	if (IS_ERR(madc->usb3v1))
-		return -ENODEV;
+	if (IS_ERR(madc->usb3v1)) {
+		ret = -ENODEV;
+		goto err_i2c;
+	}
 
 	ret = regulator_enable(madc->usb3v1);
 	if (ret)