Fix an overflow in range_to_mtrr func
Quoted 28 lines · ----- [email protected] 写道:
Quoted 1 line · Zhenzhong Duan
When boot
x86_64kernel on sun G5+ with 4T mem, see an overflow inmtrr cleanup as below.
Quoted 2 lines
*BAD*gran_size: 2G chunk_size: 2G num_reg: 10 lose cover
RAM:
Quoted 6 lines
-18014398505283592M
This is because 1<<31 sign extended.
Use explicit type conversion to force a 64bit constant to fix it. Useful for mem larger than or equal to 4T.Review
Quoted 6 lines
Signed-off-by Zhenzhong Duan <[email protected]>---
arch/x86/kernel/cpu/mtrr/cleanup.c | 2 +-1 files changed, 1 insertions(+), 1 deletions(-)(quoted diff) +0
-0
b/arch/x86/kernel/cpu/mtrr/cleanup.carch/x86/kernel/cpu/mtrr/cleanup.c range_to_mtrr(unsigned int reg, unsigned long
Quoted 4 lines
index ac140c7..853a4c6 100644
arch/x86/kernel/cpu/mtrr/cleanup.c +0
-0@@ -266,7 +266,7 @@ range_to_mtrr(unsigned int reg, unsigned long
range_startk,Quoted 3 lines
arch/x86/kernel/cpu/mtrr/cleanup.c +0
-0if (align > max_align) align = max_align;
Quoted 14 lines
arch/x86/kernel/cpu/mtrr/cleanup.c range_to_mtrr(unsigned int reg, unsigned long · line 269
Quoted 2 lines
arch/x86/kernel/cpu/mtrr/cleanup.c +1
-1- sizek = 1 << align; + sizek = (unsigned long)1 << align;how about
sizek = 1UL << align;Quoted 6 lines
arch/x86/kernel/cpu/mtrr/cleanup.c +0
-1if (debug_print) { char start_factor = 'K', size_factor = 'K'; unsigned long start_base, size_base; --1.7.3
Yes, this looks more clean although same compiling result. Should i resend it?