aboutsummaryrefslogtreecommitdiffstats
path: root/lib/radix-tree.c
diff options
context:
space:
mode:
authorPeter Lund <firefly@vax64.dk>2007-10-17 02:29:35 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-17 11:42:56 -0400
commit430d275a399175c7c0673459738979287ec1fd22 (patch)
treee38f1e8b69ba5cad535a14edec4d0ff213bbc477 /lib/radix-tree.c
parent22e48eaf587d044ba311a73c6fe0d0deaa8fdb63 (diff)
avoid negative (and full-width) shifts in radix-tree.c
Negative shifts are not allowed in C (the result is undefined). Same thing with full-width shifts. It works on most platforms but not on the VAX with gcc 4.0.1 (it results in an "operand reserved" fault). Shifting by more than the width of the value on the left is also not allowed. I think the extra '>> 1' tacked on at the end in the original code was an attempt to work around that. Getting rid of that is an extra feature of this patch. Here's the chapter and verse, taken from the final draft of the C99 standard ("6.5.7 Bitwise shift operators", paragraph 3): "The integer promotions are performed on each of the operands. The type of the result is that of the promoted left operand. If the value of the right operand is negative or is greater than or equal to the width of the promoted left operand, the behavior is undefined." Thank you to Jan-Benedict Glaw, Christoph Hellwig, Maciej Rozycki, Pekka Enberg, Andreas Schwab, and Christoph Lameter for review. Special thanks to Andreas for spotting that my fix only removed half the undefined behaviour. Signed-off-by: Peter Lund <firefly@vax64.dk> Christoph Lameter <clameter@sgi.com> Cc: Christoph Hellwig <hch@infradead.org> Cc: "Maciej W. Rozycki" <macro@linux-mips.org> Cc: Pekka Enberg <penberg@cs.helsinki.fi> Cc: Andreas Schwab <schwab@suse.de> Cc: Nick Piggin <nickpiggin@yahoo.com.au> Cc: WU Fengguang <wfg@mail.ustc.edu.cn> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'lib/radix-tree.c')
-rw-r--r--lib/radix-tree.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 53fd44d78716..48c250fe2233 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -1049,12 +1049,14 @@ radix_tree_node_ctor(struct kmem_cache *cachep, void *node)
1049 1049
1050static __init unsigned long __maxindex(unsigned int height) 1050static __init unsigned long __maxindex(unsigned int height)
1051{ 1051{
1052 unsigned int tmp = height * RADIX_TREE_MAP_SHIFT; 1052 unsigned int width = height * RADIX_TREE_MAP_SHIFT;
1053 unsigned long index = (~0UL >> (RADIX_TREE_INDEX_BITS - tmp - 1)) >> 1; 1053 int shift = RADIX_TREE_INDEX_BITS - width;
1054 1054
1055 if (tmp >= RADIX_TREE_INDEX_BITS) 1055 if (shift < 0)
1056 index = ~0UL; 1056 return ~0UL;
1057 return index; 1057 if (shift >= BITS_PER_LONG)
1058 return 0UL;
1059 return ~0UL >> shift;
1058} 1060}
1059 1061
1060static __init void radix_tree_init_maxindex(void) 1062static __init void radix_tree_init_maxindex(void)