mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] pwm: stm32: Add check for clk_enable()
@ 2024-12-15 22:47 Mingwei Zheng
  2024-12-16  8:23 ` Uwe Kleine-König
  0 siblings, 1 reply; 2+ messages in thread
From: Mingwei Zheng @ 2024-12-15 22:47 UTC (permalink / raw)
  To: fabrice.gasnier, ukleinek, mcoquelin.stm32, alexandre.torgue,
	thierry.reding, p.zabel
  Cc: linux-pwm, linux-stm32, linux-arm-kernel, linux-kernel,
	Mingwei Zheng, Jiasheng Jiang

Add check for the return value of clk_enable() to catch the potential
error.

Fixes: 19f1016ea960 ("pwm: stm32: Fix enable count for clk in .probe()")
Signed-off-by: Mingwei Zheng <zmw12306@gmail.com>
Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
---
 drivers/pwm/pwm-stm32.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
index b889e64522c3..b94d186e3c0c 100644
--- a/drivers/pwm/pwm-stm32.c
+++ b/drivers/pwm/pwm-stm32.c
@@ -858,8 +858,11 @@ static int stm32_pwm_probe(struct platform_device *pdev)
 	chip->ops = &stm32pwm_ops;
 
 	/* Initialize clock refcount to number of enabled PWM channels. */
-	for (i = 0; i < num_enabled; i++)
-		clk_enable(priv->clk);
+	for (i = 0; i < num_enabled; i++) {
+		ret = clk_enable(priv->clk);
+		if (ret)
+			return ret;
+	}
 
 	ret = devm_pwmchip_add(dev, chip);
 	if (ret < 0)
-- 
2.34.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] pwm: stm32: Add check for clk_enable()
  2024-12-15 22:47 [PATCH] pwm: stm32: Add check for clk_enable() Mingwei Zheng
@ 2024-12-16  8:23 ` Uwe Kleine-König
  0 siblings, 0 replies; 2+ messages in thread
From: Uwe Kleine-König @ 2024-12-16  8:23 UTC (permalink / raw)
  To: Mingwei Zheng
  Cc: fabrice.gasnier, mcoquelin.stm32, alexandre.torgue,
	thierry.reding, p.zabel, linux-pwm, linux-stm32,
	linux-arm-kernel, linux-kernel, Jiasheng Jiang

[-- Attachment #1: Type: text/plain, Size: 1544 bytes --]

Hello,

On Sun, Dec 15, 2024 at 05:47:52PM -0500, Mingwei Zheng wrote:
> Add check for the return value of clk_enable() to catch the potential
> error.
> 
> Fixes: 19f1016ea960 ("pwm: stm32: Fix enable count for clk in .probe()")
> Signed-off-by: Mingwei Zheng <zmw12306@gmail.com>
> Signed-off-by: Jiasheng Jiang <jiashengjiangcool@gmail.com>
> ---
>  drivers/pwm/pwm-stm32.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c
> index b889e64522c3..b94d186e3c0c 100644
> --- a/drivers/pwm/pwm-stm32.c
> +++ b/drivers/pwm/pwm-stm32.c
> @@ -858,8 +858,11 @@ static int stm32_pwm_probe(struct platform_device *pdev)
>  	chip->ops = &stm32pwm_ops;
>  
>  	/* Initialize clock refcount to number of enabled PWM channels. */
> -	for (i = 0; i < num_enabled; i++)
> -		clk_enable(priv->clk);
> +	for (i = 0; i < num_enabled; i++) {
> +		ret = clk_enable(priv->clk);
> +		if (ret)
> +			return ret;
> +	}

I wondered for some time if we could still improve more here. If the
(say) second clk_enable() or devm_pwmchip_add() fails, the clk_enable()
calls are leaked. However disabling the clk also might have downsides
(as it might stop a running PWM). OTOH the only expected failure point
is the first clk_enable() as the following are just software operations
and devm_pwmchip_add() only fails on memory pressure. So proper cleanup
doesn't really matter.

So I think the patch is fine as is and I will apply it.

Best regards
Uwe

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-12-16  8:23 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-12-15 22:47 [PATCH] pwm: stm32: Add check for clk_enable() Mingwei Zheng
2024-12-16  8:23 ` Uwe Kleine-König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®