Re: [PATCH 2/2] devres: Provide kmalloc_obj*-style API for devm_kmalloc
From: Linus Torvalds
Date: Thu Nov 12 2026 - 11:46:30 EST
On Thu, 12 Nov 2026 at 02:13, Alejandro Colomar
<alx+linux-hardening@xxxxxxxxxx> wrote:
>
> I suggest removing kmalloc_obj() entirely, and using kmalloc_objs()
> always, with a second argument of 1 when we want a single object. This
> would remove the risk of that typo.
>
> I also suggest having default arguments without variadic macros. The
> way to do that is using empty arguments. Linus complained that it hurts
> his eyes, but it really makes these macros much safer.
No to both. These are both "make the code worse to catch errors that
the compiler should have been able to catch anyway".
If you *really* want to catch them, make "gfp_t" be a 'struct'. That
way even compilers without things like the restricted types that
sparse has will catch at least that one.
I did that many many years (argh, decades - I'm old) ago to catch all
the 'pte_t' etc issues when rewriting the MM layer, and it works very
well.
It's going to be somewhat painful, but ti might be worth it. People
who only use GFP_xyz flags to pass them around wouldn't notice.
Linus