[PATCH] pinctrl: stm32: Add check for clk_enable()
From: Mingwei Zheng
Date: Wed Dec 04 2024 - 23:56:32 EST
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@xxxxxxxxx>
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@xxxxxxxxx>
---
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++)
+ clk_disable(pctl->banks[j].clk);
+ return ret;
+ }
+ }
for (i = 0; i < pctl->ngroups; i++, g++)
stm32_pinctrl_restore_gpio_regs(pctl, g->pin);
--
2.34.1