From: Liam R. Howlett Date: Fri, 11 Dec 2020 02:31:43 +0000 (-0500) Subject: maple_tree: Fix mas_destroy_rebalance() rework X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=376661d40ce9e1e80bed462b8428674196125a83;p=users%2Fjedix%2Flinux-maple.git maple_tree: Fix mas_destroy_rebalance() rework Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index cddcc0eae552..c9ff930e93dc 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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; }