lkml.org 
[lkml]   [2007]   [Aug]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
SubjectRe: [PATCH] avoid negative shifts in radix-tree.c
On Mon, 27 Aug 2007, Christoph Hellwig wrote:

> The conceptual change looks fine to me, but the code looks a little odd,
> what about:
>
> static __init unsigned long __maxindex(unsigned int height)
> {
> unsigned int tmp = height * RADIX_TREE_MAP_SHIFT;
> int shift = RADIX_TREE_INDEX_BITS - tmp;
>
> if (shift < 0)
> return ~0UL;
> return ~0UL >> shift;
> }
>
> instead?

This patch has been successfully tested on actual hardware (VAXstation
4000/90). If nobody objects, I'll push it to Andrew.

Maciej

Signed-off-by: Maciej W. Rozycki <macro@linux-mips.org>

patch-vax-2.6.17-rc4-20070111-radix-maxindex-0
diff -up --recursive --new-file linux-vax-2.6.17-rc4-20070111.macro/lib/radix-tree.c linux-vax-2.6.17-rc4-20070111/lib/radix-tree.c
--- linux-vax-2.6.17-rc4-20070111.macro/lib/radix-tree.c 2006-10-31 19:05:50.000000000 +0000
+++ linux-vax-2.6.17-rc4-20070111/lib/radix-tree.c 2007-01-22 01:24:17.000000000 +0000
@@ -825,9 +825,11 @@ radix_tree_node_ctor(void *node, kmem_ca
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;
+ unsigned long index;

- if (tmp >= RADIX_TREE_INDEX_BITS)
+ if (tmp < RADIX_TREE_INDEX_BITS)
+ index = (~0UL >> (RADIX_TREE_INDEX_BITS - tmp - 1)) >> 1;
+ else
index = ~0UL;
return index;
}
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
\
 
 \ /
  Last update: 2007-08-29 13:41    [W:0.048 / U:1.168 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site