The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH 1/3] x86/tsc: Use div64_ul instead of do_div()
@ 2024-04-28 17:31 Jules Irenge
  2024-04-28 19:13 ` H. Peter Anvin
  0 siblings, 1 reply; 3+ messages in thread
From: Jules Irenge @ 2024-04-28 17:31 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_ul 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 5a69a49acc96..2da37f33dd17 100644
--- a/arch/x86/kernel/tsc.c
+++ b/arch/x86/kernel/tsc.c
@@ -484,7 +484,7 @@ static unsigned long pit_calibrate_tsc(u32 latch, unsigned long ms, int loopmin)
 
 	/* Calculate the PIT value */
 	delta = t2 - t1;
-	do_div(delta, ms);
+	div64_ul(delta, ms);
 	return delta;
 }
 
-- 
2.43.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2024-05-02 16:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-04-28 17:31 [PATCH 1/3] x86/tsc: Use div64_ul instead of do_div() Jules Irenge
2024-04-28 19:13 ` H. Peter Anvin
2024-05-02 16:30   ` David Laight

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox