* [PATCH] pwm: mxs: Disable clock on invalid period error path
@ 2026-11-02 10:50 Xiangwu Lai
2026-11-16 3:10 ` Xiangwu Lai
0 siblings, 1 reply; 3+ messages in thread
From: Xiangwu Lai @ 2026-11-02 10:50 UTC (permalink / raw)
To: Uwe Kleine-König, Frank Li, Sascha Hauer
Cc: Pengutronix Kernel Team, Fabio Estevam, linux-pwm, imx,
linux-arm-kernel, linux-kernel, Xiangwu Lai
mxs_pwm_apply() enables the clock when the PWM channel is currently
disabled, but when the requested period is too long to be represented
by the period divider it returns -EINVAL without disabling it again.
The PWM core does not roll back the hardware state when ->apply()
fails and pwm->state is only updated on success, so pwm_is_enabled()
still reports the old (disabled) state after the failed apply. The
clock is shared by all channels of the chip and stays prepared and
enabled forever, and every further failed apply bumps the enable
count again.
Disable the clock on the error path, mirroring the condition used
when it was enabled.
Fixes: bf29c2ff82fd ("pwm: mxs: Implement ->apply()")
Signed-off-by: Xiangwu Lai <laixiangwu@cmss.chinamobile.com>
---
drivers/pwm/pwm-mxs.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c
index e1a3df654..ece42da8e 100644
--- a/drivers/pwm/pwm-mxs.c
+++ b/drivers/pwm/pwm-mxs.c
@@ -78,8 +78,11 @@ static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,
if (c < PERIOD_PERIOD_MAX)
break;
div++;
- if (div >= PERIOD_CDIV_MAX)
+ if (div >= PERIOD_CDIV_MAX) {
+ if (!pwm_is_enabled(pwm))
+ clk_disable_unprepare(mxs->clk);
return -EINVAL;
+ }
}
period_cycles = c;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pwm: mxs: Disable clock on invalid period error path
2026-11-02 10:50 [PATCH] pwm: mxs: Disable clock on invalid period error path Xiangwu Lai
@ 2026-11-16 3:10 ` Xiangwu Lai
2026-11-16 9:29 ` Uwe Kleine-König
0 siblings, 1 reply; 3+ messages in thread
From: Xiangwu Lai @ 2026-11-16 3:10 UTC (permalink / raw)
To: ukleinek, Frank.Li, s.hauer
Cc: Xiangwu Lai, kernel, festevam, linux-pwm, imx, linux-arm-kernel,
linux-kernel
Hi,
I've noticed that Lee Jones' series "pwm: Fix various bugs
reported by Sashiko" also fixes the clock leak addressed by my
patch below, with a broader scope:
[PATCH 2/8] pwm: mxs: Return early when disabling and fix error-path clock leak
https://lore.kernel.org/all/20261105143847.2559586-3-lee@kernel.org/
Besides balancing clk_prepare_enable() on the same -EINVAL error
path, that patch also handles the !state->enabled case upfront,
avoiding a division by zero when state->period is zero, and it
already carries a Reviewed-by from Frank Li.
My patch for reference:
pwm: mxs: Disable clock on invalid period error path
https://lore.kernel.org/all/20261102105005.1007-1-laixiangwu@cmss.chinamobile.com/
Please feel free to drop my patch in favour of Lee's more complete
fix; there is no need to keep both.
Best regards,
Xiangwu Lai
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] pwm: mxs: Disable clock on invalid period error path
2026-11-16 3:10 ` Xiangwu Lai
@ 2026-11-16 9:29 ` Uwe Kleine-König
0 siblings, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2026-11-16 9:29 UTC (permalink / raw)
To: Xiangwu Lai
Cc: Frank.Li, s.hauer, kernel, festevam, linux-pwm, imx,
linux-arm-kernel, linux-kernel, Lee Jones
[-- Attachment #1: Type: text/plain, Size: 1107 bytes --]
[Cc: += Lee]
Hello,
On Mon, Nov 16, 2026 at 11:10:43AM +0800, Xiangwu Lai wrote:
> I've noticed that Lee Jones' series "pwm: Fix various bugs
> reported by Sashiko" also fixes the clock leak addressed by my
> patch below, with a broader scope:
>
> [PATCH 2/8] pwm: mxs: Return early when disabling and fix error-path clock leak
> https://lore.kernel.org/all/20261105143847.2559586-3-lee@kernel.org/
>
> Besides balancing clk_prepare_enable() on the same -EINVAL error
> path, that patch also handles the !state->enabled case upfront,
> avoiding a division by zero when state->period is zero, and it
> already carries a Reviewed-by from Frank Li.
>
> My patch for reference:
>
> pwm: mxs: Disable clock on invalid period error path
> https://lore.kernel.org/all/20261102105005.1007-1-laixiangwu@cmss.chinamobile.com/
>
> Please feel free to drop my patch in favour of Lee's more complete
> fix; there is no need to keep both.
Thanks for this follow-up, very appreciated. I marked your patch as
Superseded in patchwork in favour of Lee's patch.
Best regards
Uwe
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-16 9:29 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-02 10:50 [PATCH] pwm: mxs: Disable clock on invalid period error path Xiangwu Lai
2026-11-16 3:10 ` Xiangwu Lai
2026-11-16 9:29 ` 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®