]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Change ma_coalesce to return the number of slots removed.
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Thu, 10 Jan 2019 19:05:43 +0000 (14:05 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 18:55:11 +0000 (14:55 -0400)
Set ma->node to the new node, so save the previous node before calling
the function.  Also fix an off-by-one error in ma_coalesce.

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

index f90fd7f5b0255c58bea66807f6974e7bf5ae13c9..e2586362caaa565645d345f0c5402509ba8c2030 100644 (file)
@@ -438,27 +438,28 @@ static void mas_update_limits(struct ma_state *ms, unsigned char slot)
 /* Private
  * Combine nulls with the same pivot value
  */
-static void *mas_coalesce(struct ma_state *mas)
+static int mas_coalesce(struct ma_state *mas)
 {
        struct maple_range_64 *src = &mt_to_node(mas->node)->mr64;
+       unsigned char s_slot, d_slot = 0;
        unsigned long last = mas->max;
        struct maple_range_64 *dst;
        struct maple_node *mn;
-       unsigned char s_slot, d_slot = 0;
 
        /* Allocate a new node */
        mas_node_cnt(mas, 1);
        if (mas_is_err(mas))
-               return NULL;
+               return 0;
 
        mn = ma_next_alloc(mas);
        dst = &mn->mr64;
+       mas->node = mt_mk_node(mn, maple_leaf_64);
 
-       for (s_slot = 0; s_slot < MAPLE_RANGE64_SLOTS - 1; s_slot++) {
-               if (last == src->pivot[s_slot])
-                       continue;
-
+       for (s_slot = 0; s_slot < MAPLE_RANGE64_SLOTS; s_slot++) {
                if (s_slot < MAPLE_RANGE64_SLOTS - 1) {
+                       if (last == src->pivot[s_slot])
+                               continue;
+
                        if (s_slot != 0 && src->pivot[s_slot] == 0)
                                break;
 
@@ -468,7 +469,7 @@ static void *mas_coalesce(struct ma_state *mas)
                RCU_INIT_POINTER(dst->slot[d_slot], src->slot[s_slot]);
                last = dst->pivot[d_slot++];
        }
-       return mn;
+       return s_slot - d_slot;
 }
 
 static void ma_adopt_children(struct maple_node *parent)
@@ -582,7 +583,6 @@ void *ma_insert(struct ma_state *mas, void *entry)
 {
        void *p_entry; // Previous entry.
        unsigned char slot = MAPLE_NODE_SLOTS;
-       struct maple_node *mn;
        bool leaf;
 
 
@@ -612,13 +612,11 @@ void *ma_insert(struct ma_state *mas, void *entry)
                }
        }
 
-       mn = mas_coalesce(mas);
+       p_entry = mas->node;
+       mas_coalesce(mas);
        if (mas_is_err(mas))
                goto error;
 
-       p_entry = mas->node;
-
-       mas->node = mt_mk_node(mn, maple_leaf_64);
        /* Do the insert */
        _ma_insert(mas, entry, slot);
        if (mas_is_err(mas))
@@ -685,7 +683,6 @@ int ma_erase(struct ma_state *mas)
        unsigned long piv_val;
        int cnt = -EINVAL;
        void *p_entry; // Previous entry.
-       struct maple_node *mn;
 
        if (slot == MAPLE_NODE_SLOTS)
                return cnt;
@@ -707,12 +704,10 @@ int ma_erase(struct ma_state *mas)
                mr64->pivot[slot] = piv_val;
                cnt++;
        }
-
-       mn = mas_coalesce(mas);
+       p_entry = mas->node;
+       mas_coalesce(mas);
        if (mas_is_err(mas))
                goto error;
-       p_entry = mas->node;
-       mas->node = mt_mk_node(mn, maple_leaf_64);
        mt_replace(mas, p_entry, leaf);
 
 error: