Re: [PATCH 2/6] treewide: remove using list iterator after loop body as a ptr
From: Jakob Koschel <hidden>
Date: 2022-02-28 21:47:11
Also in:
alsa-devel, amd-gfx, dmaengine, dri-devel, intel-gfx, intel-wired-lan, kvm, linux-arch, linux-aspeed, linux-block, linux-cifs, linux-crypto, linux-f2fs-devel, linux-fsdevel, linux-iio, linux-media, linux-mediatek, linux-pm, linux-rdma, linux-scsi, linux-staging, linux-tegra, linux-usb, linux-wireless, lkml, netdev, nouveau
On 28. Feb 2022, at 21:10, Linus Torvalds [off-list ref] wrote:
On Mon, Feb 28, 2022 at 12:03 PM Linus Torvalds
[off-list ref] wrote:
quoted
Side note: we do need *some* way to do it.
Ooh.
This patch is a work of art.
And I mean that in the worst possible way.
We can do
typeof(pos) pos
in the 'for ()' loop, and never use __iter at all.
That means that inside the for-loop, we use a _different_ 'pos' than outside.
And then the compiler will not see some "might be uninitialized", but
the outer 'pos' *will* be uninitialized.
Unless, of course, the outer 'pos' had that pointless explicit initializer.
The goal of this is to get compiler warnings right? This would indeed be great.
Changing the list_for_each_entry() macro first will break all of those cases
(e.g. the ones using 'list_entry_is_head()).
I assumed it is better to fix those cases first and then have a simple
coccinelle script changing the macro + moving the iterator into the scope
of the macro.
Here - can somebody poke holes in this "work of art" patch?
With this you are no longer able to set the 'outer' pos within the list
iterator loop body or am I missing something? Like this it stays
uninitialized but you'll probably want to set it from within the loop.
You would then yet again need a variable with another name to use
after the loop.
I fail to see how this will make most of the changes in this
patch obsolete (if that was the intention).
Linus
<patch.diff>
- Jakob