Re: [cocci] [PATCH v5 4/4] coccinelle: Add kmalloc_objs conversion script

From: Markus Elfring
Date: Mon Nov 24 2025 - 07:56:12 EST


> Finds and converts sized kmalloc-family of allocations into the
> typed kmalloc_obj-family of allocations.

See also:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.18-rc7#n94



> +++ b/scripts/coccinelle/api/kmalloc_objs.cocci
> @@ -0,0 +1,168 @@

> +// Comments:


* Please omit such an empty information line.

* Would a field like “Keywords” become helpful?


> +virtual patch

Will additional operation modes become relevant after clarification of implementation details?



> +def alloc_array(name):
> + func = "FAILED_RENAME"
> + if name == "kmalloc_array":
> + func = "kmalloc_objs"


* I suggest to avoid duplicate variable assignments.

* How do you think about to collaborate with the Python data structure “dictionary”?



> +type TYPE;
> +TYPE *P;
> +TYPE INST;
> +expression VAR;
> +expression GFP;


Such repetition of SmPL key words can eventually be also avoided.

Regards,
Markus