]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
maple_tree: fix mas_prev() and mas_find() state handling
authorLiam R. Howlett <Liam.Howlett@oracle.com>
Fri, 20 Jan 2023 16:26:07 +0000 (11:26 -0500)
committerLiam R. Howlett <Liam.Howlett@oracle.com>
Wed, 22 Mar 2023 16:04:24 +0000 (12:04 -0400)
When mas_prev() does not find anything, set the state to MAS_NONE.

Handle the MAS_NONE in mas_find() like a MAS_START.

Link: https://lkml.kernel.org/r/20230120162650.984577-7-Liam.Howlett@oracle.com
Cc: <Stable@vger.kernel.org>
Fixes: 54a611b60590 ("Maple Tree: add new data structure")
Signed-off-by: Liam R. Howlett <Liam.Howlett@oracle.com>
Reported-by: <syzbot+502859d610c661e56545@syzkaller.appspotmail.com>
lib/maple_tree.c

index 50604fecd476166977586042c48db8503a1626fd..fc3e22cff642b335124c047538961a00aa8ecf8e 100644 (file)
@@ -4850,7 +4850,7 @@ static inline void *mas_prev_entry(struct ma_state *mas, unsigned long min)
 
        if (mas->index < min) {
                mas->index = mas->last = min;
-               mas_pause(mas);
+               mas->node = MAS_NONE;
                return NULL;
        }
 retry:
@@ -5926,6 +5926,7 @@ void *mas_prev(struct ma_state *mas, unsigned long min)
        if (!mas->index) {
                /* Nothing comes before 0 */
                mas->last = 0;
+               mas->node = MAS_NONE;
                return NULL;
        }
 
@@ -6016,6 +6017,9 @@ void *mas_find(struct ma_state *mas, unsigned long max)
                mas->index = ++mas->last;
        }
 
+       if (unlikely(mas_is_none(mas)))
+               mas->node = MAS_START;
+
        if (unlikely(mas_is_start(mas))) {
                /* First run or continue */
                void *entry;