From: Karl Mehltretter <kmehltretter@gmail.com>
To: "Uwe Kleine-König" <ukleinek@kernel.org>
Cc: Claudiu Beznea <claudiu.beznea@tuxon.dev>,
Nicolas Ferre <nicolas.ferre@microchip.com>,
Alexandre Belloni <alexandre.belloni@bootlin.com>,
linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] pwm: atmel: Fix prescaler for periods of 2^32 clock cycles or more
Date: Sat, 24 Oct 2026 09:16:37 +0200 [thread overview]
Message-ID: <atxaqNeZdj_-gAKM@gmail.com> (raw)
In-Reply-To: <atnHHaOwTkI78_tc@monoceros>
Hi Uwe,
On Thu, Oct 22, 2026 at 10:29:42AM +0100, Uwe Kleine-König wrote:
> >
> > if (shift > PWM_MAX_PRES) {
> > dev_err(pwmchip_parent(chip), "pres exceeds the maximum value\n");
>
> just above this code snippet there is:
>
> unsigned long long cycles = state->period;
>
> /* Calculate the period cycles and prescale value */
> cycles *= clkrate;
> do_div(cycles, NSEC_PER_SEC);
>
> there is another overflow happening here if state->period * clkrate
> doesn't fit into an u64. A complete fix converts that to:
>
> cycles = mul_u64_u64_div_u64(state->period, clkrate, NSEC_PER_SEC);
>
> which prevents an overflow if clkrate ≤ NSEC_PER_SEC.
> The latter can be asserted by checking that at probe time after calling
> clk_rate_exclusive_get().
>
> The options now are I apply your patch anyhow and the above can be
> addressed later, or you rework your patch to a complete fix. What is
> your preference?
>
Good point. I took a look at this and will send an improved patch soon.
Karl
prev parent reply other threads:[~2026-10-24 7:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-16 16:12 Karl Mehltretter
2026-10-22 8:29 ` Uwe Kleine-König
2026-10-24 7:16 ` Karl Mehltretter [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=atxaqNeZdj_-gAKM@gmail.com \
--to=kmehltretter@gmail.com \
--cc=alexandre.belloni@bootlin.com \
--cc=claudiu.beznea@tuxon.dev \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=nicolas.ferre@microchip.com \
--cc=ukleinek@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®