Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

pwm: loongson: Fix u32 overflow in waveform calculation

mul_u64_u64_div_u64() returns an u64 that might be bigger than U32_MAX.
To properly handle this case it must not be directly assigned to an u32
value.

Use a wider type for duty and period to make the idiom:

duty = mul_u64_u64_div_u64(...)
if (duty > U32_MAX)
duty = U32_MAX;

actually work as intended.

Reported-by: Dan Carpenter <dan.carpenter@linaro.org>
Link: https://lore.kernel.org/r/44f3c764-8b65-49a9-b3ad-797e9fbb96f5@stanley.mountain
Fixes: 2b62c89448dd ("pwm: Add Loongson PWM controller support")
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@baylibre.com>
Reviewed-by: Binbin Zhou <zhoubinbin@loongson.cn>
Link: https://lore.kernel.org/r/20250412122124.1636152-2-u.kleine-koenig@baylibre.com
Signed-off-by: Uwe Kleine-König <ukleinek@kernel.org>

authored by

Uwe Kleine-König and committed by
Uwe Kleine-König
dcb882bd 29f1d5ca

+1 -1
+1 -1
drivers/pwm/pwm-loongson.c
··· 118 118 static int pwm_loongson_config(struct pwm_chip *chip, struct pwm_device *pwm, 119 119 u64 duty_ns, u64 period_ns) 120 120 { 121 - u32 duty, period; 121 + u64 duty, period; 122 122 struct pwm_loongson_ddata *ddata = to_pwm_loongson_ddata(chip); 123 123 124 124 /* duty = duty_ns * ddata->clk_rate / NSEC_PER_SEC */