From: Liam R. Howlett Date: Thu, 13 Aug 2020 16:29:42 +0000 (-0400) Subject: maple_tree: Fix mas_awalk gap issues X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=fa5eaf3a0b37ae1a61faa6fa9d97a1460bd58409;p=users%2Fjedix%2Flinux-maple.git maple_tree: Fix mas_awalk gap issues Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 06807be04e563..22a60dcfe0e94 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);