Re: [GIT PULL] kmalloc_obj treewide refactor for v7.0-rc1

Linus Torvalds
2026-02-22T04:53:14Z

On Sat, 21 Feb 2026 at 11:49, Linus Torvalds
<torvalds@linux-foundation.org> wrote:
>
> IOW, how about doing something like this:
>
> #define pick_first(a, ...) a
> #define GFP(...) pick_first(__VA_ARGS__ __VA_OPT__(,) GFP_KERNEL)
>
> #define kmalloc_obj(VAR_OR_TYPE, ...) \
> __alloc_objs(kmalloc, GFP(__VA_ARGS__), typeof(VAR_OR_TYPE), 1)
>
> and now you can just do
>
> a = kmalloc_obj(type);
>
> if you just want the default GFP_KERNEL?

So I decided to just do this now, because it's going to cause
unnecessary merge conflict pain if I do it at any other time.

Right now, those lines are all being modified anyway, so any merge
conflict pain is not going to be made worse if I tweak the end result
a bit more.

Yes, hopefully the "just before rc1" timing minimizes conflicts
anyway, but I still don't want to add more to it.

I'm not super-happy about it considering how the base patch caused
issues, but I tried to be rather careful and I did only the trivial
cases where I could then look at the resulting diffs (both with my
eyes and some scripts) and try to double-check them that way too.

I did the truly trivial cases with some simplistic sed scripts, and
some of the line-wrapping cases with an even uglier script.

I'm adding Julia, because for the line-wrapping case I first tried to
use coccinelle to do it, but spatch failed on me half-way with an
assertion failure in kernel/trace/trace_events_hist.c, which I
couldn't figure out.

My script was probably to blame, but it boiled down to basically just

-ALLOC(E, GFP_KERNEL)
+ALLOC(E)

(with the ALLOC pattern from Kees' script) but I'm really not very
good at coccinelle. And "not very good" is putting it lightly.

End result: I didn't convert everything, but I've done the big bulk of
it, and all the really low-hanging fruit.

There's a few hundred cases left of those alloc_obj(x, GFP_KERNEL)
that could just be cleaned up in favor of the default "no gpf flags"
case, but that's where I decided to stop both because my script kept
getting uglier, and the end result looked more and more like it would
want manual whitespace fixup anyway.

And yes, I verified the end result by not just building it, but also booting it.

So I've pushed out my stuff on top, even though I'm not exactly proud
of the timing of this thing. The whole conversion has been a disaster,
and earlier today I really was just going to revert it all, but I just
decided to instead bite the bullet and getting this all behind us.

On the rare "good news" front, I have to say that while I am now very
fed up with trying to look at the resulting patches, I *did* actually
enjoy seeing the cleanup for the first few hundred cases I looked at.
The code really does look better. It's just that it gets very old very
quickly when there's about 15k cases of them.

[ I'm also adding Eric just because he seemed to be looking at this
mess anyway, so on the core principle of "Tag, you're it", Eric now
gets more to look at if he's willing ]

Linus