* [PATCH] clk: sunxi-ng: nkm: use div64_ul() for the rate divisions
@ 2026-11-18 16:22 Romain TISSERAND
0 siblings, 0 replies; only message in thread
From: Romain TISSERAND @ 2026-11-18 16:22 UTC (permalink / raw)
To: Chen-Yu Tsai, Jernej Skrabec, Samuel Holland
Cc: Stephen Boyd, Brian Masney, Jerome Brunet, Maxime Ripard,
Frank Oltmanns, linux-clk, linux-sunxi, linux-arm-kernel,
linux-kernel, sashiko-reviews
ccu_nkm_calc_rate() and ccu_nkm_calc_parent_rate() divide their 64-bit
products by an unsigned long (m, n * k) with do_div(), whose divisor is
32 bits: on 64-bit it would be truncated. The N, K and M factors keep
it far below 2^32, so the results do not change, but use div64_ul(),
which takes an unsigned long divisor, as coccinelle suggests. On 32-bit
it is the same do_div() as before.
Fixes: e9d9dae0d248 ("clk: sunxi-ng: nkm: avoid 32-bit overflow in rate calculations")
Reported-by: kernel test robot <lkp@intel.com>
Closes: https://lore.kernel.org/oe-kbuild-all/202611151822.QXTOs54d-lkp@intel.com/
Signed-off-by: Romain TISSERAND <romain.tisserand@gmail.com>
---
Notes:
- Follow-up to e9d9dae0d248 in sunxi/clk-for-7.5, for the coccinelle
report of the kernel test robot (do_div() with an unsigned long
divisor); squash it into that commit if you prefer.
- No functional change: m and n * k stay far below 2^32 for every NKM
clock, so do_div() never saw a truncated divisor.
- Testing: built with W=1 for arm (multi_v7_defconfig with the A31 and
A33 CCUs) and arm64 (defconfig), no warnings; on arm the divisions
still go through __do_div64 (no __aeabi_uldivmod). Not run on
hardware: the generated code for the rates the hardware uses is the
same division as before.
- Tool disclosure: prepared with Claude Opus 5.5 (Anthropic) as a coding
assistant, from the robot report; I reviewed and understand the change.
drivers/clk/sunxi-ng/ccu_nkm.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/drivers/clk/sunxi-ng/ccu_nkm.c b/drivers/clk/sunxi-ng/ccu_nkm.c
index e5a8f22d50f5..a11d51dd0f2a 100644
--- a/drivers/clk/sunxi-ng/ccu_nkm.c
+++ b/drivers/clk/sunxi-ng/ccu_nkm.c
@@ -35,9 +35,8 @@ static unsigned long ccu_nkm_calc_rate(unsigned long parent,
unsigned long n, unsigned long k,
unsigned long m)
{
- u64 rate = (u64)parent * n * k;
+ u64 rate = div64_ul((u64)parent * n * k, m);
- do_div(rate, m);
return min_t(u64, rate, ULONG_MAX);
}
@@ -45,9 +44,8 @@ static unsigned long ccu_nkm_calc_parent_rate(unsigned long rate,
unsigned long n, unsigned long k,
unsigned long m)
{
- u64 parent = (u64)rate * m;
+ u64 parent = div64_ul((u64)rate * m, n * k);
- do_div(parent, n * k);
return min_t(u64, parent, ULONG_MAX);
}
base-commit: 3f8438336a3b340ffbda9e89480630436423782d
--
2.43.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-18 16:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-18 16:22 [PATCH] clk: sunxi-ng: nkm: use div64_ul() for the rate divisions Romain TISSERAND
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®