From: David Laight <david.laight.linux@gmail.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Kees Cook <kees@kernel.org>, linux-kernel@vger.kernel.org
Subject: Re: [GIT PULL] kmalloc_obj treewide refactor for v7.0-rc1
Date: Sun, 22 Feb 2026 10:38:59 +0000 [thread overview]
Message-ID: <20260222103859.3b884714@pumpkin> (raw)
In-Reply-To: <CAHk-=wjOeEk1oFekLvEx081ZROBm3oHTeWzOg8W5AFyErsC57A@mail.gmail.com>
On Sat, 21 Feb 2026 11:49:19 -0800
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?
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
next prev parent reply other threads:[~2026-02-22 10:39 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-21 9:18 [GIT PULL] kmalloc_obj treewide refactor for v7.0-rc1 Kees Cook
2026-02-21 19:49 ` Linus Torvalds
2026-02-21 20:16 ` Linus Torvalds
2026-02-21 22:33 ` Linus Torvalds
2026-02-21 22:43 ` Kees Cook
2026-02-21 23:01 ` Linus Torvalds
2026-02-21 23:19 ` Linus Torvalds
2026-02-21 23:19 ` Kees Cook
2026-02-22 1:08 ` Eric Biggers
2026-02-22 14:50 ` David Laight
2026-02-22 17:34 ` Kees Cook
2026-02-23 9:19 ` Geert Uytterhoeven
2026-02-21 22:37 ` Kees Cook
2026-02-21 22:43 ` Linus Torvalds
2026-02-21 22:46 ` Kees Cook
2026-02-22 4:52 ` Linus Torvalds
2026-02-22 7:05 ` Kees Cook
2026-02-22 10:44 ` Julia Lawall
2026-02-22 17:37 ` Kees Cook
2026-02-22 10:38 ` David Laight [this message]
2026-02-21 19:55 ` pr-tracker-bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260222103859.3b884714@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox