Re: Sparse not supporting kzalloc_obj() and friends

Linus Torvalds <[email protected]> Mon, 23 Feb 2026 10:02:07 -0800
Newsgroups org.kernel.vger.linux-sparse
Message-ID <CAHk-=whii0ao=uEoNocj5H56cUa_xZ5v=Hrth3K1aN1uU3XsqA@mail.gmail.com>
On Mon, 23 Feb 2026 at 09:21, Ricardo Ribalda <[email protected]> wrote:
>
> I tried both smatch and sparse and both work fine with your trick.
>
> I also tried to boot it with virtme... That also worked :)

Ok, I'll commit it.

What I actually wanted to do originally was the much simpler

  #define default_gfp(...) (GFP_KERNEL,##__VA_ARGS__)

but sadly it causes an endless stream of

    error: left-hand operand of comma expression has no effect
[-Werror=unused-value]

and the tricks to avoid that make the "simple" trick anything but
simple. This would seem to work:

  static inline gfp_t __attribute__((unused)) GFP_DEFAULT(void)
  { return GFP_KERNEL; }
  #define default_gfp(...) (GFP_DEFAULT(),##__VA_ARGS__)

but at that point the existing __default_gfp() macro is simpler, I feel.

Oh well. That "has not effect" was very much the *point* of that
really simple comma operator trick, but I do understand why the
warning exists.

               Linus