]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Fix mas_find for a single entry, add test
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 1 Mar 2021 19:36:59 +0000 (14:36 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 1 Mar 2021 19:36:59 +0000 (14:36 -0500)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c
lib/test_maple_tree.c

index 70846dbeb796708d6bd46b832d40f2152919f584..40e3321a43f8f1312bc97b98b143f738c08c57e2 100644 (file)
@@ -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;
index 0f5548cd4bca97856c1f9c108d8bdeecf0dc6df4..315f546936690534f7e69746a2ad821088b760d1 100644 (file)
@@ -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