From: Alejandro Colomar <alx+linux-hardening@kernel.org>
To: Linus Torvalds <torvalds@linuxfoundation.org>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Kees Cook <kees@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
"Rafael J. Wysocki" <rafael@kernel.org>,
Danilo Krummrich <dakr@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
driver-core@lists.linux.dev, linux-hardening@vger.kernel.org,
Lorenzo Stoakes <ljs@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>,
Vlastimil Babka <vbabka@kernel.org>,
Suren Baghdasaryan <surenb@google.com>,
Michal Hocko <mhocko@suse.com>,
Brendan Jackman <brendan.jackman@linux.dev>,
Johannes Weiner <hannes@cmpxchg.org>, Zi Yan <ziy@nvidia.com>,
David Hildenbrand <david@kernel.org>,
"Liam R. Howlett" <liam@infradead.org>,
Mike Rapoport <rppt@kernel.org>,
linux-kernel@vger.kernel.org, linux-mm@kvack.org,
Geert Uytterhoeven <geert@linux-m68k.org>
Subject: Re: [PATCH 2/2] devres: Provide kmalloc_obj*-style API for devm_kmalloc
Date: Thu, 12 Nov 2026 18:32:54 +0100 [thread overview]
Message-ID: <avX3Y08tF8Z0C4LH@devuan> (raw)
In-Reply-To: <CAHk-=wgYBrhvo2NAG_Ja-0ovPf=xO20Gcopv9Yrr1u=QVxECZw@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 1788 bytes --]
Hi Linus,
> Date: 2026-11-12 08:34:13-0800
> From: Linus Torvalds <torvalds@linuxfoundation.org>
>
> On Thu, 12 Nov 2026 at 02:13, Alejandro Colomar
> <alx+linux-hardening@kernel.org> 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".
I don't agree that the code is worse. It's _different_, just like Rust
forces one to write different code in order to make certain bugs trivial
to reject. But I don't think having to write malloc_objs(T, 1) is
objectively worse than malloc_obj(T).
But let's agree to disagree.
> 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.
Yes, that's a third alternative, which Kees and I discussed some months
ago in Prague as a mitigation.
> 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.
Indeed, I don't volunteer for writing this patch. :)
But yeah, it would also work.
Have a lovely night!
Alex
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-11-12 17:33 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-14 22:32 [PATCH 0/2] devres: Provide kmalloc_obj*-style API for devm_kmalloc Kees Cook
2026-09-14 22:32 ` [PATCH 1/2] mm: Move default_gfp() into gfp_types.h Kees Cook
2026-09-15 2:13 ` Zi Yan
2026-09-15 6:56 ` Vlastimil Babka (SUSE)
2026-10-06 15:42 ` Lorenzo Stoakes (ARM)
2026-09-14 22:32 ` [PATCH 2/2] devres: Provide kmalloc_obj*-style API for devm_kmalloc Kees Cook
2026-10-05 21:35 ` Greg Kroah-Hartman
2026-10-06 0:52 ` Kees Cook
2026-10-06 21:55 ` Danilo Krummrich
2026-11-12 0:40 ` Laurent Pinchart
2026-11-12 10:12 ` Alejandro Colomar
2026-11-12 16:34 ` Linus Torvalds
2026-11-12 17:09 ` Kees Cook
2026-11-12 17:23 ` Linus Torvalds
2026-11-12 18:22 ` Justin Stitt
2026-11-12 17:32 ` Alejandro Colomar [this message]
2026-11-12 17:47 ` Linus Torvalds
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=avX3Y08tF8Z0C4LH@devuan \
--to=alx+linux-hardening@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=brendan.jackman@linux.dev \
--cc=dakr@kernel.org \
--cc=david@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=geert@linux-m68k.org \
--cc=gregkh@linuxfoundation.org \
--cc=gustavoars@kernel.org \
--cc=hannes@cmpxchg.org \
--cc=kees@kernel.org \
--cc=laurent.pinchart@ideasonboard.com \
--cc=liam@infradead.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=mhocko@suse.com \
--cc=rafael@kernel.org \
--cc=rppt@kernel.org \
--cc=surenb@google.com \
--cc=torvalds@linuxfoundation.org \
--cc=vbabka@kernel.org \
--cc=ziy@nvidia.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.