From: Liam R. Howlett Date: Mon, 3 Apr 2023 15:59:40 +0000 (-0400) Subject: maple_tree: Clear up index and last setting in single entry tree X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=a7b78016c765d8825232524200a3c2ee928bf667;p=users%2Fjedix%2Flinux-maple.git maple_tree: Clear up index and last setting in single entry tree When there is a single entry tree (range of 0-0 pointing to an entry), then ensure the limit is either 0-0 or 1-oo, depending on where the user walks. Ensure the correct node setting as well; either MAS_ROOT or MAS_NONE. Signed-off-by: Liam R. Howlett --- diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 7bf7446a6250..8c98d1ab8744 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -5099,24 +5099,25 @@ void *mas_walk(struct ma_state *mas) { void *entry; + if (mas_is_none(mas) || mas_is_paused(mas)) + mas->node = MAS_START; retry: entry = mas_state_walk(mas); - if (mas_is_start(mas)) + if (mas_is_start(mas)) { goto retry; - - if (mas_is_ptr(mas)) { + } else if (mas_is_none(mas)) { + mas->index = 0; + mas->last = ULONG_MAX; + } else if (mas_is_ptr(mas)) { if (!mas->index) { mas->last = 0; - } else { - mas->index = 1; - mas->last = ULONG_MAX; + return mas_root(mas); } - return entry; - } - if (mas_is_none(mas)) { - mas->index = 0; + mas->index = 1; mas->last = ULONG_MAX; + mas->node = MAS_NONE; + return NULL; } return entry;