All of lore.kernel.org
 help / color / mirror / Atom feed
From: Guenter Roeck <guenter.roeck@ericsson.com>
To: lm-sensors@vger.kernel.org
Subject: Re: [lm-sensors] [PATCH 2/2] lm90.c: fix checkpatch error
Date: Thu, 05 Jan 2012 14:45:51 +0000	[thread overview]
Message-ID: <20120105144551.GA8347@ericsson.com> (raw)
In-Reply-To: <1325716040-22310-2-git-send-email-fransmeulenbroeks@gmail.com>

On Thu, Jan 05, 2012 at 09:29:04AM -0500, Jean Delvare wrote:
> On Wed, 4 Jan 2012 14:29:05 -0800, Guenter Roeck wrote:
> > On Wed, 2012-01-04 at 17:27 -0500, Frans Meulenbroeks wrote:
> > > Signed-off-by: Frans Meulenbroeks <fransmeulenbroeks@gmail.com>
> > > ---
> > >  drivers/hwmon/lm90.c |   11 ++++++++---
> > >  1 files changed, 8 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/hwmon/lm90.c b/drivers/hwmon/lm90.c
> > > index 615bc4f..36dcbc9 100644
> > > --- a/drivers/hwmon/lm90.c
> > > +++ b/drivers/hwmon/lm90.c
> > > @@ -388,9 +388,14 @@ static int lm90_read16(struct i2c_client *client, u8 regh, u8 regl, u16 *value)
> > >  	 * we have to read the low byte again, and now we believe we have a
> > >  	 * correct reading.
> > >  	 */
> > > -	if ((err = lm90_read_reg(client, regh, &oldh))
> > > -	 || (err = lm90_read_reg(client, regl, &l))
> > > -	 || (err = lm90_read_reg(client, regh, &newh)))
> > > +	err = lm90_read_reg(client, regh, &oldh);
> > > +	if (err)
> > > +		return err;
> > > +	err = lm90_read_reg(client, regl, &l);
> > > +	if (err)
> > > +		return err;
> > > +	err = lm90_read_reg(client, regh, &newh);
> > > +	if (err)
> > >  		return err;
> > >  	if (oldh != newh) {
> > >  		err = lm90_read_reg(client, regl, &l);
> > 
> > Ah, we left those in for readability.
> 
> Actually this is one of the things checkpatch complains about which I
> consider a false positive. There is really nothing wrong with the code
> above, it does the right thing with no risk of error. Its replacement,
> OTOH, is harder to read, and less efficient.
> 
> The check should either be improved to only complain in cases which are
> really wrong, or should be plain discarded if fixing it is not possible.
> 
Strictly speaking, it violates "Don't put multiple statements on a single line",
at least for the first line, so I guess that would be arguable. But I agree, in the 
above case the "correct" way hurts readability.

Sad but true, while I personally like to use assignments in if statements
outside the kernel, I have often seen people make a mess of it, so I can
understand why it is frowned upon in the kernel.

Guenter

_______________________________________________
lm-sensors mailing list
lm-sensors@lm-sensors.org
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors

      parent reply	other threads:[~2012-01-05 14:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-04 22:27 [lm-sensors] [PATCH 2/2] lm90.c: fix checkpatch error Frans Meulenbroeks
2012-01-04 22:29 ` Guenter Roeck
2012-01-05 14:29 ` Jean Delvare
2012-01-05 14:45 ` Guenter Roeck [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120105144551.GA8347@ericsson.com \
    --to=guenter.roeck@ericsson.com \
    --cc=lm-sensors@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.