Re: [PATCH v1 5/5] pinctrl: intel: define iterator variables inside for-loop
From: Mika Westerberg
Date: Thu Mar 19 2026 - 03:10:30 EST
On Thu, Mar 19, 2026 at 08:57:58AM +0200, Andy Shevchenko wrote:
> 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.
I disagree.
>
> > 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.
No, just use "int i" there. Compiler is fine and this is more idiomatic C
anyways.