diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-12-13 01:06:55 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-12-13 01:06:55 -0500 |
commit | 13c07b0286d340275f2d97adf085cecda37ede37 (patch) | |
tree | 1171b73c8261ddc0c47817f765c470260c8d2699 /include | |
parent | 12870da5c3ace563902babdfa10d824fdbd4ce88 (diff) |
linux/log2.h: Fix rounddown_pow_of_two(1)
Exactly like roundup_pow_of_two(1), the rounddown version was buggy for
the case of a compile-time constant '1' argument. Probably because it
originated from the same code, sharing history with the roundup version
from before the bugfix (for that one, see commit 1a06a52ee1b0: "Fix
roundup_pow_of_two(1)").
However, unlike the roundup version, the fix for rounddown is to just
remove the broken special case entirely. It's simply not needed - the
generic code
1UL << ilog2(n)
does the right thing for the constant '1' argment too. The only reason
roundup needed that special case was because rounding up does so by
subtracting one from the argument (and then adding one to the result)
causing the obvious problems with "ilog2(0)".
But rounddown doesn't do any of that, since ilog2() naturally truncates
(ie "rounds down") to the right rounded down value. And without the
ilog2(0) case, there's no reason for the special case that had the wrong
value.
tl;dr: rounddown_pow_of_two(1) should be 1, not 0.
Acked-by: Dmitry Torokhov <dtor@vmware.com>
Cc: stable@kernel.org
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'include')
-rw-r--r-- | include/linux/log2.h | 1 |
1 files changed, 0 insertions, 1 deletions
diff --git a/include/linux/log2.h b/include/linux/log2.h index 25b808631cd9..fd7ff3d91e6a 100644 --- a/include/linux/log2.h +++ b/include/linux/log2.h | |||
@@ -185,7 +185,6 @@ unsigned long __rounddown_pow_of_two(unsigned long n) | |||
185 | #define rounddown_pow_of_two(n) \ | 185 | #define rounddown_pow_of_two(n) \ |
186 | ( \ | 186 | ( \ |
187 | __builtin_constant_p(n) ? ( \ | 187 | __builtin_constant_p(n) ? ( \ |
188 | (n == 1) ? 0 : \ | ||
189 | (1UL << ilog2(n))) : \ | 188 | (1UL << ilog2(n))) : \ |
190 | __rounddown_pow_of_two(n) \ | 189 | __rounddown_pow_of_two(n) \ |
191 | ) | 190 | ) |