Skip to content

Commit 5c4bfbb

Browse files
zmw12306Linus Walleij
authored andcommitted
pinctrl: nomadik: Add check for clk_enable()
Add check for the return value of clk_enable() to catch the potential error. Disable success clks in the error handling. Change return type of nmk_gpio_glitch_slpm_init casade. Fixes: 3a19805 ("pinctrl: nomadik: move all Nomadik drivers to subdir") Signed-off-by: Mingwei Zheng <[email protected]> Signed-off-by: Jiasheng Jiang <[email protected]> Link: https://lore.kernel.org/[email protected] Signed-off-by: Linus Walleij <[email protected]>
1 parent efe479c commit 5c4bfbb

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

drivers/pinctrl/nomadik/pinctrl-nomadik.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,9 +438,9 @@ static void nmk_prcm_altcx_set_mode(struct nmk_pinctrl *npct,
438438
* - Any spurious wake up event during switch sequence to be ignored and
439439
* cleared
440440
*/
441-
static void nmk_gpio_glitch_slpm_init(unsigned int *slpm)
441+
static int nmk_gpio_glitch_slpm_init(unsigned int *slpm)
442442
{
443-
int i;
443+
int i, j, ret;
444444

445445
for (i = 0; i < NMK_MAX_BANKS; i++) {
446446
struct nmk_gpio_chip *chip = nmk_gpio_chips[i];
@@ -449,11 +449,21 @@ static void nmk_gpio_glitch_slpm_init(unsigned int *slpm)
449449
if (!chip)
450450
break;
451451

452-
clk_enable(chip->clk);
452+
ret = clk_enable(chip->clk);
453+
if (ret) {
454+
for (j = 0; j < i; j++) {
455+
chip = nmk_gpio_chips[j];
456+
clk_disable(chip->clk);
457+
}
458+
459+
return ret;
460+
}
453461

454462
slpm[i] = readl(chip->addr + NMK_GPIO_SLPC);
455463
writel(temp, chip->addr + NMK_GPIO_SLPC);
456464
}
465+
466+
return 0;
457467
}
458468

459469
static void nmk_gpio_glitch_slpm_restore(unsigned int *slpm)
@@ -923,7 +933,9 @@ static int nmk_pmx_set(struct pinctrl_dev *pctldev, unsigned int function,
923933

924934
slpm[nmk_chip->bank] &= ~BIT(bit);
925935
}
926-
nmk_gpio_glitch_slpm_init(slpm);
936+
ret = nmk_gpio_glitch_slpm_init(slpm);
937+
if (ret)
938+
goto out_pre_slpm_init;
927939
}
928940

929941
for (i = 0; i < g->grp.npins; i++) {
@@ -940,7 +952,10 @@ static int nmk_pmx_set(struct pinctrl_dev *pctldev, unsigned int function,
940952
dev_dbg(npct->dev, "setting pin %d to altsetting %d\n",
941953
g->grp.pins[i], g->altsetting);
942954

943-
clk_enable(nmk_chip->clk);
955+
ret = clk_enable(nmk_chip->clk);
956+
if (ret)
957+
goto out_glitch;
958+
944959
/*
945960
* If the pin is switching to altfunc, and there was an
946961
* interrupt installed on it which has been lazy disabled,
@@ -988,6 +1003,7 @@ static int nmk_gpio_request_enable(struct pinctrl_dev *pctldev,
9881003
struct nmk_gpio_chip *nmk_chip;
9891004
struct gpio_chip *chip;
9901005
unsigned int bit;
1006+
int ret;
9911007

9921008
if (!range) {
9931009
dev_err(npct->dev, "invalid range\n");
@@ -1004,7 +1020,9 @@ static int nmk_gpio_request_enable(struct pinctrl_dev *pctldev,
10041020

10051021
find_nmk_gpio_from_pin(pin, &bit);
10061022

1007-
clk_enable(nmk_chip->clk);
1023+
ret = clk_enable(nmk_chip->clk);
1024+
if (ret)
1025+
return ret;
10081026
/* There is no glitch when converting any pin to GPIO */
10091027
__nmk_gpio_set_mode(nmk_chip, bit, NMK_GPIO_ALT_GPIO);
10101028
clk_disable(nmk_chip->clk);
@@ -1058,6 +1076,7 @@ static int nmk_pin_config_set(struct pinctrl_dev *pctldev, unsigned int pin,
10581076
unsigned long cfg;
10591077
int pull, slpm, output, val, i;
10601078
bool lowemi, gpiomode, sleep;
1079+
int ret;
10611080

10621081
nmk_chip = find_nmk_gpio_from_pin(pin, &bit);
10631082
if (!nmk_chip) {
@@ -1116,7 +1135,9 @@ static int nmk_pin_config_set(struct pinctrl_dev *pctldev, unsigned int pin,
11161135
output ? (val ? "high" : "low") : "",
11171136
lowemi ? "on" : "off");
11181137

1119-
clk_enable(nmk_chip->clk);
1138+
ret = clk_enable(nmk_chip->clk);
1139+
if (ret)
1140+
return ret;
11201141
if (gpiomode)
11211142
/* No glitch when going to GPIO mode */
11221143
__nmk_gpio_set_mode(nmk_chip, bit, NMK_GPIO_ALT_GPIO);

0 commit comments

Comments
 (0)