pwm: stm32: Add check for clk_enable()
Subsystems (3)
PATCH 1/1 pwm: stm32: Add check for clk_enable()
Add check for the return value of clk_enable() to catch the potential error.
--- drivers/pwm/pwm-stm32.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
drivers/pwm/pwm-stm32.c +5 -2
@@ -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 )
Signature · 1 line
2.34.1
Uwe Kleine-König
maintainerHello,
Quoted 15 lines · Mingwei Zheng
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 <[email protected]>Signed-off-by Jiasheng Jiang <[email protected]>--- drivers/pwm/pwm-stm32.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)drivers/pwm/pwm-stm32.c +0
-0
drivers/pwm/pwm-stm32.c static int stm32_pwm_probe(struct platform_device *pdev) · line 865
Quoted 10 lines
drivers/pwm/pwm-stm32.c +5
-2@@ -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