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

Steven Rostedt <[email protected]>
Newsgroups dev.linux.lists.ksummit,org.kernel.vger.linux-kernel
Message-ID <[email protected]>
On Tue, 18 Nov 2025 11:22:27 -0800
Linus Torvalds <[email protected]> wrote:

> 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.

For the few places that do what that example shows, I may update them, as I
think it does make the code look better.

I do have several places that have something like this:

        struct ring_buffer_per_cpu *cpu_buffer __free(kfree) = NULL;
        struct ring_buffer_cpu_meta *meta;
        struct buffer_page *bpage;
        struct page *page;
        int ret;

        cpu_buffer = kzalloc_node(ALIGN(sizeof(*cpu_buffer), cache_line_size()),
                                  GFP_KERNEL, cpu_to_node(cpu));
        if (!cpu_buffer)
                return NULL;

Where the allocation happens right after the declaration. I think I did it
this way because the full line goes over 80 characters, and breaks up the
declaration.

        struct ring_buffer_per_cpu *cpu_buffer __free(kfree) = 
				kzalloc_node(ALIGN(sizeof(*cpu_buffer), cache_line_size()),
                                		  GFP_KERNEL, cpu_to_node(cpu));
        struct ring_buffer_cpu_meta *meta;
        struct buffer_page *bpage;
        struct page *page;
        int ret;

        if (!cpu_buffer)
                return NULL;

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? The "cpu_buffer" is declared right after the declaration,
but the space after the declaration also makes it easier to read than:

        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;


-- Steve
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.