[PATCH] pwm: mxs: Disable clock on invalid period error path

Xiangwu Lai laixiangwu at cmss.chinamobile.com
Mon Nov 2 02:50:05 PST 2026


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 at 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;





More information about the linux-arm-kernel mailing list