All of lore.kernel.org
 help / color / mirror / Atom feed
From: David Laight <david.laight.linux@gmail.com>
To: Jerome Brunet <jbrunet@baylibre.com>
Cc: Brian Masney <masneyb@kernel.org>,
	Carlo Caione <ccaione@baylibre.com>,
	Stephen Boyd <sboyd@kernel.org>,
	Brian Masney <bmasney+clk@redhat.com>,
	Jerome Brunet <jbrunet+clk@baylibre.com>,
	Brian Norris <computersforpeace@gmail.com>,
	Brian Norris <briannorris@chromium.org>,
	Sebastian Reichel <sebastian.reichel@collabora.com>,
	linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org,
	Stephen Boyd <sboyd@codeaurora.org>
Subject: Re: [PATCH 1/2] clk: divider: Fix the divisor for rates above 4.29 GHz
Date: Fri, 6 Nov 2026 18:00:29 +0000	[thread overview]
Message-ID: <20261106180029.05452269@pumpkin> (raw)
In-Reply-To: <179398031041.2573818.13317727784501684521.b4-reply@b4>

On Fri, 06 Nov 2026 16:51:50 +0100
Jerome Brunet <jbrunet@baylibre.com> wrote:

> On 2026-11-04 16:52:04-05:00, Brian Masney wrote:
> > > DIV_ROUND_UP_ULL() takes a 32-bit divisor, so on 64-bit platforms a
> > > requested rate above 4.29 GHz is truncated. A divider fed by a 5.94 GHz
> > > PLL then computes a divisor of 7, not 1, for 5.94 GHz.
> > > 
> > > Use DIV64_U64_ROUND_UP(), which takes a 64-bit divisor.
> > > 
> > > Fixes: 9556f9dad8f5 ("clk: divider: handle integer overflow when dividing large clock rates")
> > > Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
> > > Signed-off-by: Carlo Caione <ccaione@baylibre.com>  
> > 
> > Reviewed-by: Brian Masney <masneyb@kernel.org>
> > 
> > Since this is a core change to the framework, I'd also like to see what
> > Jerome thinks before we merge this.  
> 
> I've had not problem with the change initially but then the AI told me that
> it brings back the overflow problem fixed by 9556f9dad8f5.
> 
> At first I thought it was crazy because it would mean parent_rate + rate is
> more than 18 billion GHz ... BUT, a common way to ask for the maximum rate a
> clock supports is clk_round_rate(clk, ULONG_MAX). This could trigger the overflow
> and there are instance of this in the kernel right now.
> 
> A way to make the calculation without the overflow could be:
> parent_rate / rate + (parent_rate % rate ? 1 : 0)
> 

You just want:
	parent_rate ? (parent_rate - 1) / rate + 1 : 0
it is even likely here that you can assume parent_rate in non-zero.

David


  reply	other threads:[~2026-11-06 18:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-02 21:07 [PATCH 0/2] Fix clk-divider rates above 4.29 GHz on 64-bit Carlo Caione
2026-11-02 21:07 ` [PATCH 1/2] clk: divider: Fix the divisor for rates above 4.29 GHz Carlo Caione
2026-11-04 21:52   ` Brian Masney
2026-11-04 23:10     ` David Laight
2026-11-06 15:51     ` Jerome Brunet
2026-11-06 18:00       ` David Laight [this message]
2026-11-11 23:38         ` Sebastian Reichel
2026-11-02 21:07 ` [PATCH 2/2] clk: divider: test: Add tests " Carlo Caione
2026-11-04 21:52   ` Brian Masney

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=20261106180029.05452269@pumpkin \
    --to=david.laight.linux@gmail.com \
    --cc=bmasney+clk@redhat.com \
    --cc=briannorris@chromium.org \
    --cc=ccaione@baylibre.com \
    --cc=computersforpeace@gmail.com \
    --cc=jbrunet+clk@baylibre.com \
    --cc=jbrunet@baylibre.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=masneyb@kernel.org \
    --cc=sboyd@codeaurora.org \
    --cc=sboyd@kernel.org \
    --cc=sebastian.reichel@collabora.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.