* [PATCH] iio/adc/palmas: Use common error handling code in palmas_gpadc_calibrate()
@ 2017-10-26 6:08 SF Markus Elfring
2017-10-26 16:33 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: SF Markus Elfring @ 2017-10-26 6:08 UTC (permalink / raw)
To: linux-iio, Alison Schofield, H. Nikolaus Schaller, Hartmut Knaack,
Jonathan Cameron, Lars-Peter Clausen, Peter Meerwald-Stadler
Cc: LKML, kernel-janitors
From: Markus Elfring <elfring@users.sourceforge.net>
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 <elfring@users.sourceforge.net>
---
drivers/iio/adc/palmas_gpadc.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
index 69b9affeef1e..5e6566692d46 100644
--- a/drivers/iio/adc/palmas_gpadc.c
+++ b/drivers/iio/adc/palmas_gpadc.c
@@ -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)
--
2.14.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] iio/adc/palmas: Use common error handling code in palmas_gpadc_calibrate()
2017-10-26 6:08 [PATCH] iio/adc/palmas: Use common error handling code in palmas_gpadc_calibrate() SF Markus Elfring
@ 2017-10-26 16:33 ` Jonathan Cameron
2017-10-27 13:43 ` SF Markus Elfring
0 siblings, 1 reply; 3+ messages in thread
From: Jonathan Cameron @ 2017-10-26 16:33 UTC (permalink / raw)
To: SF Markus Elfring
Cc: linux-iio, Alison Schofield, H. Nikolaus Schaller, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, LKML, kernel-janitors
On Thu, 26 Oct 2017 08:08:49 +0200
SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> 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 <elfring@users.sourceforge.net>
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
> ---
> drivers/iio/adc/palmas_gpadc.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/iio/adc/palmas_gpadc.c b/drivers/iio/adc/palmas_gpadc.c
> index 69b9affeef1e..5e6566692d46 100644
> --- a/drivers/iio/adc/palmas_gpadc.c
> +++ b/drivers/iio/adc/palmas_gpadc.c
> @@ -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:
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.
> + 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)
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] iio/adc/palmas: Use common error handling code in palmas_gpadc_calibrate()
2017-10-26 16:33 ` Jonathan Cameron
@ 2017-10-27 13:43 ` SF Markus Elfring
0 siblings, 0 replies; 3+ messages in thread
From: SF Markus Elfring @ 2017-10-27 13:43 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio
Cc: Alison Schofield, H. Nikolaus Schaller, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, LKML, kernel-janitors
>> @@ -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.
> 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.
>> + 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
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-10-27 13:43 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-26 6:08 [PATCH] iio/adc/palmas: Use common error handling code in palmas_gpadc_calibrate() SF Markus Elfring
2017-10-26 16:33 ` Jonathan Cameron
2017-10-27 13:43 ` SF Markus Elfring
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).