Re: [PATCH v1 5/5] pinctrl: intel: define iterator variables inside for-loop

From: Mika Westerberg

Date: Thu Mar 19 2026 - 02:06:04 EST


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.
>
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxxxxxxxx>
> ---
> drivers/pinctrl/intel/pinctrl-intel.c | 44 ++++++++++++---------------
> 1 file changed, 19 insertions(+), 25 deletions(-)
>
> diff --git a/drivers/pinctrl/intel/pinctrl-intel.c b/drivers/pinctrl/intel/pinctrl-intel.c
> index 7311b787dfc6..c506f9f343c3 100644
> --- a/drivers/pinctrl/intel/pinctrl-intel.c
> +++ b/drivers/pinctrl/intel/pinctrl-intel.c
> @@ -431,7 +431,6 @@ static int intel_pinmux_set_mux(struct pinctrl_dev *pctldev,
> {
> struct intel_pinctrl *pctrl = pinctrl_dev_get_drvdata(pctldev);
> const struct intel_pingroup *grp = &pctrl->soc->groups[group];
> - int i;

If there are multiple loops, I prefer to declare the variable outside of
them.

If it is just a single loop then for (int i = 0, ..) is fine.

>
> guard(raw_spinlock_irqsave)(&pctrl->lock);
>
> @@ -439,13 +438,13 @@ static int intel_pinmux_set_mux(struct pinctrl_dev *pctldev,
> * All pins in the groups needs to be accessible and writable
> * before we can enable the mux for this group.
> */
> - 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.

> if (!intel_pad_usable(pctrl, grp->grp.pins[i]))
> return -EBUSY;
> }