diff options
| author | George Stark <[email protected]> | 2024-04-25 17:12:53 +0000 |
|---|---|---|
| committer | Uwe Kleine-König <[email protected]> | 2024-04-30 16:57:09 +0000 |
| commit | 32c44e1fa921aebf8a5ef9f778534a30aab39313 (patch) | |
| tree | fc2b9a15276f5798c800d624d147f58175c6fa24 /drivers/pwm/pwm-meson.c | |
| parent | pwm: meson: Add check for error from clk_round_rate() (diff) | |
| download | kernel-32c44e1fa921aebf8a5ef9f778534a30aab39313.tar.gz kernel-32c44e1fa921aebf8a5ef9f778534a30aab39313.zip | |
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: 329db102a26d ("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]>
Diffstat (limited to 'drivers/pwm/pwm-meson.c')
| -rw-r--r-- | drivers/pwm/pwm-meson.c | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 4a652d500dfc..b2f97dfb01bb 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -176,7 +176,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm, dev_dbg(pwmchip_parent(chip), "fin_freq: %ld Hz\n", fin_freq); - cnt = div_u64(fin_freq * period, NSEC_PER_SEC); + cnt = mul_u64_u64_div_u64(fin_freq, period, NSEC_PER_SEC); if (cnt > 0xffff) { dev_err(pwmchip_parent(chip), "unable to get period cnt\n"); return -EINVAL; @@ -191,7 +191,7 @@ static int meson_pwm_calc(struct pwm_chip *chip, struct pwm_device *pwm, channel->hi = 0; channel->lo = cnt; } else { - duty_cnt = div_u64(fin_freq * duty, NSEC_PER_SEC); + duty_cnt = mul_u64_u64_div_u64(fin_freq, duty, NSEC_PER_SEC); dev_dbg(pwmchip_parent(chip), "duty=%llu duty_cnt=%u\n", duty, duty_cnt); |
