Message ID | 20241205045942.2441430-1-zmw12306@gmail.com |
---|---|
State | New |
Headers | show |
Series | pinctrl: stm32: Add check for clk_enable() | expand |
On 12/5/24 5:59 AM, Mingwei Zheng wrote: > Add check for the return value of clk_enable() to catch the potential > error. Add a cleanup loop to disable clocks already enabled in case > of an error during clock enabling for subsequent banks. > > Fixes: 05d8af449d93 ("pinctrl: stm32: Keep pinctrl block clock enabled when LEVEL IRQ requested") > Signed-off-by: Mingwei Zheng <zmw12306@gmail.com> > Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com> > --- > drivers/pinctrl/stm32/pinctrl-stm32.c | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c > index 5b7fa77c1184..eb7b2f864d88 100644 > --- a/drivers/pinctrl/stm32/pinctrl-stm32.c > +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c > @@ -1738,10 +1738,16 @@ int __maybe_unused stm32_pinctrl_resume(struct device *dev) > { > struct stm32_pinctrl *pctl = dev_get_drvdata(dev); > struct stm32_pinctrl_group *g = pctl->groups; > - int i; > + int i, j, ret; > > - for (i = 0; i < pctl->nbanks; i++) > - clk_enable(pctl->banks[i].clk); > + for (i = 0; i < pctl->nbanks; i++) { > + ret = clk_enable(pctl->banks[i].clk); > + if (ret) { > + for (j = 0; j < i; j++) Instead of this open-coded loop, can you please convert the driver to clk_bulk*() API and then do simple clk_bulk_enable()/clk_bulk_disable() here and everywhere ? Thank you
diff --git a/drivers/pinctrl/stm32/pinctrl-stm32.c b/drivers/pinctrl/stm32/pinctrl-stm32.c index 5b7fa77c1184..eb7b2f864d88 100644 --- a/drivers/pinctrl/stm32/pinctrl-stm32.c +++ b/drivers/pinctrl/stm32/pinctrl-stm32.c @@ -1738,10 +1738,16 @@ int __maybe_unused stm32_pinctrl_resume(struct device *dev) { struct stm32_pinctrl *pctl = dev_get_drvdata(dev); struct stm32_pinctrl_group *g = pctl->groups; - int i; + int i, j, ret; - for (i = 0; i < pctl->nbanks; i++) - clk_enable(pctl->banks[i].clk); + for (i = 0; i < pctl->nbanks; i++) { + ret = clk_enable(pctl->banks[i].clk); + if (ret) { + for (j = 0; j < i; j++) + clk_disable(pctl->banks[j].clk); + return ret; + } + } for (i = 0; i < pctl->ngroups; i++, g++) stm32_pinctrl_restore_gpio_regs(pctl, g->pin);