Skip to content

Commit 17f6bac

Browse files
Chuanhua LeiKAGA-KOKO
authored andcommitted
x86/tsc: Prevent result truncation on 32bit
Loops per jiffy is calculated by multiplying tsc_khz with 1e3 and then dividing it by HZ. Both tsc_khz and the temporary variable holding the multiplication result are of type unsigned long, so on 32bit the result is truncated to the lower 32bit. Use u64 as type for the temporary variable and cast tsc_khz to it before multiplying. [ tglx: Massaged changelog and removed pointless braces ] Fixes: cf7a63e ("x86/tsc: Calibrate tsc only once") Signed-off-by: Chuanhua Lei <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Cc: [email protected] Cc: "H. Peter Anvin" <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Len Brown <[email protected]> Cc: Pavel Tatashin <[email protected]> Cc: Rajvi Jingar <[email protected]> Cc: Dou Liyang <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 4331f4d commit 17f6bac

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/x86/kernel/tsc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1415,7 +1415,7 @@ static bool __init determine_cpu_tsc_frequencies(bool early)
14151415

14161416
static unsigned long __init get_loops_per_jiffy(void)
14171417
{
1418-
unsigned long lpj = tsc_khz * KHZ;
1418+
u64 lpj = (u64)tsc_khz * KHZ;
14191419

14201420
do_div(lpj, HZ);
14211421
return lpj;

0 commit comments

Comments
 (0)