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

From: Steven Rostedt

Date: Tue Nov 18 2025 - 14:16:55 EST


On Tue, 18 Nov 2025 10:38:20 -0800
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> wrote:

> struct x509_parse_context *ctx __free(kfree) = NULL;
> ... other code ...
> ctx = kzalloc(sizeof(struct x509_parse_context), GFP_KERNEL);
>
> where you have now split up the whole "this is allocated by kmalloc,
> and free'd by kfree" into two different sections that are not next to
> each other.

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 think the code could also be better optimized? I haven't run an objcopy to
confirm but now early exits do not require calling the __free() function on
NULL pointers.

Most of my code allocates near the top where I don't find this a problem,
but I do have a few places of:

struct foo *var __free(kfree) = NULL;

if (ret < 0)
return -ERROR;

[ several more error exits ]

var = kmalloc(..);

-- Steve