mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-10-03 07:38:10 +00:00
pwm: meson: Use mul_u64_u64_div_u64() for frequency calculating
[ Upstream commit32c44e1fa9
] 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:329db102a2
("pwm: meson: make full use of common clock framework") Suggested-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: George Stark <gnstark@salutedevices.com> Link: https://lore.kernel.org/r/20240425171253.2752877-4-gnstark@salutedevices.com Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
parent
513202bfe4
commit
132fe6c1ee
1 changed files with 2 additions and 2 deletions
|
@ -175,7 +175,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;
|
||||
|
@ -190,7 +190,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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue