From bcadc3678460105e1402f5e3fa8ed68c07f48939 Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Thu, 7 Mar 2019 10:18:29 -0500 Subject: [PATCH] maple: Fix _mas_walk return & clean up ma_insert root expand logic Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 7229bc460be8..7a3970ea8cad 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1281,8 +1281,9 @@ static inline bool _mas_walk(struct ma_state *mas) { enum maple_type type; struct maple_node *next; - unsigned long pivot_cnt, pivot, max, min, i; - bool ret = true; + unsigned long pivot = 0; + unsigned long pivot_cnt, max, min, i; + bool ret = false; mas->node = mas_start(mas); min = mas->min; @@ -1294,12 +1295,11 @@ static inline bool _mas_walk(struct ma_state *mas) switch (type) { default: - pivot = 0; for (i = 0; i < pivot_cnt; i++) { pivot = _ma_get_pivot(mas->node, i, type); if (i != 0 && pivot == 0) { - ma_set_slot(mas, MAPLE_NODE_SLOTS); - return NULL; + i = MAPLE_NODE_SLOTS; + goto done; } if (mas->index <= pivot) { @@ -1312,13 +1312,16 @@ static inline bool _mas_walk(struct ma_state *mas) if ((i == pivot_cnt - 1) && (mas->index > pivot)) i++; - if (type < maple_range_16) // Leaf. + if (type < maple_range_16) { // Leaf. + ret = true; goto done; + } break; case maple_dense: // Linear node. i = mas->index - mas->min; + ret = true; goto done; break; } @@ -1344,18 +1347,19 @@ static inline void ma_insert(struct ma_state *mas, void *entry) mas->node = mas_start(mas); if (!xa_is_node(rcu_dereference(mas->tree->ma_root))) { - if (mas->last == 0) { - if (mas->node != NULL) - goto exists; - - if (((unsigned long) (entry) & 3) == 2) - ma_root_expand(mas, entry); - else - rcu_assign_pointer(mas->tree->ma_root, entry); - + if (mas->last != 0) { + ma_root_expand(mas, entry); return; } - ma_root_expand(mas, entry); + + if (mas->node != NULL) + goto exists; + + if (((unsigned long) (entry) & 3) == 2) + ma_root_expand(mas, entry); + else + rcu_assign_pointer(mas->tree->ma_root, entry); + return; } -- 2.50.1