All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Serge Semin <fancer.lancer@gmail.com>
Cc: Linus Walleij <linus.walleij@linaro.org>,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	linux-gpio@vger.kernel.org
Subject: Re: [PATCH v1 2/4] gpio: dwapb: Don't use 0 as valid Linux interrupt number
Date: Mon, 18 May 2020 19:12:04 +0300	[thread overview]
Message-ID: <20200518161204.GJ1634618@smile.fi.intel.com> (raw)
In-Reply-To: <20200517125244.oayqjhhq5755b4cg@mobilestation>

On Sun, May 17, 2020 at 03:52:44PM +0300, Serge Semin wrote:
> On Tue, May 12, 2020 at 09:45:11PM +0300, Andy Shevchenko wrote:
> > 0 is not valid IRQ number in Linux interrupt number space.
> > Refactor the code with this kept in mind.

Serge, thanks for review, my answers below.

...

> > +	int err, j;
> 
> Err might be used uninitialized here. The compiler also says so:
> 
> drivers/gpio/gpio-dwapb.c:560:14: warning: ‘err’ may be used uninitialized in this function [-Wmaybe-uninitialized]
>    pp->irq[j] = err;
> 
> drivers/gpio/gpio-dwapb.c:547:6: note: ‘err’ was declared here
>   int err, j;

Good catch! I'm puzzled how I missed it :-(
I usually compile with W=1.

Hmm... gcc (Debian 9.3.0-12) 9.3.0 building for i386, doesn't give me a
warning, but I see that there is potentially possible that scenario, so, I'm
going to fix it.

> Could you please make it initialized with error number like -ENXIO by default?

Will do.

> Also if it was just a single issue in my mind, I wouldn't have probably payed
> much attention to this. But since you need to send v2 anyway, I'd prefer to have
> a positive naming here since normally both of_irq_get() and
> platform_get_irq_optional() return IRQ number, and error is returned only on
> failure. So checking an erroneous value of a positively named variable seems
> more natural, rather than copying an error-named variable to a normal variable.
> To cut it short could you please rename err to something like irq?

Makes sense.

...

> > +	pp->has_irq = memchr_inv(pp->irq, 0, sizeof(pp->irq)) != NULL;
> 
> Sorry, but I don't see why is setting the has_irq flag in the loop above worse than
> using memchr_inv()? As I see it since we need to perform the loop above anyway, it
> would be normal to update the flag synchronously there instead of traversing the
> irq's array byte-by-byte again in the memchr_inv() method. Moreover
> (memchr_inv() != NULL) seems harder to read. A kernel hacker needs to keep in
> mind the method semantics, that it returns non-null if unmatched character found
> in the array, to get the line logic. Setting "has_irq = true" is straightforward -
> if IRQ's found then set the flag to true. So if you don't have a strong opinion
> against my reasoning could you please get the setting the has_irq flag back in to
> the loop above?

It's done in that way for a reason of the next clean ups, i.e. moving this to
the actual user of it. I hope you already read further patches to see the
intention behind this change. So, I prefer to leave it as is, however I agree
with you in general.

Btw, we may also leave the domain when even no IRQ is available as some other
drivers do, but I consider it less plausible than using memchr_inv().

-- 
With Best Regards,
Andy Shevchenko



  reply	other threads:[~2020-05-18 16:12 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-12 18:45 [PATCH v1 1/4] gpio: dwapb: avoid error message for optional IRQ Andy Shevchenko
2020-05-12 18:45 ` [PATCH v1 2/4] gpio: dwapb: Don't use 0 as valid Linux interrupt number Andy Shevchenko
2020-05-17 12:52   ` Serge Semin
2020-05-18 16:12     ` Andy Shevchenko [this message]
2020-05-12 18:45 ` [PATCH v1 3/4] gpio: dwapb: Drop extra check to call acpi_gpiochip_request_interrupts() Andy Shevchenko
2020-05-17 13:55   ` Serge Semin
2020-05-17 14:47     ` Serge Semin
2020-05-18 17:03       ` Andy Shevchenko
2020-05-18 17:07     ` Andy Shevchenko
2020-05-12 18:45 ` [PATCH v1 4/4] gpio: dwapb: Remove unneeded has_irq member in struct dwapb_port_property Andy Shevchenko
2020-05-12 22:53   ` kbuild test robot
2020-05-12 22:53     ` kbuild test robot
2020-05-13 10:22     ` Andy Shevchenko
2020-05-13 10:22       ` Andy Shevchenko
2020-05-13 12:39   ` kbuild test robot
2020-05-13 12:39     ` kbuild test robot
2020-05-17 14:26   ` Serge Semin
2020-05-18 17:27     ` Andy Shevchenko
2020-05-13 14:43 ` [PATCH v1 1/4] gpio: dwapb: avoid error message for optional IRQ Andy Shevchenko
2020-05-14 11:59   ` Serge Semin
2020-05-17 12:22 ` Serge Semin

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=20200518161204.GJ1634618@smile.fi.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=fancer.lancer@gmail.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@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.