Skip to content

Commit 32c44e1

Browse files
geo-starkUwe Kleine-König
authored andcommitted
pwm: meson: Use mul_u64_u64_div_u64() for frequency calculating
While calculating frequency for the given period u64 numbers are multiplied before division what can lead to overflow in theory so use secure mul_u64_u64_div_u64() which handles overflow correctly. Fixes: 329db10 ("pwm: meson: make full use of common clock framework") Suggested-by: Uwe Kleine-König <[email protected]> Signed-off-by: George Stark <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 3e55111 commit 32c44e1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/pwm/pwm-meson.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
176176

177177
dev_dbg(pwmchip_parent(chip), "fin_freq: %ld Hz\n", fin_freq);
178178

179-
cnt = div_u64(fin_freq * period, NSEC_PER_SEC);
179+
cnt = mul_u64_u64_div_u64(fin_freq, period, NSEC_PER_SEC);
180180
if (cnt > 0xffff) {
181181
dev_err(pwmchip_parent(chip), "unable to get period cnt\n");
182182
return -EINVAL;
@@ -191,7 +191,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm,
191191
channel->hi = 0;
192192
channel->lo = cnt;
193193
} else {
194-
duty_cnt = div_u64(fin_freq * duty, NSEC_PER_SEC);
194+
duty_cnt = mul_u64_u64_div_u64(fin_freq, duty, NSEC_PER_SEC);
195195

196196
dev_dbg(pwmchip_parent(chip), "duty=%llu duty_cnt=%u\n", duty, duty_cnt);
197197

0 commit comments

Comments
 (0)