From 49c31946279aeb1a20868a8f8dc93d620efe80bc Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Thu, 11 Sep 2025 10:06:16 -0400 Subject: [PATCH] spanning_leaf_init: make spanning leaf safe for all rebalances Getting the right side of the operations content from the slot means that the rebalance can pass the same wr_mas into this function to correctly set up the new leaf entries. Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 0b110e6ffe81..e7c746821672 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -2997,7 +2997,7 @@ static inline void append_node_cp(struct maple_copy *cp, cp->s_count++; } -static inline void spanning_leaf_init(struct maple_copy *cp, +static inline void rebalance_leaf_init(struct maple_copy *cp, struct ma_state *mas, struct ma_wr_state *l_wr_mas, struct ma_wr_state *r_wr_mas) { @@ -3005,9 +3005,9 @@ static inline void spanning_leaf_init(struct maple_copy *cp, /* Create entries to insert including split entries to left and right */ if (l_wr_mas->r_min < mas->index) { + end++; cp->slot[0] = l_wr_mas->content; cp->pivot[0] = mas->index - 1; - end++; if (l_wr_mas->content) cp->gap[0] = 0; else @@ -3022,7 +3022,7 @@ static inline void spanning_leaf_init(struct maple_copy *cp, if (r_wr_mas->r_max > mas->last) { end++; - cp->slot[end] = r_wr_mas->content; + cp->slot[end] = r_wr_mas->slots[r_wr_mas->offset_end]; cp->pivot[end] = r_wr_mas->r_max; if (r_wr_mas->content) cp->gap[end] = 0; @@ -3530,7 +3530,7 @@ static void mas_wr_spanning_rebalance(struct ma_state *mas, */ cp.height = 1; - spanning_leaf_init(&cp, mas, l_wr_mas, r_wr_mas); + rebalance_leaf_init(&cp, mas, l_wr_mas, r_wr_mas); do { spanning_data_calc(&cp, mas, l_wr_mas, r_wr_mas, &sib); spanning_split_src_setup(&cp, mas, l_wr_mas, r_wr_mas, &sib); -- 2.51.0