Fix roundup_pow_of_two(1)
PATCH 1/1 Fix roundup_pow_of_two(1)
Fix roundup_pow_of_two(1)
1 is a power of two, therefore roundup_pow_of_two(1) should return 1. It does in case the argument is a variable but in case it's a constant it behaves wrong and returns 0. Probably nobody ever did it so this was never noticed.
---
commit 01ceeffac83011f0b5021013cc4abd1c4f291df5
tree 7da59df51617d7cebd55e4361019181645a17e10
parent ab35916f807eb4f2019a208e96cb0bddbb91dfc3
author Rolf Eike Beer <[email protected]> Thu, 17 May 2007 23:43:54 +0200 committer Rolf Eike Beer <[email protected]> Thu, 17 May 2007 23:43:54 +0200
include/linux/log2.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
include/linux/log2.h +1 -1
@@ -159,7 +159,7 @@ unsigned long __roundup_pow_of_two(unsigned long n)#define roundup_pow_of_two (n) \ ( \ __builtin_constant_p(n) ? ( \ - (n == 1) ? 0 : \ + (n == 1) ? 1 : \ (1UL << (ilog2((n) - 1) + 1)) \ ) : \ __roundup_pow_of_two(n) \
Quoted 5 lines · Rolf Eike Beer
Fix
roundup_pow_of_two(1)1 is a power of two, therefore
roundup_pow_of_two(1)should return 1. It does in case the argument is a variable but in case it's a constant it behaves wrong and returns 0. Probably nobody ever did it so this was never noticed.
I'm not getting the problem.
2^0 = 1
Quoted 17 lines
Signed-off-by Rolf Eike Beer <[email protected]>---
commit01ceeffac83011f0b5021013cc4abd1c4f291df5
tree7da59df51617d7cebd55e4361019181645a17e10
parentab35916f807eb4f2019a208e96cb0bddbb91dfc3
author Rolf Eike Beer <[email protected]> Thu, 17 May 2007 23:43:54 +0200 committer Rolf Eike Beer <[email protected]> Thu, 17 May 2007 23:43:54 +0200include/linux/log2.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)include/linux/log2.h +0
-0
include/linux/log2.h unsigned long __roundup_pow_of_two(unsigned long n) · line 165
Quoted 8 lines
include/linux/log2.h +1
-1@@ -159,7 +159,7 @@ unsigned long __roundup_pow_of_two(unsigned long n)#define roundup_pow_of_two (n) \ ( \ __builtin_constant_p(n) ? ( \ - (n == 1) ? 0 : \ + (n == 1) ? 1 : \ (1UL << (ilog2((n) - 1) + 1)) \ ) : \ __roundup_pow_of_two(n) \
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedQuoted 10 lines · Adrian Bunk
Quoted 6 lines · Rolf Eike Beer
Fix
roundup_pow_of_two(1)1 is a power of two, therefore
roundup_pow_of_two(1)should return 1. It does in case the argument is a variable but in case it's a constant it behaves wrong and returns 0. Probably nobody ever did it so this was never noticed.I'm not getting the problem.
2^0 = 1
Yes. But it returned 0 (not 1 << 0).
Eike
Quoted 9 lines · Rolf Eike Beer
Quoted 8 lines · Adrian Bunk
Quoted 6 lines · Rolf Eike Beer
Fix
roundup_pow_of_two(1)1 is a power of two, therefore
roundup_pow_of_two(1)should return 1. It does in case the argument is a variable but in case it's a constant it behaves wrong and returns 0. Probably nobody ever did it so this was never noticed.
Quoted 4 lines
Quoted 2 lines
I'm not getting the problem.
2^0 = 1Yes. But it returned 0 (not 1 << 0).
Sorry, I had a thinko and you are right.
Quoted 1 line
Eike
cu
Adrian
Signature · 4 lines
"Is there not promise of rain?" Ling Tan asked suddenly out
of the darkness. There had been need of rain for many days.
"Only a promise," Lao Er said.
Pearl S. Buck - Dragon SeedQuoted 5 lines · Adrian Bunk
Quoted 3 lines
1 is a power of two, therefore
roundup_pow_of_two(1)should return 1. It does in case the argument is a variable but in case it's a constant it behaves wrong and returns 0. Probably nobody ever did it so this was never noticed.I'm not getting the problem.
2^0 = 1
Adrian,
that's of course true, but unrelated to the patch in question :)
You simply want roundup_pow_of_two(1) to be 1, and not 0. That's what the patch does, and that's correct.
Signature · 1 line
Jiri Kosina