Re: [PATCH v1 1/1] pinctrl: Move for_each_maps() to namespace and hide iterator inside

From: Linus Walleij
Date: Thu Nov 10 2022 - 04:56:04 EST


On Wed, Nov 9, 2022 at 5:08 PM Andy Shevchenko
<andriy.shevchenko@xxxxxxxxxxxxxxx> wrote:
> On Wed, Nov 09, 2022 at 05:57:24PM +0200, Andy Shevchenko wrote:
> > First of all, while for_each_maps() is private to pin control subsystem
> > it's still better to have it put into a namespace.
> >
> > Besides that, users are not relying on iterator variable, so hide it
> > inside for-loop.
>
> ...
>
> > +#define for_each_pin_map(_maps_node_, _map_) \
> > + list_for_each_entry(_maps_node_, &pinctrl_maps, node) \
> > + for (unsigned int __i = 0; \
>
> > + _map_ = &_maps_node_->maps[__i], __i < _maps_node_->num_maps; \
>
> Hmm... I think this is actually not okay, if we have maps be NULL and
> num_maps = 0, KABOOM is guaranteed.
>
> I will experiment and update this.

OK

> Meanwhile, Linus, do you think this change is useful?

Even if just a name change, it makes things better by being more
readable so yes :)

Yours,
Linus Walleij