Re: [PATCH v1 5/5] pinctrl: intel: define iterator variables inside for-loop
From: Andy Shevchenko
Date: Thu Mar 19 2026 - 03:23:36 EST
On Thu, Mar 19, 2026 at 08:09:25AM +0100, Mika Westerberg wrote:
> 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:
...
> > > > - 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.
Why? Can you give a constructive feedback, please?
> > > 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.
I can agree on this, but it (in this case theoretically) might lead to subtle
signdness issues if compiler is not capable to see the upper limit and predict
no overflow or wrap-around.
--
With Best Regards,
Andy Shevchenko