From: Liam R. Howlett Date: Thu, 10 Jan 2019 19:05:43 +0000 (-0500) Subject: maple_tree: Change ma_coalesce to return the number of slots removed. X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=f67fa28bef6485e2e82111d6883dfd34ffa586c3;p=users%2Fjedix%2Flinux-maple.git maple_tree: Change ma_coalesce to return the number of slots removed. 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 --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index f90fd7f5b025..e2586362caaa 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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: