lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Date: Thu, 22 Feb 2024 10:18:02 +0100
From: Linus Walleij <linus.walleij@...aro.org>
To: Bartosz Golaszewski <brgl@...ev.pl>
Cc: linux-gpio@...r.kernel.org, linux-kernel@...r.kernel.org, 
	Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
Subject: Re: [PATCH 1/2] gpio: provide for_each_gpio()

On Thu, Feb 22, 2024 at 9:48 AM Bartosz Golaszewski <brgl@...ev.pl> wrote:
> On Wed, Feb 21, 2024 at 10:51 PM Linus Walleij <linus.walleij@...aro.org> wrote:
> >
> > Hi Bartosz,
> >
> > On Thu, Feb 15, 2024 at 9:33 AM Bartosz Golaszewski <brgl@...evpl> wrote:
> >
> > > From: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
> > >
> > > We only provide iterators for requested GPIOs to provider drivers. In
> > > order to allow them to display debug information about all GPIOs, let's
> > > provide a variant for iterating over all GPIOs.
> > >
> > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@...aro.org>
> > (...)
> >
> > > +/**
> > > + * for_each_gpio - Iterates over all GPIOs for given chip.
> >
> > Does this really intuitively fit with other functions named for_each_XXX()?
> >
> > > + * @_chip: Chip to iterate over.
> > > + * @_i: Loop counter.
> > > + * @_label: Place to store the address of the label if the GPIO is requested.
> > > + *          Set to NULL for unused GPIOs.
> > > + */
> > > +#define for_each_gpio(_chip, _i, _label) \
> > > +       for (CLASS(_gpiochip_for_each_data, _data)(&_label, &_i); \
> > > +            *_data.i < _chip->ngpio; \
> > > +            (*_data.i)++, kfree(*(_data.label)), *_data.label = NULL) \
> > > +               if (IS_ERR(*_data.label = \
> > > +                       gpiochip_dup_line_label(_chip, *_data.i))) {} \
> > > +               else
> >
> > I would call it for_each_line_label() or something. I try to avoid using
> > "gpio" in function names as well because of ambiguity, I could also go
> > with for_each_hwgpio_label() I suppose.
>
> The problem is: this doesn't iterate over labels. It really goes
> through all offsets and if there's no consumer then the label is NULL
> (I should have said that in the kerneldoc).
>
> >
> > With some more reasonable name:
>
> Does for_each_hwgpio() make more sense?

It's better it reflects the usage, but isn't the usage to conditionally
extract the label (or NULL) for each hwgpio?

What I'm after is if there is a risk that someone think this is a generic
iterator for hwgpios which would be confusing.

At the same time
for_each_hwgpio_attempt_extract_label() is a bit long I guess.

I don't wanna bikeshed too much so go with for_each_hwgpio() if
you don't immediately see anything better.

Yours,
Linus Walleij

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ