Commit 8a14f4d8 authored by Matthew Wilcox's avatar Matthew Wilcox Committed by Linus Torvalds

radix-tree: fix radix_tree_create for sibling entries

If the radix tree user attempted to insert a colliding entry with an
existing multiorder entry, then radix_tree_create() could encounter a
sibling entry when walking down the tree to look for a slot.  Use
radix_tree_descend() to fix the problem, and add a test-case to make
sure the problem doesn't come back in future.
Signed-off-by: default avatarMatthew Wilcox <willy@linux.intel.com>
Reviewed-by: default avatarRoss Zwisler <ross.zwisler@linux.intel.com>
Cc: Konstantin Khlebnikov <koct9i@gmail.com>
Cc: Kirill Shutemov <kirill.shutemov@linux.intel.com>
Cc: Jan Kara <jack@suse.com>
Cc: Neil Brown <neilb@suse.de>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 0fc9b8ca
...@@ -548,9 +548,9 @@ int __radix_tree_create(struct radix_tree_root *root, unsigned long index, ...@@ -548,9 +548,9 @@ int __radix_tree_create(struct radix_tree_root *root, unsigned long index,
/* Go a level down */ /* Go a level down */
height--; height--;
shift -= RADIX_TREE_MAP_SHIFT; shift -= RADIX_TREE_MAP_SHIFT;
offset = (index >> shift) & RADIX_TREE_MAP_MASK;
node = indirect_to_ptr(slot); node = indirect_to_ptr(slot);
slot = node->slots[offset]; offset = (index >> shift) & RADIX_TREE_MAP_MASK;
offset = radix_tree_descend(node, &slot, offset);
} }
#ifdef CONFIG_RADIX_TREE_MULTIORDER #ifdef CONFIG_RADIX_TREE_MULTIORDER
......
...@@ -135,6 +135,11 @@ static void multiorder_check(unsigned long index, int order) ...@@ -135,6 +135,11 @@ static void multiorder_check(unsigned long index, int order)
item_check_absent(&tree, i); item_check_absent(&tree, i);
for (i = max; i < 2*max; i++) for (i = max; i < 2*max; i++)
item_check_absent(&tree, i); item_check_absent(&tree, i);
for (i = min; i < max; i++) {
static void *entry = (void *)
(0xA0 | RADIX_TREE_EXCEPTIONAL_ENTRY);
assert(radix_tree_insert(&tree, i, entry) == -EEXIST);
}
assert(item_delete(&tree, index) != 0); assert(item_delete(&tree, index) != 0);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment