From: Liam R. Howlett Date: Mon, 1 Mar 2021 19:36:59 +0000 (-0500) Subject: maple_tree: Fix mas_find for a single entry, add test X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=ad359a8dd84bee478b3bdc2263340d2ab44c901f;p=users%2Fjedix%2Flinux-maple.git maple_tree: Fix mas_find for a single entry, add test Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 70846dbeb796..40e3321a43f8 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -4214,7 +4214,7 @@ static inline int mas_dead_node(struct ma_state *mas, unsigned long index) { unsigned long range_max, range_min; - if (unlikely(!mas_searchable(mas))) + if (unlikely(!mas_searchable(mas) || mas_is_start(mas))) return 0; if (likely(!mte_dead_node(mas->node))) @@ -4580,7 +4580,13 @@ retry: static inline bool mas_search_cont(struct ma_state *mas, unsigned long index, unsigned long max, void *entry) { - if (index >= max) + if (index > max) + return false; + + if (mas_is_start(mas)) + return true; + + if (index == max) return false; if (!mas_searchable(mas)) @@ -4589,9 +4595,6 @@ static inline bool mas_search_cont(struct ma_state *mas, unsigned long index, if (mas_is_err(mas)) return false; - if (mas_is_start(mas)) - return true; - if (entry) return false; @@ -5413,21 +5416,20 @@ void *mas_find(struct ma_state *mas, unsigned long max) { void *entry = NULL; bool first = false; + unsigned long index = mas->index; - if (mas_is_start(mas)) + if (mas_is_start(mas) && (mas->index <= max)) first = true; retry: - while (mas_search_cont(mas, mas->index, max, entry)) { + while (mas_search_cont(mas, mas->index, max, entry)) entry = _mas_next(mas, max); - if (unlikely(mas_dead_node(mas, mas->index))) { - if (first) - mas->node = MAS_START; + if (unlikely(mas_dead_node(mas, index))) { + if (first) + mas->node = MAS_START; - goto retry; - } - first = false; + goto retry; } return entry; diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index 0f5548cd4bca..315f54693669 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -812,6 +812,12 @@ static noinline void check_find(struct maple_tree *mt) } mas_unlock(&mas); + mas_set(&mas, 1048576); + mas_lock(&mas); + entry = mas_find(&mas, 1048576); + mas_unlock(&mas); + MT_BUG_ON(mas.tree, entry == NULL); + /* Find last value. * 1. get the expected value, leveraging the existence of an end entry * 2. delete end entry