Re: Sparse not supporting kzalloc_obj() and friends
Ricardo Ribalda <[email protected]> Mon, 23 Feb 2026 18:20:53 +0100
| Newsgroups | org.kernel.vger.linux-sparse |
|---|---|
| Message-ID | <CANiDSCsn4gctPL5ms+hCHBwFyv7wAWPCKw6Jfrk2TjMS2tNrCA@mail.gmail.com> |
Hi Linus On Mon, 23 Feb 2026 at 17:36, Linus Torvalds <[email protected]> wrote: > > On Mon, 23 Feb 2026 at 08:19, Linus Torvalds > <[email protected]> wrote: > > > > Argh. The culprit is the use of __VA_OPT__, which apparently sparse > > never got taught. > > [...] > > Ho humm. I guess I should look at the sparse pre-processor code, > > unless somebody already implemented __VA_OPT__ somewhere? > > Actually, it looks like Al at least *looked* at doing __VA_OPT__ back > at the end of last year. In fact, just a couple of months ago I said > "I'm not sure it buys us much", but that was when I thought it was > just a standard versions of the gcc ## thing, and before I realized > how much more convenient it actually is to use. > > Al? You know the pre-process.c file a *lot* better than I do, even > ignoring the fact that it's been fifteen years since I touched it. And > you presumably already had some thoughts on doing __VA_OPT__? > > That said, I can also just make default_gfp() use ## after all. I > _had_ grepped for __VA_OPT__ in the kernel and decided "we already use > it", but clearly it's causing some issues. > > So instead of <linux/gfp.h> doing > > #define __default_gfp(a,...) a > #define default_gfp(...) __default_gfp(__VA_ARGS__ __VA_OPT__(,) GFP_KERNEL) > > which I think is fairly straightforward and the "natural" way to do > things, the kernel can just do > > #define __default_gfp(a,b,...) b > #define default_gfp(...) __default_gfp(,##__VA_ARGS__,GFP_KERNEL) > > instead, with a dummy empty argument to make the gcc ## trick work. > It's smaller and denser, so it's actually superior in that sense, even > if it feels a bit less natural than the __VA_OPT__ model. > > Ricardo, can you verify that that trick works for you? I tried both smatch and sparse and both work fine with your trick. I also tried to boot it with virtme... That also worked :) I will try to retrofit your hack into media-ci until it lands in rc. Thanks > > Al, comments? > > Linus -- Ricardo Ribalda