Re: Clarifying confusion of our variable placement rules caused by cleanup.h
From: Linus Torvalds
Date: Tue Nov 18 2025 - 15:23:20 EST
On Tue, 18 Nov 2025 at 11:55, Steven Rostedt <rostedt@xxxxxxxxxxx> wrote:
>
> Doesn't look nice. I wonder since its the first allocation, if doing:
>
> struct ring_buffer_cpu_meta *meta;
> struct buffer_page *bpage;
> struct page *page;
> int ret;
>
> struct ring_buffer_per_cpu *cpu_buffer __free(kfree) =
> kzalloc_node(ALIGN(sizeof(*cpu_buffer), cache_line_size()),
> GFP_KERNEL, cpu_to_node(cpu));
> if (!cpu_buffer)
> return NULL;
>
> Would be acceptable?
So no, I do not think this is something we want to do, because that
thing is just stupidly complicated and as such I think it *wants* to
be broken up into multiple pieces.
But this is also literally *why* I was talking up that automatic type
thing, because I think that together with a few helper macros, we
*can* make cases that would otherwise look like the above horror-show
actually work really nicely.
Now, I think that your crazy case that wants to do alignment etc may
never be a good example of this, but for the simpler case of "I just
want a normal allocation for this" a couple of helper macros would
make it quite nice.
Because in the simpler - and I suspect *much* more common - cases, you
could easily end up with something simpler like
auto cpu_buffer __free(kfree) = kmalloc_type(struct ring_buffer_per_cpu);
and at *that* point I think it's nice. But please - not your horror-show.
Because if you need three lines to make one allocation be legible,
just separate it out.
Linus