]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Fix off by one on mas_prev when going to previous node.
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Tue, 25 Feb 2020 16:18:51 +0000 (11:18 -0500)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Fri, 30 Oct 2020 19:01:16 +0000 (15:01 -0400)
mas_prev_nentry decrements the slot prior to checking for an entry, so
don't decrement the slot in mas_prev loop on new nodes.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
lib/maple_tree.c
lib/test_maple_tree.c

index a58caac4defa4e3449b1d5076cb9bf787894195e..12838071355a63f503128c1efdc2ce721ed448a1 100644 (file)
@@ -3207,7 +3207,7 @@ static inline void* _mas_prev(struct ma_state *mas, unsigned long limit)
                        break;
 
                mas_prev_node(mas, limit);
-               mas_set_slot(mas, mt_slot_count(mas->node) - 1);
+               mas_set_slot(mas, mt_slot_count(mas->node));
        }
 
        if (mas_is_none(mas))
index 0477191b93c57d05829caddd2b45910a73d59232..7e86303c403f39e3745ab690722aff9dd6b32119 100644 (file)
@@ -11671,10 +11671,18 @@ static noinline void check_next_entry(struct maple_tree *mt)
 
 static noinline void check_prev_entry(struct maple_tree *mt)
 {
-       MT_BUG_ON(mt, !mtree_empty(mt));
+       unsigned long index = 16;
+       void *value;
+       MA_STATE(mas, mt, index, index);
 
+       MT_BUG_ON(mt, !mtree_empty(mt));
        check_seq(mt, 30, false);
+
        rcu_read_lock();
+       value = mas_find(&mas, ULONG_MAX);
+       MT_BUG_ON(mt, value != xa_mk_value(index));
+       value = mas_prev(&mas, 0);
+       MT_BUG_ON(mt, value != xa_mk_value(index - 1));
        rcu_read_unlock();
        mtree_destroy(mt);
 
@@ -11834,7 +11842,7 @@ static int maple_tree_seed(void)
        mtree_destroy(&tree);
 
 
-       mtree_init(&tree, 0);
+       mtree_init(&tree, MAPLE_ALLOC_RANGE);
        check_prev_entry(&tree);
 
        mtree_init(&tree, 0);