]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Rework mas_replace()
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Wed, 3 Feb 2021 14:35:43 +0000 (09:35 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Wed, 3 Feb 2021 16:24:57 +0000 (11:24 -0500)
Drop ma_set_slot() and mte_set_slot() in favour of just setting the slot
value in the parent.  This is the only function using those two
functions and they are not necessary.

Drop check for replacing the node with itself as that doesn't happen -
confirmed by running the test suite with a BUG_ON instead of the swap.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index eabe5c503f227ca526d3e0ac82849f85cdc96878..10de480cf6ec3215dae23ffa3bf4883edc4b482e 100644 (file)
@@ -726,46 +726,6 @@ static inline void *mas_root_locked(struct ma_state *mas)
        return mas->tree->ma_root;
 }
 
-/*
- * ma_set_slot() - Set a nodes rcu slot.
- * @mn - the maple node for the operation
- * @slot - the slot number to set
- * @type - the maple node type
- * @val - the value to store
- */
-static inline void ma_set_slot(struct maple_node *mn,
-               unsigned char slot, enum maple_type type, void *val)
-{
-       BUG_ON(slot >= mt_slots[type]);
-
-       switch (type) {
-       default:
-       case maple_range_64:
-       case maple_leaf_64:
-               rcu_assign_pointer(mn->mr64.slot[slot], val);
-               break;
-       case maple_arange_64:
-               rcu_assign_pointer(mn->ma64.slot[slot], val);
-               break;
-       case maple_dense:
-               rcu_assign_pointer(mn->slot[slot], val);
-               break;
-       }
-}
-
-/*
- * mte_set_slot() - Set an encoded nodes rcu slot.
- * @mn: The encoded maple node
- * @slot: The offset into the slots array
- * @val: The entry to store into the slot.
- */
-static inline void mte_set_slot(const struct maple_enode *mn,
-                                unsigned char slot, void *val)
-{
-       ma_set_slot(mte_to_node(mn), slot, mte_node_type(mn), val);
-}
-
-
 #define MA_META_END_MASK       0b1111
 #define MA_META_GAP_SHIFT      4
 /*
@@ -1515,28 +1475,23 @@ static inline void mas_adopt_children(struct ma_state *mas,
  * leave the node (true) and handle the adoption and free elsewhere.
  */
 static inline void mas_replace(struct ma_state *mas, bool advanced)
+       __must_hold(mas->tree->lock)
 {
-       struct maple_node *parent, *mn = mas_mn(mas);
-       struct maple_enode *prev, *eparent = NULL;
+       struct maple_node *mn = mas_mn(mas);
+       struct maple_enode *old_enode;
        unsigned char offset = 0;
-       void **slots;
+       void **slots = NULL;
 
 
        if (mte_is_root(mas->node)) {
-               prev = mas_root_locked(mas);
+               old_enode = mas_root_locked(mas);
        } else {
-               enum maple_type ptype = mas_parent_enum(mas, mas->node);
-
-               parent = mte_parent(mas->node);
-               eparent = mt_mk_node(parent, ptype);
                offset = mte_parent_slot(mas->node);
-               slots = ma_slots(parent, ptype);
-               prev = slots[offset];
+               slots = ma_slots(mte_parent(mas->node),
+                                mas_parent_enum(mas, mas->node));
+               old_enode = slots[offset];
        }
 
-       if (mte_to_node(prev) == mn)
-               return;
-
        if (!advanced && !mte_is_leaf(mas->node))
                mas_adopt_children(mas, mas->node);
 
@@ -1546,11 +1501,11 @@ static inline void mas_replace(struct ma_state *mas, bool advanced)
                rcu_assign_pointer(mas->tree->ma_root, mte_mk_root(mas->node));
                mas_set_height(mas);
        } else {
-               mte_set_slot(eparent, offset, mas->node);
+               rcu_assign_pointer(slots[offset], mas->node);
        }
 
        if (!advanced)
-               mas_free(mas, prev);
+               mas_free(mas, old_enode);
 }
 
 /*