Commit:     430d275a399175c7c0673459738979287ec1fd22
Parent:     22e48eaf587d044ba311a73c6fe0d0deaa8fdb63
Author:     Peter Lund <[EMAIL PROTECTED]>
AuthorDate: Tue Oct 16 23:29:35 2007 -0700
Committer:  Linus Torvalds <[EMAIL PROTECTED]>
CommitDate: Wed Oct 17 08:42:56 2007 -0700

    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 
    "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
    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
    Signed-off-by: Peter Lund <[EMAIL PROTECTED]>
    Christoph Lameter <[EMAIL PROTECTED]>
    Cc: Christoph Hellwig <[EMAIL PROTECTED]>
    Cc: "Maciej W. Rozycki" <[EMAIL PROTECTED]>
    Cc: Pekka Enberg <[EMAIL PROTECTED]>
    Cc: Andreas Schwab <[EMAIL PROTECTED]>
    Cc: Nick Piggin <[EMAIL PROTECTED]>
    Cc: WU Fengguang <[EMAIL PROTECTED]>
    Signed-off-by: Andrew Morton <[EMAIL PROTECTED]>
    Signed-off-by: Linus Torvalds <[EMAIL PROTECTED]>
 lib/radix-tree.c |   14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/lib/radix-tree.c b/lib/radix-tree.c
index 53fd44d..48c250f 100644
--- a/lib/radix-tree.c
+++ b/lib/radix-tree.c
@@ -1049,12 +1049,14 @@ radix_tree_node_ctor(struct kmem_cache *cachep, void 
 static __init unsigned long __maxindex(unsigned int height)
-       unsigned int tmp = height * RADIX_TREE_MAP_SHIFT;
-       unsigned long index = (~0UL >> (RADIX_TREE_INDEX_BITS - tmp - 1)) >> 1;
-       if (tmp >= RADIX_TREE_INDEX_BITS)
-               index = ~0UL;
-       return index;
+       unsigned int width = height * RADIX_TREE_MAP_SHIFT;
+       int shift = RADIX_TREE_INDEX_BITS - width;
+       if (shift < 0)
+               return ~0UL;
+       if (shift >= BITS_PER_LONG)
+               return 0UL;
+       return ~0UL >> shift;
 static __init void radix_tree_init_maxindex(void)
To unsubscribe from this list: send the line "unsubscribe git-commits-head" in
the body of a message to [EMAIL PROTECTED]
More majordomo info at

Reply via email to