[PATCH v4] pinctrl: stm32: Add check for clk_enable()

Antonio Borneo antonio.borneo at foss.st.com
Fri Dec 13 05:43:18 PST 2024


On Fri, 2024-12-13 at 12:45 +0100, Marek Vasut wrote:
> On 12/13/24 2:09 AM, Mingwei Zheng wrote:
> 
> [...]
> 
> > @@ -1397,7 +1397,7 @@ static int stm32_gpiolib_register_bank(struct stm32_pinctrl *pctl, struct fwnode
> >         return 0;
> >   
> >   err_clk:
> > -       clk_disable_unprepare(bank->clk);
> > +       clk_disable_unprepare(pctl->clks[pctl->nbanks].clk);
> 
> 
> Should this be
> 
> -clk_disable_unprepare(pctl->clks[pctl->nbanks].clk);
> +clk_disable_unprepare(pctl->clks[bank->bank_nr].clk);
>                                    ^^^^^^^^^^^^^
> 

No Marek,
pctl->nbanks is the progressive index of the bank's subnode, that is also the index for pctl->clks[].
Instead bank->bank_nr can be computed from gpio-ranges, and there is no guarantee it would match the index for pctl->clks[].

Actually this is quite confusing; I think it would be much cleaner dropping the clock handling from stm32_gpiolib_register_bank() and moving it to its caller.
In stm32_pctl_probe() we can just call clk_bulk_prepare_enable() and, in case of error, clk_bulk_disable_unprepare()

Antonio

> ?
> 
> >         return err;
> >   }
> >   
> > @@ -1617,10 +1617,18 @@ int stm32_pctl_probe(struct platform_device *pdev)
> >                 return -EINVAL;
> >         }
> >         pctl->banks = devm_kcalloc(dev, banks, sizeof(*pctl->banks),
> > -                       GFP_KERNEL);
> > +                                  GFP_KERNEL);
> >         if (!pctl->banks)
> >                 return -ENOMEM;
> >   
> > +       pctl->clks = devm_kcalloc(dev, banks, sizeof(*pctl->clks),
> > +                                 GFP_KERNEL);
> > +       if (!pctl->clks)
> > +               return -ENOMEM;
> > +
> > +       for (i = 0; i < banks; ++i)
> 
> i++



More information about the linux-arm-kernel mailing list