If period_ns is small, prd might well become 0. Catch that case because otherwise with regmap_write(priv->regmap, TIM_ARR, prd - 1); a few lines down quite a big period is configured. Fixes: 7edf7369205b ("pwm: Add driver for STM32 plaftorm") Cc: stable@xxxxxxxxxxxxxxx Reviewed-by: Trevor Gamblin <tgamblin@xxxxxxxxxxxx> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxx> Link: https://lore.kernel.org/r/b86f62f099983646f97eeb6bfc0117bb2d0c340d.1718979150.git.u.kleine-koenig@xxxxxxxxxxxx Signed-off-by: Uwe Kleine-König <ukleinek@xxxxxxxxxx> (cherry picked from commit c45fcf46ca2368dafe7e5c513a711a6f0f974308) Signed-off-by: Uwe Kleine-König <u.kleine-koenig@xxxxxxxxxxxx> --- Hello, this is a backport of c45fcf46ca2368dafe7e5c513a711a6f0f974308 to 6.9.y. It applies fine to 4.19.y, 5.4.y, 5.10.y, 5.15.y, 6.1.y and 6.6.y, too. Please apply accordingly. Best regards Uwe drivers/pwm/pwm-stm32.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/pwm/pwm-stm32.c b/drivers/pwm/pwm-stm32.c index 0c028d17c075..9f07d50aba2a 100644 --- a/drivers/pwm/pwm-stm32.c +++ b/drivers/pwm/pwm-stm32.c @@ -329,6 +329,9 @@ static int stm32_pwm_config(struct stm32_pwm *priv, unsigned int ch, prd = div; + if (!prd) + return -EINVAL; + if (prescaler > MAX_TIM_PSC) return -EINVAL; base-commit: 9c5a72fbc90d829ffb761da64a73c23cd4e0503f -- 2.43.0