[PATCH] x86: fix alignment determination in range_to_mtrr()

From: Jan Beulich
Date: Fri Jul 06 2012 - 10:06:57 EST


With the variable operated on being of "unsigned long" type, neither
ffs() nor fls() are suitable to use on them, as those truncate their
arguments to 32 bits. Using __ffs() and __fls() respectively at once
eliminates the need t subtract 1 from their results.

Additionally, with the alignment value subsequently used as a shift
count, it must be enforced to be less than BITS_PER_LONG (and on 64-bit
there's no need for it to be any smaller).

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

---
arch/x86/kernel/cpu/mtrr/cleanup.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

--- 3.5-rc5/arch/x86/kernel/cpu/mtrr/cleanup.c
+++ 3.5-rc5-x86-mtrr-cleanup-types/arch/x86/kernel/cpu/mtrr/cleanup.c
@@ -258,11 +258,11 @@ range_to_mtrr(unsigned int reg, unsigned

/* Compute the maximum size with which we can make a range: */
if (range_startk)
- max_align = ffs(range_startk) - 1;
+ max_align = __ffs(range_startk);
else
- max_align = 32;
+ max_align = BITS_PER_LONG - 1;

- align = fls(range_sizek) - 1;
+ align = __fls(range_sizek);
if (align > max_align)
align = max_align;




--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/