Skip to content

Commit c45fcf4

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: stm32: Refuse too small period requests
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: 7edf736 ("pwm: Add driver for STM32 plaftorm") Cc: stable@vger.kernel.org Reviewed-by: Trevor Gamblin <tgamblin@baylibre.com> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Link: https://lore.kernel.org/r/b86f62f099983646f97eeb6bfc0117bb2d0c340d.1718979150.git.u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
1 parent 1613e60 commit c45fcf4

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

drivers/pwm/pwm-stm32.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,8 @@ static int stm32_pwm_config(struct stm32_pwm *priv, unsigned int ch,
337337

338338
prd = mul_u64_u64_div_u64(period_ns, clk_get_rate(priv->clk),
339339
(u64)NSEC_PER_SEC * (prescaler + 1));
340+
if (!prd)
341+
return -EINVAL;
340342

341343
/*
342344
* All channels share the same prescaler and counter so when two

0 commit comments

Comments
 (0)