radix_tree: loop based on shift count, not height
authorMatthew Wilcox <[email protected]>
Thu, 17 Mar 2016 21:21:51 +0000 (14:21 -0700)
committerLinus Torvalds <[email protected]>
Thu, 17 Mar 2016 22:09:34 +0000 (15:09 -0700)
When we introduce entries that can cover multiple indices, we will need
to stop in __radix_tree_create based on the shift, not the height.
Split out for ease of bisect.

Signed-off-by: Matthew Wilcox <[email protected]>
Cc: Johannes Weiner <[email protected]>
Cc: Matthew Wilcox <[email protected]>
Cc: "Kirill A. Shutemov" <[email protected]>
Cc: Ross Zwisler <[email protected]>
Cc: Hugh Dickins <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
lib/radix-tree.c

index ff91792346f62b02b290cf40416ac3056d96d27c..9bb440f317c91a97ce0c0e678c8f5735bee8a9e1 100644 (file)
@@ -415,10 +415,10 @@ int __radix_tree_create(struct radix_tree_root *root, unsigned long index,
        slot = indirect_to_ptr(root->rnode);
 
        height = root->height;
-       shift = (height-1) * RADIX_TREE_MAP_SHIFT;
+       shift = height * RADIX_TREE_MAP_SHIFT;
 
        offset = 0;                     /* uninitialised var warning */
-       while (height > 0) {
+       while (shift > 0) {
                if (slot == NULL) {
                        /* Have to add a child node.  */
                        if (!(slot = radix_tree_node_alloc(root)))
@@ -436,11 +436,11 @@ int __radix_tree_create(struct radix_tree_root *root, unsigned long index,
                }
 
                /* Go a level down */
+               shift -= RADIX_TREE_MAP_SHIFT;
                offset = (index >> shift) & RADIX_TREE_MAP_MASK;
                node = slot;
                slot = node->slots[offset];
                slot = indirect_to_ptr(slot);
-               shift -= RADIX_TREE_MAP_SHIFT;
                height--;
        }