From: Philipp Stanner <phasta@mailbox.org>
To: "Kaitao Cheng" <kaitao.cheng@linux.dev>,
"David Laight" <david.laight.linux@gmail.com>,
"Jani Nikula" <jani.nikula@linux.intel.com>,
"Christian König" <christian.koenig@amd.com>,
"David Hildenbrand" <david@kernel.org>,
"Nathan Chancellor" <nathan@kernel.org>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"Nicolas Schier" <nsc@kernel.org>
Cc: Christian Brauner <brauner@kernel.org>,
"Paul E . McKenney" <paulmck@kernel.org>,
David Howells <dhowells@redhat.com>,
Simona Vetter <simona.vetter@ffwll.ch>,
Neeraj Upadhyay <neeraj.upadhyay@kernel.org>,
Luca Ceresoli <luca.ceresoli@bootlin.com>,
Randy Dunlap <rdunlap@infradead.org>,
Kaitao Cheng <chengkaitao@kylinos.cn>,
Andrew Morton <akpm@linux-foundation.org>,
Philipp Stanner <phasta@kernel.org>,
Alex Williamson <alex@shazbot.org>,
David Matlack <dmatlack@google.com>,
Shuah Khan <skhan@linuxfoundation.org>,
"Joy H . J . Lee" <rkr0k0r@gmail.com>,
Peter Zijlstra <peterz@infradead.org>,
Ian Rogers <irogers@google.com>,
Namhyung Kim <namhyung@kernel.org>,
Swapnil Sapkal <swapnil.sapkal@amd.com>,
linux-kbuild@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 1/4] list: Add mutable iterator variants
Date: Fri, 31 Jul 2026 08:54:14 +0200 [thread overview]
Message-ID: <fa3d31c188640d013c8da2f3a1be32188926e4a5.camel@mailbox.org> (raw)
In-Reply-To: <20260730095041.35715-2-kaitao.cheng@linux.dev>
Hi,
On Thu, 2026-07-30 at 17:50 +0800, Kaitao Cheng wrote:
> From: Kaitao Cheng <chengkaitao@kylinos.cn>
>
> The list_for_each*_safe() helpers allow the current entry to be removed
> while iterating, but require callers to declare and pass a temporary
> cursor. Most callers never use that cursor directly, so exposing it adds
> boilerplate and leaks an implementation detail into each call site.
>
> Add *_mutable() variants for list and hlist iterators. These variants
> keep the temporary cursor in a uniquely named local variable inside the
> macro while preserving the removal-safe iteration semantics.
>
> Keep the existing *_safe() variants for callers that need to access or
> reset the temporary cursor, and update their documentation to clarify
> which interface to use.
>
> Signed-off-by: Kaitao Cheng <chengkaitao@kylinos.cn>
> ---
> include/linux/list.h | 180 +++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 175 insertions(+), 5 deletions(-)
>
> diff --git a/include/linux/list.h b/include/linux/list.h
> index 09d979976b3b..373b08b929d3 100644
> --- a/include/linux/list.h
> +++ b/include/linux/list.h
> @@ -765,26 +765,62 @@ static inline void list_splice_tail_init(struct list_head *list,
>
> /**
> * list_for_each_safe - iterate over a list safe against removal of list entry
> + * with a caller-provided temporary cursor
> * @pos: the &struct list_head to use as a loop cursor.
> * @n: another &struct list_head to use as temporary storage
> * @head: the head for your list.
> + *
> + * If the caller does not need to access the temporary cursor, use
> + * list_for_each_mutable() instead.
> */
> #define list_for_each_safe(pos, n, head) \
>
I as a reader would probably be confused by this. What temporary
cursor? pos? n?
I tend to agree with Andrew's comment, that we would have to wonder how
much of an improvement more functions to choose from are, when
considering the cost-benefit-ratio.
Sure the temporary variables are often not needed, but sometimes APIs
are (have to be) just like that. With spin_lock_irqsave() you're also
forced to carry an integer around that you yourself never need.
Philipp
next prev parent reply other threads:[~2026-07-31 6:54 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-30 9:50 [PATCH v4 0/4] Prepare mutable list iterators to cache cursor state Kaitao Cheng
2026-07-30 9:50 ` [PATCH v4 1/4] list: Add mutable iterator variants Kaitao Cheng
2026-07-31 6:54 ` Philipp Stanner [this message]
2026-08-07 0:39 ` Andy Shevchenko
2026-07-30 9:50 ` [PATCH v4 2/4] llist: " Kaitao Cheng
2026-07-30 9:50 ` [PATCH v4 3/4] tools/list: " Kaitao Cheng
2026-07-30 9:50 ` [PATCH v4 4/4] scripts/list: " Kaitao Cheng
2026-07-30 19:11 ` [PATCH v4 0/4] Prepare mutable list iterators to cache cursor state Andrew Morton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=fa3d31c188640d013c8da2f3a1be32188926e4a5.camel@mailbox.org \
--to=phasta@mailbox.org \
--cc=akpm@linux-foundation.org \
--cc=alex@shazbot.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=brauner@kernel.org \
--cc=chengkaitao@kylinos.cn \
--cc=christian.koenig@amd.com \
--cc=david.laight.linux@gmail.com \
--cc=david@kernel.org \
--cc=dhowells@redhat.com \
--cc=dmatlack@google.com \
--cc=irogers@google.com \
--cc=jani.nikula@linux.intel.com \
--cc=kaitao.cheng@linux.dev \
--cc=linux-kbuild@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luca.ceresoli@bootlin.com \
--cc=namhyung@kernel.org \
--cc=nathan@kernel.org \
--cc=neeraj.upadhyay@kernel.org \
--cc=nsc@kernel.org \
--cc=paulmck@kernel.org \
--cc=peterz@infradead.org \
--cc=phasta@kernel.org \
--cc=rdunlap@infradead.org \
--cc=rkr0k0r@gmail.com \
--cc=simona.vetter@ffwll.ch \
--cc=skhan@linuxfoundation.org \
--cc=swapnil.sapkal@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®