lkml.org 
[lkml]   [2022]   [Dec]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Date
SubjectRe: 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@gmail.com> wrote:
> On Sun, Dec 25, 2022 at 12:50:46PM +0100, Andy Shevchenko wrote:
> > > Andy Shevchenko <andy.shevchenko@gmail.com> kirjoitti 25.12.2022 kello 12.45:
> > >>> Dan Carpenter <error27@gmail.com> kirjoitti 24.12.2022 kello 20.30:
> > >>> On Sat, Dec 24, 2022 at 05:19:27PM +0100, Andy Shevchenko wrote:
> > >>>> Dan Carpenter <error27@gmail.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

\
 
 \ /
  Last update: 2023-03-26 23:21    [W:0.085 / U:0.128 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site