]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Fix bug in mas_next_node and optimize _mas_next slightly
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Mon, 28 Sep 2020 19:25:50 +0000 (15:25 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:12:26 +0000 (15:12 -0400)
Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c

index 6ab6a50dabfbfffa72f15d2697d6ff5efb1bf327..f1d9ae6b6f2a13ac25f73f6518e0f33a10937a0a 100644 (file)
@@ -3254,6 +3254,8 @@ static inline unsigned long mas_next_node(struct ma_state *mas,
        start_piv = mas_safe_pivot(mas, offset);
 restart_next_node:
        level = 0;
+
+ascend_again:
        do {
                if (mte_is_root(mas->node))
                        goto no_entry;
@@ -3269,10 +3271,14 @@ restart_next_node:
                prev_piv = mas_safe_pivot(mas, offset);
                if (prev_piv > max)
                        goto no_entry;
-
        } while (prev_piv == mas->max);
 
-       ++offset;
+       if (++offset >= mt_slots[mt])
+               goto ascend_again;
+
+       if (!mas_slot(mas, slots, offset)) // beyond the end of data
+               goto ascend_again;
+
        pivot = mas_safe_pivot(mas, offset);
        // Descend, if necessary.
        while (level > 1) {
@@ -4165,11 +4171,10 @@ static inline void *_mas_next(struct ma_state *mas, unsigned long limit,
                mas_start(mas);
                entry = mas_range_load(mas, range_start, &range_max);
                mas->last = range_max;
+               if (entry)
+                       return entry;
        }
 
-       if (entry)
-               return entry;
-
        return __mas_next(mas, limit, range_start);
 }