mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@barebox.org>
Subject: [PATCH 6/8] clk: divider: use 64-bit division in _div_round_up and divider_get_val
Date: Mon, 31 Aug 2026 21:35:53 +0200	[thread overview]
Message-ID: <20260831193605.1474749-6-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20260831193605.1474749-1-a.fatoum@pengutronix.de>

From: Ahmad Fatoum <a.fatoum@barebox.org>

The parent_rate + rate - 1 addition in DIV_ROUND_UP can overflow on
32-bit platforms. Use DIV_ROUND_UP_ULL, as Linux does since commit
9556f9dad8f5 ("clk: divider: handle integer overflow when dividing
large clock rates").

Fixes: 7d664f98d1ba ("clk: clk-divider: divider calculation in clk_set_rate needs DIV_ROUND_UP")
Fixes: b75025a39c77 ("clk: divider: Fix best div calculation for power-of-two and table dividers")
Reported-by: Claude:opus-4.6
Signed-off-by: Ahmad Fatoum <a.fatoum@barebox.org>
---
 drivers/clk/clk-divider.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
index 62d63ef39c7e..97dc9679c91c 100644
--- a/drivers/clk/clk-divider.c
+++ b/drivers/clk/clk-divider.c
@@ -161,7 +161,7 @@ static int _div_round_up(const struct clk_div_table *table,
 			 unsigned long parent_rate, unsigned long rate,
 			 unsigned long flags)
 {
-	int div = DIV_ROUND_UP(parent_rate, rate);
+	int div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
 
 	if (flags & CLK_DIVIDER_POWER_OF_TWO)
 		div = __roundup_pow_of_two(div);
@@ -292,7 +292,7 @@ int divider_get_val(unsigned long rate, unsigned long parent_rate,
 {
 	unsigned int div, value;
 
-	div = DIV_ROUND_UP(parent_rate, rate);
+	div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
 
 	if (!_is_valid_div(table, div, flags))
 		return -EINVAL;
-- 
2.47.3




  parent reply	other threads:[~2026-08-31 19:37 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-31 19:35 [PATCH 1/8] clk: stm32f4: allow building under COMPILE_TEST and fix the build Ahmad Fatoum
2026-08-31 19:35 ` [PATCH 2/8] clk: at91: sam9x60-pll: " Ahmad Fatoum
2026-08-31 19:35 ` [PATCH 3/8] clk: composite: return ERR_PTR on registration failure Ahmad Fatoum
2026-08-31 19:35 ` [PATCH 4/8] clk: fixed-factor: use 64-bit arithmetic in recalc_rate Ahmad Fatoum
2026-08-31 19:35 ` [PATCH 5/8] clk: imx: pllv3: use 64-bit arithmetic in fractional PLL recalc_rate Ahmad Fatoum
2026-08-31 19:35 ` Ahmad Fatoum [this message]
2026-08-31 19:35 ` [PATCH 7/8] clk: divider: round up when searching for the best divider Ahmad Fatoum
2026-08-31 19:35 ` [PATCH 8/8] clk: divider: fix calculation of maximal parent rate for a given divider Ahmad Fatoum

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=20260831193605.1474749-6-a.fatoum@pengutronix.de \
    --to=a.fatoum@pengutronix.de \
    --cc=a.fatoum@barebox.org \
    --cc=barebox@lists.infradead.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