]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: Add check for mas_for_each loop.
authorLiam R. Howlett <Liam.Howlett@Oracle.com>
Wed, 31 Jul 2019 17:12:10 +0000 (13:12 -0400)
committerLiam R. Howlett <Liam.Howlett@Oracle.com>
Wed, 31 Jul 2019 17:12:10 +0000 (13:12 -0400)
Also change the ams_start to reset min/max

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

index cc1b5b2b80819f3e1850134cf11fa480ffdf5a81..050675c7ce28ae603a41c3f821a0f376cf7d7a8f 100644 (file)
@@ -177,6 +177,11 @@ static inline bool mas_is_start(struct ma_state *ms)
        return ms->node == MAS_START;
 }
 
+void mas_reset(struct ma_state *mas)
+{
+       mas->node = MAS_START;
+}
+
 static inline struct maple_node *mt_to_node(const struct maple_enode *entry)
 {
        return (struct maple_node *)((unsigned long)entry & ~127);
@@ -913,6 +918,7 @@ static inline struct maple_node *mas_node_cnt(struct ma_state *ms, int count)
 static inline struct maple_enode *mas_start(struct ma_state *mas)
 {
        if (mas->node == MAS_START) {
+               mas->min = 0;
                if (!xa_is_node(mas->tree->ma_root)) {
                        if (mas->index > 0)
                                return NULL;
@@ -920,7 +926,10 @@ static inline struct maple_enode *mas_start(struct ma_state *mas)
                        ma_set_slot(mas, MAPLE_NODE_SLOTS);
                        return NULL;
                } else {
-                       return mt_safe_root(mas->tree->ma_root);
+                       struct maple_enode *root = mt_safe_root(
+                                       mas->tree->ma_root);
+                       mas->max = mt_node_max(root);
+                       return root;
                }
        }
        return mas->node;
index 60e749d8403bb1c6bf3dab8617d84f360b7aca6c..ea40c425fda06e6251dbbccadab7a5118a29132c 100644 (file)
@@ -362,13 +362,13 @@ static noinline void check_mid_split(struct maple_tree *mt)
 
 static noinline void check_find(struct maple_tree *mt)
 {
-       unsigned long val = 1;
+       unsigned long val = 0;
        unsigned long count = 20;
        void *entry;
        MA_STATE(mas, mt, 0, 0);
 
        // Insert 0.
-       MT_BUG_ON(mt, mtree_insert_index(mt, 0, GFP_KERNEL));
+       MT_BUG_ON(mt, mtree_insert_index(mt, val++, GFP_KERNEL));
 
        for (int i = 0; i <= count; i++) {
                if (val != 64)
@@ -380,8 +380,10 @@ static noinline void check_find(struct maple_tree *mt)
                val <<= 2;
        }
 
-       mas.node = MAS_START;
        val = 0;
+       mas_reset(&mas);
+       mas.index = val;
+
        while ( (entry = mas_find(&mas, 268435456)) != NULL) {
                if (val != 64)
                        MT_BUG_ON(mt, xa_mk_value(val) != entry);
@@ -394,6 +396,20 @@ static noinline void check_find(struct maple_tree *mt)
                        val = 1;
        }
 
+       val = 0;
+       mas_reset(&mas);
+       mas.index = val;
+       mas_for_each(&mas, entry, ULONG_MAX) {
+               if (val != 64)
+                       MT_BUG_ON(mt, xa_mk_value(val) != entry);
+               else
+                       MT_BUG_ON(mt, entry != XA_ZERO_ENTRY);
+               val <<= 2;
+               // For zero check.
+               if (!val)
+                       val = 1;
+       }
+
 }
 static noinline void check_alloc_rev_range(struct maple_tree *mt)
 {