maple_tree: add helper mas_make_walkable()
authorLiam R. Howlett (Oracle) <liam@infradead.org>
Fri, 21 Aug 2026 19:26:27 +0000 (15:26 -0400)
committerAndrew Morton <akpm@linux-foundation.org>
Tue, 25 Aug 2026 01:43:32 +0000 (18:43 -0700)
A check in mas_walk() was incorrect and caused inefficient use of the
maple state.  The same issue existed in mas_erase(), but was left unfixed.
Making a helper function is the obvious answer.

Link: https://lore.kernel.org/20260821192627.4085470-20-liam@infradead.org
Signed-off-by: Liam R. Howlett (Oracle) <liam@infradead.org>
Cc: Boqun Feng <boqun.feng@gmail.com>
Cc: Breno Leitao <leitao@debian.org>
Cc: Chris Mason <clm@meta.com>
Cc: Chuck Lever <cel@kernel.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Joe Perches <joe@perches.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rik van Riel <riel@surriel.com>
Cc: Waiman Long <longman@redhat.com>
Cc: Will Deacon <will@kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
lib/maple_tree.c

index b43e2ce..1aba6cc 100644 (file)
@@ -261,6 +261,12 @@ static inline bool mas_is_underflow(struct ma_state *mas)
        return mas->status == ma_underflow;
 }
 
+static inline void mas_make_walkable(struct ma_state *mas)
+{
+       if (!mas_is_active(mas) && !mas_is_start(mas))
+               mas->status = ma_start;
+}
+
 static __always_inline struct maple_node *mte_to_node(
                const struct maple_enode *entry)
 {
@@ -4447,8 +4453,7 @@ void *mas_walk(struct ma_state *mas)
        void *entry;
 
        mas_may_init_lock_check(mas);
-       if (!mas_is_active(mas) && !mas_is_start(mas))
-               mas->status = ma_start;
+       mas_make_walkable(mas);
 retry:
        entry = mas_state_walk(mas);
        if (mas_is_start(mas)) {
@@ -5685,9 +5690,7 @@ void *mas_erase(struct ma_state *mas)
        if (mt_external_lock(mas->tree))
                might_alloc(GFP_KERNEL);
 
-       if (!mas_is_active(mas) || !mas_is_start(mas))
-               mas->status = ma_start;
-
+       mas_make_walkable(mas);
 write_retry:
        entry = mas_state_walk(mas);
        if (!entry)