[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAHp75Vem0ypV9+3JUrt_mBJU_TQ5yrp-ubk_NV2-ejTZ8Ac4Dg@mail.gmail.com>
Date: Tue, 27 Dec 2022 20:30:33 +0200
From: Andy Shevchenko <andy.shevchenko@...il.com>
To: Dan Carpenter <error27@...il.com>
Cc: oe-kbuild@...ts.linux.dev, Qingtao Cao <qingtao.cao.au@...il.com>,
lkp@...el.com, oe-kbuild-all@...ts.linux.dev,
linux-kernel@...r.kernel.org, Bartosz Golaszewski <brgl@...ev.pl>
Subject: Re: drivers/gpio/gpio-exar.c:52 exar_offset_to_sel_addr() warn:
replace divide condition 'pin / 8' with 'pin >= 8'
On Tue, Dec 27, 2022 at 7:46 PM Dan Carpenter <error27@...il.com> wrote:
> On Sun, Dec 25, 2022 at 12:50:46PM +0100, Andy Shevchenko wrote:
> > > Andy Shevchenko <andy.shevchenko@...il.com> kirjoitti 25.12.2022 kello 12.45:
> > >>> Dan Carpenter <error27@...il.com> kirjoitti 24.12.2022 kello 20.30:
> > >>> On Sat, Dec 24, 2022 at 05:19:27PM +0100, Andy Shevchenko wrote:
> > >>>> Dan Carpenter <error27@...il.com> kirjoitti 23.12.2022 kello 11.54:
...
> > >>>> smatch warnings:
> > >>>> drivers/gpio/gpio-exar.c:52 exar_offset_to_sel_addr() warn: replace divide condition 'pin / 8' with 'pin >= 8'
> > >>>> drivers/gpio/gpio-exar.c:62 exar_offset_to_lvl_addr() warn: replace divide condition 'pin / 8' with 'pin >= 8'
> > >>>
> > >>> I don’t think this is a good advice. If we want to limit that, we need
> > >>> to check also upper limit. But. The GPIO framework does that. So,
> > >>> changing / to >= is bogus.
> > >>
> > >> How is checking pin / 8 not mathematically equivalent to pin >= 8?
> > >
> > > The point is that semantically the / is better in case this code will ever support more than two banks of pins.
> >
> > On top of that it’s paired with pin % 8.
>
> I noticed that, but it's a common bug though that a lot of people
> accidentally write if (pin / 8) when if ((pin % 8) == 0) is intended.
Probably. Here the pin/8 is the correct approach, it shows the bank
number, where each bank is out of 8 pins.
> For example:
Thanks, but it's unrelated to this case.
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists