kmalloc_obj branch for v7.0-rc1
Hi Linus,
Please pull the kmalloc_obj branch for v7.0-rc1. Vlastimil asked me to carry this tree as a distinct branch, so here it is. Introduces the kmalloc_obj* family of APIs for switching to type-based kmalloc allocations, away from purely size-based allocations. Discussed on lkml, with you, and at Linux Plumbers. It's been in -next for the entire dev cycle.
Before you cut -rc1, I'd like to send you the treewide change (generated from the Coccinelle script in this PR), which mechanically converts almost 20k callsites from kmalloc* to kmalloc_obj*:
8007 files changed, 19980 insertions(+), 20838 deletions(-)
This change needed fixes for mismatched types (since now the return type from allocations is a pointer to the requested type, not "void *"), and I've been fixing these over the last 4 releases. For those, see:
$ git log --author Kees --grep "preparation for making the kmalloc"
These fixes have mostly been trivial mismatches with const qualifiers or accidentally identical sizes (e.g. same object size: "struct kvec *" vs "struct iovec *", or differing pointer pointers: "struct vkms_plane_state **" vs "struct drm_plane **"), but I did catch one case of too-small allocation (the fix is in the works).
While working through these fixes it became clear the integral type allocations needed to be excluded from the mechanical treewide change since many of those needed case-by-case examination for type correctness. Much of the Coccinelle script, therefore, is excluding those. I've had the treewide change getting scanned by 0-day for the entire dev cycle, and a few stragglers have popped up (recently introduced type mismatches). I've sent patches for these already, but if they don't get picked up for -rc1, I'll add them to my treewide change branch before I send you that PR. I've also been doing my own allmodconfig builds across architectures to see if I can catch anything 0-day hasn't found.
Note that the Coccinelle script commit has a commit date from today since I added wchar_t to the exclusion list today after finding an instance of that in s390 over the weekend.
If you'd rather handle the treewide change differently, please let me know what you'd like to see! :)
Thanks!
-Kees
The following changes since commit 9448598b22c50c8a5bb77a9103e2d49f134c9578:
Linux 6.19-rc2 (2025-12-21 15:52:04 -0800)
are available in the Git repository at:
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git tags/kmalloc_obj-v7.0-rc1
for you to fetch changes up to bdc5071d7f7bb82589737741e9bf19820ceb7a6a:
coccinelle: Add kmalloc_objs conversion script (2026-02-09 10:48:20 -0800)
----------------------------------------------------------------kmalloc_obj branch for v7.0-rc1
- Introduce kmalloc_obj*() family of type-based allocator APIs
- checkpatch: Suggest kmalloc_obj family for sizeof allocations
- coccinelle: Add kmalloc_objs conversion script
----------------------------------------------------------------
Kees Cook (5):
slab: Introduce kmalloc_obj() and family
checkpatch: Suggest kmalloc_obj family for sizeof allocations
compiler_types: Introduce __flex_counter() and family
slab: Introduce kmalloc_flex() and family
coccinelle: Add kmalloc_objs conversion script
scripts/checkpatch.pl | 39 ++++++++-- scripts/coccinelle/api/kmalloc_objs.cocci | 124 ++++++++++++++++++++++++++++++ Documentation/process/deprecated.rst | 31 ++++++++ include/linux/compiler_types.h | 31 ++++++++ include/linux/overflow.h | 42 ++++++++++ include/linux/slab.h | 106 +++++++++++++++++++++++++ 6 files changed, 367 insertions(+), 6 deletions(-) create mode 100644 scripts/coccinelle/api/kmalloc_objs.cocci
Signature · 1 line
Kees Cook
The pull request you sent on Mon, 9 Feb 2026 11:22:59 -0800:
The pull request you sent on Mon, 9 Feb 2026 11:22:59 -0800:
Quoted 1 line
https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git tags/kmalloc_obj-v7.0-rc1
has been merged into torvalds/linux.git:
https://git.kernel.org/torvalds/c/958f7fb68c6be4e2d9dcb5bf31bfe746f6744aa3
Thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/prtracker.html