summaryrefslogtreecommitdiff
path: root/scripts/coccinelle/api/kmalloc_objs.cocci
AgeCommit message (Collapse)Author
2026-09-21coccinelle: kmalloc_obj: Convert multi-byte integral allocationsKees Cook
Currently the kmalloc_obj conversion rules leave alone every allocation sized to an integral type, or assigned to a pointer to one, so that byte buffers keep being allocated with a byte count. That also leaves alone arrays of multi-byte integers, such as vals = kcalloc(n, sizeof(u32), GFP_KERNEL); which count objects like any other array. At the same time the signed types (s8 through s64 and their variants) were not in the list at all. But these multi-byte types are better handled through the full kmalloc_obj-style allocation, as they are, in fact, typed and aren't just a byte string, so they would benefit from type checking. Split INTEGRAL into BYTE_TYPES and MULTIBYTE_TYPES: - Allocations sized by a byte type or a string literal, or assigned to a pointer to a byte type, are still left alone. - Allocations sized by a multi-byte type are converted when they are assigned to a pointer, or a pointer to const, of that same type. Other allocations sized by a multi-byte type are left alone, as their target may be a pointer to an array. - Allocations of other types assigned to a pointer to a multi-byte type are still left alone. - Arrays of pointers to integral types sized by type, such as sizeof(char *), are still left alone, now including the signed types, as their target may be a pointer to an array of pointers, like "const char *(*fmts)[]". Sized as sizeof(*target), they are converted like any other array. List the signed types and the other spellings of the standard integer types (short int, unsigned, long long int, and so on), so that a declaration and a sizeof() that spell the same type differently still match. Assisted-by: LLM coccinelle Link: https://patch.msgid.link/20260914223748.i.971-kees@kernel.org Signed-off-by: Kees Cook <kees@kernel.org>
2026-03-20coccinelle: kmalloc_obj: Remove default GFP_KERNEL argKees Cook
Remove any GFP_KERNEL arguments found in the new kmalloc_obj-family helpers. This captures the script used in commit 189f164e573e ("Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses"). Link: https://patch.msgid.link/20260320175113.work.016-kees@kernel.org Signed-off-by: Kees Cook <kees@kernel.org>
2026-02-09coccinelle: Add kmalloc_objs conversion scriptKees Cook
Finds and converts sized kmalloc-family of allocations into the typed kmalloc_obj-family of allocations. Link: https://patch.msgid.link/20251203233036.3212363-5-kees@kernel.org Signed-off-by: Kees Cook <kees@kernel.org>