]> git.baikalelectronics.ru Git - kernel.git/commit
pwm: mtk-disp: Fix overflow in period and duty calculation
authorJitao Shi <jitao.shi@mediatek.com>
Sun, 8 Aug 2021 13:24:32 +0000 (21:24 +0800)
committerThierry Reding <thierry.reding@gmail.com>
Thu, 2 Sep 2021 20:27:44 +0000 (22:27 +0200)
commitabb1956a9cd1c235ecf8c37612dfe87d0e30bea4
treeba043dde61cc93e9de83767f64334d26fcae5d2b
parent170d312f7f2307343c47e58594d5f2cbc75d4faa
pwm: mtk-disp: Fix overflow in period and duty calculation

Current calculation for period and high_width may have 64-bit overflow.
state->period and rate are u64. rate * state->period will overflow.

clk_div = div_u64(rate * state->period, NSEC_PER_SEC)
period = div64_u64(rate * state->period, div);
high_width = div64_u64(rate * state->duty_cycle, div);

This patch is to resolve it by using mul_u64_u64_div_u64().

Signed-off-by: Jitao Shi <jitao.shi@mediatek.com>
Signed-off-by: Thierry Reding <thierry.reding@gmail.com>
drivers/pwm/pwm-mtk-disp.c