Re: [GIT PULL] kmalloc_obj treewide refactor for v7.0-rc1
From: David Laight
Date: Sun Feb 22 2026 - 05:39:22 EST
On Sat, 21 Feb 2026 11:49:19 -0800
Linus Torvalds <torvalds@xxxxxxxxxxxxxxxxxxxx> 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?
One problem with the above is that is you write:
a = kmalloc_obj(type, GFP_KERNEL, x)
then the 'x' is just silently discarded.
I think you can do:
#define pick_first(a, ...) a
#define pick_only(a) a
#define GFP(...) pick_first(__VA_OPT__(pick_only(__VA_ARGS__),) GFP_KERNEL)
which generates a compile-time error if there are two (or more) arguments.
It is probably wrappable as:
#define default(dflt, ##__VA_ARGS__)
allowing:
#define GFP(...) default(GFP_KERNEL, ##__VA_ARGS__)
David