iio/adc/palmas: Use common error handling code in palmas_gpadc_calibrate()
Subsystems (2)
PATCH 1/1 iio/adc/palmas: Use common error handling code in palmas_gpadc_calibrate()
From: Markus Elfring <[email protected]>
Date: Thu, 26 Oct 2017 07:58:03 +0200
* Add a jump target so that a specific error message is stored only once at the end of this function implementation.
* Adjust condition checks.
This issue was detected by using the Coccinelle software.
--- drivers/iio/adc/palmas_gpadc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/iio/adc/palmas_gpadc.c +8 -8
@@ -304,17 +304,13 @@ static int palmas_gpadc_calibrate(struct palmas_gpadc *adc, int adc_chan) ret =palmas_read (adc->palmas,PALMAS_TRIM_GPADC_BASE , adc->adc_info[adc_chan].trim1_reg, &d1); -if (ret <0 ) { -dev_err (adc->dev,"TRIM read failed: %d\n" , ret); - goto scrub; - } +if (ret) + goto report_failure; ret =palmas_read (adc->palmas,PALMAS_TRIM_GPADC_BASE , adc->adc_info[adc_chan].trim2_reg, &d2); -if (ret <0 ) { -dev_err (adc->dev,"TRIM read failed: %d\n" , ret); - goto scrub; - } +if (ret) + goto report_failure;/* gain error calculation */ k = (1000 + (1000 * (d2 - d1)) / (x2 - x1));
@@ -329,6 +325,10 @@ static int palmas_gpadc_calibrate(struct palmas_gpadc *adc, int adc_chan) scrub:return ret; + +report_failure: +dev_err (adc->dev,"TRIM read failed: %d\n" , ret); + goto scrub; }static int palmas_gpadc_start_conversion (struct palmas_gpadc *adc,int adc_chan)
Signature · 1 line
2.14.3
Jonathan Cameron
maintainerQuoted 11 lines · On Thu, 26 Oct 2017 08:08:49 +0200 SF Markus Elfring…
From: Markus Elfring <[email protected]>
Date: Thu, 26 Oct 2017 07:58:03 +0200* Add a jump target so that a specific error message is stored only once at the end of this function implementation.
* Adjust condition checks.
This issue was detected by using the Coccinelle software.
Signed-off-by Markus Elfring <[email protected]>
Markus,
You need to a apply a check in these cases. If the code is harder to read afterwards and hence more prone to bugs being introduced now or in future, it is not a good change.
As such I won't be taking this sort of change.
Jonathan
Quoted 31 lines
--- drivers/iio/adc/palmas_gpadc.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)drivers/iio/adc/palmas_gpadc.c +4
-8@@ -304,17 +304,13 @@ static int palmas_gpadc_calibrate(struct palmas_gpadc *adc, int adc_chan) ret =palmas_read (adc->palmas,PALMAS_TRIM_GPADC_BASE , adc->adc_info[adc_chan].trim1_reg, &d1); -if (ret <0 ) { -dev_err (adc->dev,"TRIM read failed: %d\n" , ret); - goto scrub; - } +if (ret) + goto report_failure; ret =palmas_read (adc->palmas,PALMAS_TRIM_GPADC_BASE , adc->adc_info[adc_chan].trim2_reg, &d2); -if (ret <0 ) { -dev_err (adc->dev,"TRIM read failed: %d\n" , ret); - goto scrub; - } +if (ret) + goto report_failure;/* gain error calculation */ k = (1000 + (1000 * (d2 - d1)) / (x2 - x1));
drivers/iio/adc/palmas_gpadc.c static int palmas_gpadc_calibrate(struct palmas_gpadc *adc, int adc_chan) · line 329
Quoted 5 lines
drivers/iio/adc/palmas_gpadc.c +2
-0@@ -329,6 +325,10 @@ static int palmas_gpadc_calibrate(struct palmas_gpadc *adc, int adc_chan) scrub:return ret; + +report_failure:
This makes for complex code flow where it is not needed. As such I am not going to even think about taking this sort of patch.
Quoted 5 lines
drivers/iio/adc/palmas_gpadc.c +2
-0+dev_err (adc->dev,"TRIM read failed: %d\n" , ret); + goto scrub; }static int palmas_gpadc_start_conversion (struct palmas_gpadc *adc,int adc_chan)
Quoted 8 lines
drivers/iio/adc/palmas_gpadc.c static int palmas_gpadc_calibrate(struct palmas_gpadc *adc, int adc_chan) · line 329
Quoted 6 lines
drivers/iio/adc/palmas_gpadc.c +2
-0@@ -329,6 +325,10 @@ static int palmas_gpadc_calibrate(struct palmas_gpadc *adc, int adc_chan) scrub:return ret; + +report_failure:This makes for complex code flow where it is not needed.
The shown code layout would be required in the suggested software design direction.
Quoted 1 line
As such I am not going to even think about taking this sort of patch.
It might take more time until similar situations will be reconsidered.
Quoted 5 lines
drivers/iio/adc/palmas_gpadc.c static int palmas_gpadc_calibrate(struct palmas_gpadc *adc, int adc_chan) · line 334
Quoted 5 lines
drivers/iio/adc/palmas_gpadc.c +2
-0+dev_err (adc->dev,"TRIM read failed: %d\n" , ret); + goto scrub; }static int palmas_gpadc_start_conversion (struct palmas_gpadc *adc,int adc_chan)
Do any other contributors find a bit of code reduction desirable for this software module?
Regards,
Markus