Re: Clarifying confusion of our variable placement rules caused by cleanup.h

From: Linus Torvalds

Date: Tue Nov 18 2025 - 14:22:46 EST


On Tue, 18 Nov 2025 at 11:16, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> I've been doing the above, and was even going to recommend it to James. But
> if it is preferred to declare the __free() variables where they are
> allocated, I'd be much happier.

I'm not going to make some hard rule that "it's preferred", but I
think it's simpler and clearer, and I would not want to discourage it.

That said, I *do* want to discourage the rash of mindless conversions.
I do think th is is a situation where people should pick the more
readable version when writing code, *not* a "let's convert existing
code that isn't being otherwise modified" situation.

And your example of

> struct foo *var __free(kfree) = NULL;
>
> if (ret < 0)
> return -ERROR;
>
> [ several more error exits ]
>
> var = kmalloc(..);

is exactly where I do think that just moving the declaration down does
actually make code sufficiently better that it then outweighs the "now
you have the variable declarations in random places".

Because I really feel like the whole "__free(kfree) = NULL" thing
doesn't make sense on its own. It really only makes sense when paired
with the "kmalloc()". And _that_ is why they go together.

But again: I don't want to make this some kind of hard rule, and I
think it should be done judiciously and with taste, not some kind of
crazy conversion thing.

Linus