Skip to content

Commit 928446a

Browse files
ukleinekUwe Kleine-König
authored andcommitted
pwm: fsl-ftm: Handle clk_get_rate() returning 0
Considering that the driver doesn't enable the used clocks (and also that clk_get_rate() returns 0 if CONFIG_HAVE_CLK is unset) better check the return value of clk_get_rate() for being non-zero before dividing by it. Fixes: 3479bbd ("pwm: fsl-ftm: More relaxed permissions for updating period") Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com> Link: https://lore.kernel.org/r/b68351a51017035651bc62ad3146afcb706874f0.1743501688.git.u.kleine-koenig@baylibre.com Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>
1 parent e7327c1 commit 928446a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

drivers/pwm/pwm-fsl-ftm.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ static unsigned int fsl_pwm_ticks_to_ns(struct fsl_pwm_chip *fpc,
118118
unsigned long long exval;
119119

120120
rate = clk_get_rate(fpc->clk[fpc->period.clk_select]);
121+
if (rate >> fpc->period.clk_ps == 0)
122+
return 0;
123+
121124
exval = ticks;
122125
exval *= 1000000000UL;
123126
do_div(exval, rate >> fpc->period.clk_ps);
@@ -190,6 +193,9 @@ static unsigned int fsl_pwm_calculate_duty(struct fsl_pwm_chip *fpc,
190193
unsigned int period = fpc->period.mod_period + 1;
191194
unsigned int period_ns = fsl_pwm_ticks_to_ns(fpc, period);
192195

196+
if (!period_ns)
197+
return 0;
198+
193199
duty = (unsigned long long)duty_ns * period;
194200
do_div(duty, period_ns);
195201

0 commit comments

Comments
 (0)