diff options
author | Uwe Kleine-König <u.kleine-koenig@pengutronix.de> | 2022-07-12 18:15:19 +0200 |
---|---|---|
committer | Thierry Reding <thierry.reding@gmail.com> | 2022-07-29 13:41:18 +0200 |
commit | 8933d30c5f468d6cc1e4bf9bb535149da35f202e (patch) | |
tree | 0051a12cc0bdd454350cf7c9f8d7547720f8788d /README | |
parent | 2ba1aede6d4184a6fd95bef3eda9acb1f40e2221 (diff) | |
download | linux-stable-8933d30c5f468d6cc1e4bf9bb535149da35f202e.tar.gz linux-stable-8933d30c5f468d6cc1e4bf9bb535149da35f202e.tar.bz2 linux-stable-8933d30c5f468d6cc1e4bf9bb535149da35f202e.zip |
pwm: lpc18xx: Fix period handling
The calculation:
val = (u64)NSEC_PER_SEC * LPC18XX_PWM_TIMER_MAX;
do_div(val, lpc18xx_pwm->clk_rate);
lpc18xx_pwm->max_period_ns = val;
is bogus because with NSEC_PER_SEC = 1000000000,
LPC18XX_PWM_TIMER_MAX = 0xffffffff and clk_rate < NSEC_PER_SEC this
overflows the (on lpc18xx (i.e. ARM32) 32 bit wide) unsigned int
.max_period_ns. This results (dependant of the actual clk rate) in an
arbitrary limitation of the maximal period. E.g. for clkrate =
333333333 (Hz) we get max_period_ns = 9 instead of 12884901897.
So make .max_period_ns an u64 and pass period and duty as u64 to not
discard relevant digits. And also make use of mul_u64_u64_div_u64()
which prevents all overflows assuming clk_rate < NSEC_PER_SEC.
Fixes: 841e6f90bb78 ("pwm: NXP LPC18xx PWM/SCT driver")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
Diffstat (limited to 'README')
0 files changed, 0 insertions, 0 deletions