Skip to contentSkip to conversation

x86/tsc: Use div64_64 instead of do_div()

PATCH In review Jules Irenge 1 participant 1 message Apr 28, 2024 x86

lore
Share & tools
lore
#0 lore raw

PATCH 3/3 x86/tsc: Use div64_64 instead of do_div()

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

---
 arch/x86/kernel/tsc.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/x86/kernel/tsc.c +1 -1
index 2ed154a2642c..9106069f18b2 100644
@@ -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;
 }
Signature · 1 line
2.43.2