From: Liam R. Howlett Date: Fri, 4 Mar 2022 02:14:54 +0000 (-0500) Subject: maple_tree: Fix left max on rebalance X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=01a5e203cd7eedc48bcfc5c71d07ae924dfde8d8;p=users%2Fjedix%2Flinux-maple.git maple_tree: Fix left max on rebalance Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 221f1c5b6ef7..44403e5559cc 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2673,14 +2673,19 @@ static inline void mast_cp_to_nodes(struct maple_subtree_state *mast, struct maple_enode *left, struct maple_enode *middle, struct maple_enode *right, unsigned char split, unsigned char mid_split) { + bool new_lmax = true; + mast->l->node = mte_node_or_none(left); mast->m->node = mte_node_or_none(middle); mast->r->node = mte_node_or_none(right); mast->l->min = mast->orig_l->min; - mab_mas_cp(mast->bn, 0, split, mast->l, true); - if (split == mast->bn->b_end) + if (split == mast->bn->b_end) { mast->l->max = mast->orig_r->max; + new_lmax = false; + } + + mab_mas_cp(mast->bn, 0, split, mast->l, new_lmax); if (middle) { mab_mas_cp(mast->bn, 1 + split, mid_split, mast->m, true); @@ -3007,7 +3012,6 @@ static inline int mas_rebalance(struct ma_state *mas, if (mas_next_sibling(&r_mas)) { mas_mab_cp(&r_mas, 0, mt_slot_count(r_mas.node), b_node, b_end); r_mas.last = r_mas.index = r_mas.max; - } else { mas_prev_sibling(&l_mas); shift = mas_data_end(&l_mas) + 1; @@ -5447,9 +5451,9 @@ static inline void mte_destroy_walk(struct maple_enode *enode, static void mas_wr_store_setup(struct ma_wr_state *wr_mas) { if (!mas_is_start(wr_mas->mas)) { - if (mas_is_none(wr_mas->mas)) + if (mas_is_none(wr_mas->mas)) { mas_reset(wr_mas->mas); - else { + } else { wr_mas->r_max = wr_mas->mas->max; wr_mas->type = mte_node_type(wr_mas->mas->node); if (mas_is_span_wr(wr_mas))