From bb77847927ad57a4ce204a02334eed3e00ab61aa Mon Sep 17 00:00:00 2001 From: "Liam R. Howlett" Date: Mon, 28 Sep 2020 15:25:50 -0400 Subject: [PATCH] maple_tree: Fix bug in mas_next_node and optimize _mas_next slightly Signed-off-by: Liam R. Howlett --- lib/maple_tree.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 6ab6a50dabfb..f1d9ae6b6f2a 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -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); } -- 2.50.1