Skip to content

Commit dcb882b

Browse files
ukleinekUwe Kleine-König
authored andcommitted
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 <[email protected]> Link: https://lore.kernel.org/r/[email protected] Fixes: 2b62c89 ("pwm: Add Loongson PWM controller support") Signed-off-by: Uwe Kleine-König <[email protected]> Reviewed-by: Binbin Zhou <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Uwe Kleine-König <[email protected]>
1 parent 29f1d5c commit dcb882b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/pwm/pwm-loongson.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ static int pwm_loongson_enable(struct pwm_chip *chip, struct pwm_device *pwm)
118118
static int pwm_loongson_config(struct pwm_chip *chip, struct pwm_device *pwm,
119119
u64 duty_ns, u64 period_ns)
120120
{
121-
u32 duty, period;
121+
u64 duty, period;
122122
struct pwm_loongson_ddata *ddata = to_pwm_loongson_ddata(chip);
123123

124124
/* duty = duty_ns * ddata->clk_rate / NSEC_PER_SEC */

0 commit comments

Comments
 (0)