All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 3/3] x86/tsc: Use div64_64 instead of do_div()
@ 2024-04-28 17:32 Jules Irenge
  0 siblings, 0 replies; only message in thread
From: Jules Irenge @ 2024-04-28 17:32 UTC (permalink / raw)
  To: mingo; +Cc: tglx, bp, x86, hpa, peterz, rdunlap, linux-kernel

do_div() truncates a u64 divisor to 32 bit.
This can lead to non-zero being truncated to zero for division.

Fix coccinelle warning
WARNING: do_div() does a 64-by-32 division, please consider using div64_64 instead

Signed-off-by: Jules Irenge <jbi.octave@gmail.com>
---
 arch/x86/kernel/tsc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
index 2ed154a2642c..9106069f18b2 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -401,7 +401,7 @@ static unsigned long calc_pmtimer_ref(u64 deltatsc, u64 pm1, u64 pm2)
 	pm2 -= pm1;
 	tmp = pm2 * 1000000000LL;
 	do_div(tmp, PMTMR_TICKS_PER_SEC);
-	do_div(deltatsc, tmp);
+	div64_u64(deltatsc, tmp);
 
 	return (unsigned long) deltatsc;
 }
-- 
2.43.2


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2024-04-28 17:33 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-28 17:32 [PATCH 3/3] x86/tsc: Use div64_64 instead of do_div() Jules Irenge

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.