]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Fix mas_destroy_rebalance() rework
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 11 Dec 2020 02:31:43 +0000 (21:31 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 5 Jan 2021 17:33:38 +0000 (12:33 -0500)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index cddcc0eae552b026045a54388593376f12106eba..c9ff930e93dcad28e4ad71c411fbfafce9be5e00 100644 (file)
@@ -2490,8 +2490,7 @@ static inline int mas_rebalance(struct ma_state *mas, struct maple_big_node *b_n
        return mas_spanning_rebalance(mas, &mast, empty_count);
 }
 
-static inline void mas_destroy_rebalance(struct ma_state *mas,
-                                        unsigned char mas_end)
+static inline void mas_destroy_rebalance(struct ma_state *mas, unsigned char end)
 {
        enum maple_type mt = mte_node_type(mas->node);
        struct maple_node reuse, *newnode, *parent, *new_left, *left, *node;
@@ -2534,31 +2533,32 @@ static inline void mas_destroy_rebalance(struct ma_state *mas,
        memcpy(slots, l_slots + split + 1, sizeof(void *) * tmp);
        memcpy(pivs, l_pivs + split + 1, sizeof(unsigned long) * tmp);
        pivs[tmp] = l_mas.max;
-       memcpy(slots + tmp, ma_slots(node, mt), sizeof(void *) * mas_end);
-       memcpy(pivs + tmp, ma_pivots(node, mt), sizeof(unsigned long) * mas_end);
+       memcpy(slots + tmp, ma_slots(node, mt), sizeof(void *) * end);
+       memcpy(pivs + tmp, ma_pivots(node, mt), sizeof(unsigned long) * end);
 
        l_mas.max = l_pivs[split];
        mas->min = l_mas.max + 1;
        eparent = mt_mk_node(mte_parent(l_mas.node),
                             mas_parent_enum(&l_mas, l_mas.node));
        if (!mt_in_rcu(mas->tree)) {
-               tmp += mas_end - 1;
-               if (tmp < mt_pivots[mt])
+               unsigned char max_p = mt_pivots[mt];
+               unsigned char max_s = mt_slots[mt];
+
+               tmp += end;
+               if (tmp < max_p)
                        memset(pivs + tmp, 0,
-                             sizeof (unsigned long *) * (mt_pivots[mt] - tmp));
+                              sizeof(unsigned long *) * (max_p - tmp));
+
                if (tmp < mt_slots[mt])
-                       memset(slots + tmp, 0,
-                             sizeof (void *) * (mt_pivots[mt] - tmp));
+                       memset(slots + tmp, 0, sizeof(void *) * (max_s - tmp));
 
                memcpy(node, newnode, sizeof(struct maple_node));
                mte_set_pivot(eparent, mte_parent_slot(l_mas.node),
                              l_pivs[split]);
                // Remove data from l_pivs.
                tmp = split + 1;
-               memset(l_pivs + tmp, 0,
-                      sizeof(unsigned long) * (mt_pivots[mt] - tmp));
-               memset(l_slots + tmp, 0,
-                      sizeof(void *) * (mt_slots[mt] - tmp));
+               memset(l_pivs + tmp, 0, sizeof(unsigned long) * (max_p - tmp));
+               memset(l_slots + tmp, 0, sizeof(void *) * (max_s - tmp));
 
                goto done;
        }