* [PATCH] iio/light/max44000: Use common error handling code in max44000_probe()
@ 2017-10-26 8:40 SF Markus Elfring
2017-10-26 16:29 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: SF Markus Elfring @ 2017-10-26 8:40 UTC (permalink / raw)
To: linux-iio, Akinobu Mita, Crestez Dan Leonard, 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 10:30:57 +0200
* Add a jump target so that a specific error message is stored only once
at the end of this function implementation.
* Replace two calls of the function "dev_err" by goto statements.
* Adjust condition checks.
This issue was detected by using the Coccinelle software.
Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
drivers/iio/light/max44000.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/light/max44000.c b/drivers/iio/light/max44000.c
index bcdb0eb9e537..8f4bc6a918d5 100644
--- a/drivers/iio/light/max44000.c
+++ b/drivers/iio/light/max44000.c
@@ -569,18 +569,14 @@ static int max44000_probe(struct i2c_client *client,
* Set a middle value so that we get some sort of valid data by default.
*/
ret = max44000_write_led_current_raw(data, MAX44000_LED_CURRENT_DEFAULT);
- if (ret < 0) {
- dev_err(&client->dev, "failed to write init config: %d\n", ret);
- return ret;
- }
+ if (ret)
+ goto report_failure;
/* Reset CFG bits to ALS_PRX mode which allows easy reading of both values. */
reg = MAX44000_CFG_TRIM | MAX44000_CFG_MODE_ALS_PRX;
ret = regmap_write(data->regmap, MAX44000_REG_CFG_MAIN, reg);
- if (ret < 0) {
- dev_err(&client->dev, "failed to write init config: %d\n", ret);
- return ret;
- }
+ if (ret)
+ goto report_failure;
/* Read status at least once to clear any stale interrupt bits. */
ret = regmap_read(data->regmap, MAX44000_REG_STATUS, ®);
@@ -596,6 +592,10 @@ static int max44000_probe(struct i2c_client *client,
}
return iio_device_register(indio_dev);
+
+report_failure:
+ dev_err(&client->dev, "failed to write init config: %d\n", ret);
+ return ret;
}
static int max44000_remove(struct i2c_client *client)
--
2.14.3
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iio/light/max44000: Use common error handling code in max44000_probe()
2017-10-26 8:40 [PATCH] iio/light/max44000: Use common error handling code in max44000_probe() SF Markus Elfring
@ 2017-10-26 16:29 ` Jonathan Cameron
2017-10-26 16:50 ` SF Markus Elfring
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Cameron @ 2017-10-26 16:29 UTC (permalink / raw)
To: SF Markus Elfring
Cc: linux-iio, Akinobu Mita, Crestez Dan Leonard, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, LKML, kernel-janitors
On Thu, 26 Oct 2017 10:40:12 +0200
SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> From: Markus Elfring <elfring@users.sourceforge.net>
> Date: Thu, 26 Oct 2017 10:30:57 +0200
>
> * Add a jump target so that a specific error message is stored only once
> at the end of this function implementation.
>
> * Replace two calls of the function "dev_err" by goto statements.
>
> * Adjust condition checks.
>
> This issue was detected by using the Coccinelle software.
>
> Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
Again, throttle your patch sending please Markus as it will save
everyone time. I try to give full reasoning in each patch because
others may encounter them without having visibility of similar
patches posted at the same time. As such I end up writing
the same thing multiple times wasting my time on top of the time
you have already wasted by sending out multiple patches of a type
I am going to reject..
> ---
> drivers/iio/light/max44000.c | 16 ++++++++--------
> 1 file changed, 8 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/iio/light/max44000.c b/drivers/iio/light/max44000.c
> index bcdb0eb9e537..8f4bc6a918d5 100644
> --- a/drivers/iio/light/max44000.c
> +++ b/drivers/iio/light/max44000.c
> @@ -569,18 +569,14 @@ static int max44000_probe(struct i2c_client *client,
> * Set a middle value so that we get some sort of valid data by default.
> */
> ret = max44000_write_led_current_raw(data, MAX44000_LED_CURRENT_DEFAULT);
> - if (ret < 0) {
> - dev_err(&client->dev, "failed to write init config: %d\n", ret);
> - return ret;
> - }
> + if (ret)
> + goto report_failure;
>
> /* Reset CFG bits to ALS_PRX mode which allows easy reading of both values. */
> reg = MAX44000_CFG_TRIM | MAX44000_CFG_MODE_ALS_PRX;
> ret = regmap_write(data->regmap, MAX44000_REG_CFG_MAIN, reg);
> - if (ret < 0) {
> - dev_err(&client->dev, "failed to write init config: %d\n", ret);
> - return ret;
> - }
> + if (ret)
> + goto report_failure;
>
> /* Read status at least once to clear any stale interrupt bits. */
> ret = regmap_read(data->regmap, MAX44000_REG_STATUS, ®);
> @@ -596,6 +592,10 @@ static int max44000_probe(struct i2c_client *client,
> }
>
> return iio_device_register(indio_dev);
> +
> +report_failure:
> + dev_err(&client->dev, "failed to write init config: %d\n", ret);
This reduces readability of the code for a very minor gain.
Printing an error message is not a source of bugs or similar unlike
unwinding some state, so a unified path makes little sense.
> + return ret;
> }
>
> static int max44000_remove(struct i2c_client *client)
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio/light/max44000: Use common error handling code in max44000_probe()
2017-10-26 16:29 ` Jonathan Cameron
@ 2017-10-26 16:50 ` SF Markus Elfring
2017-10-26 17:39 ` Jonathan Cameron
0 siblings, 1 reply; 4+ messages in thread
From: SF Markus Elfring @ 2017-10-26 16:50 UTC (permalink / raw)
To: Jonathan Cameron, linux-iio
Cc: Akinobu Mita, Crestez Dan Leonard, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, LKML, kernel-janitors
>> @@ -596,6 +592,10 @@ static int max44000_probe(struct i2c_client *client,
>> }
>>
>> return iio_device_register(indio_dev);
>> +
>> +report_failure:
>> + dev_err(&client->dev, "failed to write init config: %d\n", ret);
> This reduces readability of the code for a very minor gain.
I got an other software development view on this aspect.
> Printing an error message is not a source of bugs
I find such a general information questionable.
It is also possible to discover various update candidates in this software area.
> or similar unlike unwinding some state, so a unified path makes little sense.
How does such a view fit to the section “7) Centralized exiting of functions”
in the document “coding-style.rst”?
Regards,
Markus
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] iio/light/max44000: Use common error handling code in max44000_probe()
2017-10-26 16:50 ` SF Markus Elfring
@ 2017-10-26 17:39 ` Jonathan Cameron
0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2017-10-26 17:39 UTC (permalink / raw)
To: SF Markus Elfring
Cc: linux-iio, Akinobu Mita, Crestez Dan Leonard, Hartmut Knaack,
Lars-Peter Clausen, Peter Meerwald-Stadler, LKML, kernel-janitors
On Thu, 26 Oct 2017 18:50:14 +0200
SF Markus Elfring <elfring@users.sourceforge.net> wrote:
> >> @@ -596,6 +592,10 @@ static int max44000_probe(struct i2c_client *client,
> >> }
> >>
> >> return iio_device_register(indio_dev);
> >> +
> >> +report_failure:
> >> + dev_err(&client->dev, "failed to write init config: %d\n", ret);
> > This reduces readability of the code for a very minor gain.
>
> I got an other software development view on this aspect.
>
Sadly I am going to put my foot down here before more time
is wasted. I am not going to discuss it further after this email.
(for others please see the amount of time already wasted on
what are mostly poor code changes from Markus).
>
> > Printing an error message is not a source of bugs
>
> I find such a general information questionable.
>
> It is also possible to discover various update candidates in this software area.
Judge each one carefully. You need to be convincingly improving the code
not just obeying rules blindly.
>
>
> > or similar unlike unwinding some state, so a unified path makes little sense.
>
> How does such a view fit to the section “7) Centralized exiting of functions”
> in the document “coding-style.rst”?
All rules in there need to be applied with care. If they make the code
worse do not blindly apply them.
>
> Regards,
> Markus
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-10-26 17:48 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-10-26 8:40 [PATCH] iio/light/max44000: Use common error handling code in max44000_probe() SF Markus Elfring
2017-10-26 16:29 ` Jonathan Cameron
2017-10-26 16:50 ` SF Markus Elfring
2017-10-26 17:39 ` Jonathan Cameron
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).