Re: [PATCH v4 0/4] Prepare mutable list iterators to cache cursor state

From: Andrew Morton

Date: Thu Jul 30 2026 - 15:19:44 EST


On Thu, 30 Jul 2026 17:50:32 +0800 Kaitao Cheng <kaitao.cheng@xxxxxxxxx> wrote:

> The list_for_each*_safe() helpers are used when the loop body may remove
> the current entry. Their current interface, however, forces every caller
> to define a temporary cursor outside the macro and pass it in, even when
> the caller never uses that cursor directly. For most call sites this
> extra cursor is just boilerplate required by the macro implementation.
>
> This is awkward because the saved next pointer is an internal detail of
> the iteration. Callers that only remove or move the current entry do not
> need to spell it out.
>
> The _safe() suffix has also caused confusion. Christian Koenig pointed
> out that the name is easy to read as a thread-safe variant, especially
> for beginners, even though it only means that the iterator keeps enough
> state to tolerate removal of the current entry. He suggested _mutable()
> as a clearer description of what the loop permits.
>
> Add *_mutable() iterator variants for list, hlist and llist. The caller
> omits the temporary cursor and the macro creates a unique internal cursor
> with typeof(pos) and __UNIQUE_ID(). The existing *_safe() helpers remain
> available for compatibility.

I can't say I'm very motivated about this proposal, sorry.

It adds nearly 500 lines of tricky new macros.

It churns ancient interfaces which have more than 6,000 callsites. Are
maintainers to spend the next decade receiving "switch to *_mutable"
cleanups?

Unless I'm missing something here, my vote is to let it be and go do
more productive things.