Re: [PATCH] pwm: ipq: prevent potential 32-bit integer overflow in hi_div calculation
From: Surendra Singh
Date: Mon Sep 07 2026 - 06:36:06 EST
Hi Uwe,
Thanks for applying the patch!
I noticed this during code review while comparing how effective_div
was calculated vs hi_div in ipq_pwm_get_state().
It can trigger easily on hardware whenever long periods or low clock
frequencies are configured. Specifically, when (hi_dur * (pre_div +
1)) exceeds UINT_MAX (0xffffffff), 32-bit multiplication overflows
before assignment to the 64-bit hi_div variable, resulting in an
incorrect/truncated duty_cycle being reported via pwm_get_state() to
userspace.
Sending it for 7.2 / current cycle as a bug fix would be great.
Thanks,
Surendra Singh Chouhan
On Mon, 7 Sept 2026 at 15:21, Uwe Kleine-König <ukleinek@xxxxxxxxxx> wrote:
>
> Hello,
>
> On Fri, Jul 24, 2026 at 10:18:54AM +0530, kr494167@xxxxxxxxx wrote:
> > From: Surendra Singh Chouhan <kr494167@xxxxxxxxx>
> >
> > In ipq_pwm_get_state(), hi_div was calculated as:
> > hi_div = hi_dur * (pre_div + 1);
> >
> > hi_dur and (pre_div + 1) are both unsigned int (32-bit) values.
> > Evaluating their multiplication using 32-bit arithmetic before assigning to
> > the 64-bit u64 hi_div variable can overflow 32-bit unsigned math.
> >
> > While effective_div explicitly uses (u64)(pwm_div + 1) * (pre_div + 1) to
> > prevent overflow, hi_div was missing the (u64) cast.
> >
> > Fix this by casting hi_dur to (u64) before multiplication, matching the
> > precision used for effective_div.
> >
> > Fixes: c436e3e9c265 ("pwm: Driver for qualcomm ipq6018 pwm block")
> > Signed-off-by: Surendra Singh Chouhan <kr494167@xxxxxxxxx>
>
> Applied to
>
> https://git.kernel.org/pub/scm/linux/kernel/git/ukleinek/linux.git pwm/for-next
>
> . Did you find this issue by code review or does it trigger easily? If
> the latter you might be able to convince me to send this patch to Linus
> before 7.3.
>
> Best regards
> Uwe