Skip to content

Commit

Permalink
radix-tree: rewrite radix_tree_tag_clear
Browse files Browse the repository at this point in the history
Use the new multi-order support functions to rewrite
radix_tree_tag_clear()

Signed-off-by: Ross Zwisler <[email protected]>
Signed-off-by: Matthew Wilcox <[email protected]>
Cc: Konstantin Khlebnikov <[email protected]>
Cc: Kirill Shutemov <[email protected]>
Cc: Jan Kara <[email protected]>
Cc: Neil Brown <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Ross Zwisler authored and torvalds committed May 21, 2016
1 parent fb96990 commit 00f47b5
Showing 1 changed file with 20 additions and 24 deletions.
44 changes: 20 additions & 24 deletions lib/radix-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -768,52 +768,48 @@ EXPORT_SYMBOL(radix_tree_tag_set);
void *radix_tree_tag_clear(struct radix_tree_root *root,
unsigned long index, unsigned int tag)
{
struct radix_tree_node *node = NULL;
struct radix_tree_node *slot = NULL;
unsigned int height, shift;
struct radix_tree_node *node, *parent;
unsigned long maxindex;
unsigned int shift;
int uninitialized_var(offset);

height = root->height;
if (index > radix_tree_maxindex(height))
goto out;

shift = height * RADIX_TREE_MAP_SHIFT;
slot = root->rnode;
shift = radix_tree_load_root(root, &node, &maxindex);
if (index > maxindex)
return NULL;

while (shift) {
if (slot == NULL)
goto out;
if (!radix_tree_is_indirect_ptr(slot))
break;
slot = indirect_to_ptr(slot);
parent = NULL;

while (radix_tree_is_indirect_ptr(node)) {
shift -= RADIX_TREE_MAP_SHIFT;
offset = (index >> shift) & RADIX_TREE_MAP_MASK;
node = slot;
slot = slot->slots[offset];

parent = indirect_to_ptr(node);
offset = radix_tree_descend(parent, &node, offset);
}

if (slot == NULL)
if (node == NULL)
goto out;

while (node) {
if (!tag_get(node, tag, offset))
index >>= shift;

while (parent) {
if (!tag_get(parent, tag, offset))
goto out;
tag_clear(node, tag, offset);
if (any_tag_set(node, tag))
tag_clear(parent, tag, offset);
if (any_tag_set(parent, tag))
goto out;

index >>= RADIX_TREE_MAP_SHIFT;
offset = index & RADIX_TREE_MAP_MASK;
node = node->parent;
parent = parent->parent;
}

/* clear the root's tag bit */
if (root_tag_get(root, tag))
root_tag_clear(root, tag);

out:
return slot;
return node;
}
EXPORT_SYMBOL(radix_tree_tag_clear);

Expand Down

0 comments on commit 00f47b5

Please sign in to comment.