Skip to content

Commit

Permalink
x86/mm/mtrr: Fix alignment determination in range_to_mtrr()
Browse files Browse the repository at this point in the history
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 to 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 <[email protected]>
Cc: Linus Torvalds <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Peter Zijlstra <[email protected]>
Cc: Yinghai Lu <[email protected]>
Link: http://lkml.kernel.org/r/[email protected]
Signed-off-by: Ingo Molnar <[email protected]>
  • Loading branch information
jbeulich authored and Ingo Molnar committed Jul 10, 2012
1 parent 954e482 commit 1ba9a29
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions arch/x86/kernel/cpu/mtrr/cleanup.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,11 @@ range_to_mtrr(unsigned int reg, unsigned long range_startk,

/* 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;

Expand Down

0 comments on commit 1ba9a29

Please sign in to comment.