mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guenter Roeck <guenter.roeck@ericsson.com>
To: "axel.lin@gmail.com" <axel.lin@gmail.com>
Cc: Jean Delvare <khali@linux-fr.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"lm-sensors@lm-sensors.org" <lm-sensors@lm-sensors.org>
Subject: Re: [PATCH v2] hwmon: (pmbus) Fix the logic of checking if no id is matched
Date: Wed, 31 Aug 2011 08:27:55 -0700	[thread overview]
Message-ID: <1314804475.2455.17.camel@groeck-laptop> (raw)
In-Reply-To: <CAF+7xWnDSTOJh9cs9tUJdF=k=TD56JN1cMvfNM_ng4vw5Gntyg@mail.gmail.com>

On Wed, 2011-08-31 at 10:30 -0400, Axel Lin wrote:
> 2011/8/31 Jean Delvare <khali@linux-fr.org>:
> > Hi Alex,
> It's Axel.
> 
> >
> > On Wed, 31 Aug 2011 12:58:19 +0800, Axel Lin wrote:
> >> If no id is matched, the mid pointer is not NULL in current implementation.
> >
> > The NULL check is presumably there to catch the (impossible) case
> > ARRAY_SIZE(ucd9000_id) == 0 (array of ids is empty), not the case "no
> > id is matched". The initialization of mid to NULL is for the same
> > reason. Both should be unnecessary but may have been motivated by a
> > compiler warning (although I would think gcc is smart enough to not
> > emit these when it can check that the array isn't empty.) Guenter
> > should be able to tell more.
> >
Yes, that was the idea, and as far as I recall I did get a compiler
warning at the time. The loop aborts at the last entry due to the
strncasecmp() match on the zero length string. Axel's patch won't work,
since i == ARRAY_SIZE(ucd9000_id) is never true for the same reason.

> > The check for "no id is matched" is !strlen(mid->name), which works as
> > intended as far as I can see. Did you actually hit a bug with the
> > current code? I bet not.
> No, I didn't hit the bug. Just reading the code.
> 
Finally someone else looking into that code ... thanks, I really
appreciate that.

> >
> > Now I would agree that the current code is somewhat misleading because
> > mixing null-terminated arrays with ARRAY_SIZE() is unusual (and
> > inefficient - the last iteration always fails.) Also, strlen() is
> > relatively slow and would rather be avoided when only testing if a
> > string is empty or not: it's faster to test for mid->name[0].
> >
> > So if anything I would propose the following changes (for performance
> > and readability, NOT bug fix), untested:
> Your fix looks good to me. ( Although I don't have the h/w for testing ).
> 
I like it too. I'll dig out my test boards and test it. Jean, care to
submit complete patches ? Otherwise I'll create a set myself and send it
out for review once I tested it.

Thanks,
Guenter



      reply	other threads:[~2011-08-31 15:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-31  4:58 Axel Lin
2011-08-31 10:05 ` Jean Delvare
2011-08-31 14:30   ` Axel Lin
2011-08-31 15:27     ` 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=1314804475.2455.17.camel@groeck-laptop \
    --to=guenter.roeck@ericsson.com \
    --cc=axel.lin@gmail.com \
    --cc=khali@linux-fr.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lm-sensors@lm-sensors.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®