From 365a0eadafd8034164cdf0bb34944d487e6cae34 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Thu, 13 Aug 2020 12:29:42 -0400 Subject: [PATCH] maple_tree: Fix mas_awalk gap issues Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 21 ++++++--------------- 1 file changed, 6 insertions(+), 15 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 06807be04e56..22a60dcfe0e9 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3621,7 +3621,7 @@ ascend: static inline bool _mas_awalk(struct ma_state *mas, unsigned long size) { enum maple_type type = mte_node_type(mas->node); - unsigned long pivot, min, gap; + unsigned long pivot, min, gap = 0; unsigned char slot = 0, pivot_cnt = mt_pivots[type]; bool found = false; @@ -3641,23 +3641,15 @@ static inline bool _mas_awalk(struct ma_state *mas, unsigned long size) goto next_slot; if (ma_is_leaf(type)) { - if (!mt_is_empty(mas_get_rcu_slot(mas, slot))) - goto next_slot; - - gap = pivot - mas->index; - if (!gap) // No entry, pivot = index. - gap = 1; - - if (mas->last + size < pivot - gap) { // upper bound - mas_set_err(mas, -EBUSY); - return true; - } - if (mas->last < pivot - gap) // gap check - break; + gap = 0; + if (mt_is_empty(mas_get_rcu_slot(mas, slot))) + gap = min(pivot, mas->last) - + max(mas->index, min) + 1; } else { gap = mte_get_gap(mas->node, slot); } +next_slot: if (gap >= size) { if (ma_is_leaf(type)) { found = true; @@ -3670,7 +3662,6 @@ static inline bool _mas_awalk(struct ma_state *mas, unsigned long size) break; } } -next_slot: min = pivot + 1; if (mas->last < min) { mas_set_err(mas, -EBUSY); -- 2.50.1