Re: [PATCH v1 5/5] pinctrl: intel: define iterator variables inside for-loop
From: Andy Shevchenko
Date: Thu Mar 19 2026 - 03:02:07 EST
On Thu, Mar 19, 2026 at 07:02:21AM +0100, Mika Westerberg wrote:
> On Wed, Mar 18, 2026 at 04:10:19PM +0100, Andy Shevchenko wrote:
> > Reduce the scope of the iterator variables by defining them inside
> > the respective for-loops. This makes code more robust against reuse
> > of the same variable in the future, which might lead to some mistakes.
...
> > - int i;
>
> If there are multiple loops, I prefer to declare the variable outside of
> them.
Why?! It's exactly where it make even more sense to hide.
> If it is just a single loop then for (int i = 0, ..) is fine.
...
> > - for (i = 0; i < grp->grp.npins; i++) {
> > + for (unsigned int i = 0; i < grp->grp.npins; i++) {
>
> also why you use "unsigned int". int i is fine here.
Because grp.npins is unsigned. This is the common sense to use the same
variable type that's used for the (upper) limit.
> > }
--
With Best Regards,
Andy Shevchenko