Skip to contentSkip to conversation

gpio: mvebu: Fix optional clock enable handling

PATCH Superseded Yuho Choi 2 participants 2 messages Jul 7 – Jul 8 GPIO

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Yuho Choi

author
#0 lore raw

PATCH 1/1 gpio: mvebu: Fix optional clock enable handling

mvebu_gpio_probe() ignores clk_prepare_enable() failures and has no matching disable path for later probe failures.

Use devm_clk_get_optional_enabled() so clock lookup and enable failures are reported, and so devres disables the clock on cleanup. Reject PWM setup when the optional clock is absent.

Fixes de88747f514a ("gpio: mvebu: Add clk support to prevent lockup")
---
 drivers/gpio/gpio-mvebu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpio/gpio-mvebu.c +3 -3
index c030d1f00abc..c63cdaa78ac1 100644
@@ -1152,10 +1152,10 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
 		return id;
 	}
 
-	mvchip->clk = devm_clk_get(&pdev->dev, NULL);
+	mvchip->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
 	/* Not all SoCs require a clock.*/
-	if (!IS_ERR(mvchip->clk))
-		clk_prepare_enable(mvchip->clk);
+	if (IS_ERR(mvchip->clk))
+		return PTR_ERR(mvchip->clk);
 
 	mvchip->soc_variant = soc_variant;
 	mvchip->chip.label = dev_name(&pdev->dev);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 7 lines · Yuho Choi

mvebu_gpio_probe() ignores clk_prepare_enable() failures and has no matching disable path for later probe failures.

Use devm_clk_get_optional_enabled() so clock lookup and enable failures are reported, and so devres disables the clock on cleanup. Reject PWM setup when the optional clock is absent.

That last sentance is not clear. Which code changes "reject PWM setup" exactly?

Bart

Quoted 28 lines
Fixes de88747f514a ("gpio: mvebu: Add clk support to prevent lockup")
---
 drivers/gpio/gpio-mvebu.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/gpio/gpio-mvebu.c +3 -4
index c030d1f00abc..c63cdaa78ac1 100644
@@ -1152,10 +1152,10 @@ static int mvebu_gpio_probe(struct platform_device *pdev)
 		return id;
 	}
 
-	mvchip->clk = devm_clk_get(&pdev->dev, NULL);
+	mvchip->clk = devm_clk_get_optional_enabled(&pdev->dev, NULL);
 	/* Not all SoCs require a clock.*/
-	if (!IS_ERR(mvchip->clk))
-		clk_prepare_enable(mvchip->clk);
+	if (IS_ERR(mvchip->clk))
+		return PTR_ERR(mvchip->clk);
 
 	mvchip->soc_variant = soc_variant;
 	mvchip->chip.label = dev_name(&pdev->dev);
--

2.43.0