From b4e25e4da2421b5bc3982e5c7526d8226fc7cf6a Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Wed, 31 Jul 2019 13:12:10 -0400 Subject: [PATCH] maple_tree: Add check for mas_for_each loop. Also change the ams_start to reset min/max Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 11 ++++++++++- lib/test_maple_tree.c | 22 +++++++++++++++++++--- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index cc1b5b2b8081..050675c7ce28 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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; diff --git a/lib/test_maple_tree.c b/lib/test_maple_tree.c index 60e749d8403b..ea40c425fda0 100644 --- a/lib/test_maple_tree.c +++ b/lib/test_maple_tree.c @@ -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) { -- 2.50.1