From: Kees Cook <kees@kernel.org>
To: Guenter Roeck <linux@roeck-us.net>
Cc: linux-kernel@vger.kernel.org, Nathan Chancellor <nathan@kernel.org>
Subject: Re: [PATCH] treewide: Replace kmalloc with kmalloc_obj for non-scalar types
Date: Mon, 23 Feb 2026 09:48:03 -0800 [thread overview]
Message-ID: <8DBEF986-6446-4EF8-9570-C898BD301B1E@kernel.org> (raw)
In-Reply-To: <b04b6c13-7d0e-4a89-9e68-b572b6c686ac@roeck-us.net>
On February 23, 2026 8:05:10 AM PST, Guenter Roeck <linux@roeck-us.net> wrote:
>On Fri, Feb 20, 2026 at 11:49:23PM -0800, Kees Cook wrote:
>> This is the result of running the Coccinelle script from
>> scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
>> avoid scalar types (which need careful case-by-case checking), and
>> instead replace kmalloc-family calls that allocate struct or union
>> object instances:
>>
>> Single allocations: kmalloc(sizeof(TYPE), ...)
>> are replaced with: kmalloc_obj(TYPE, ...)
>>
>> Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
>> are replaced with: kmalloc_objs(TYPE, COUNT, ...)
>>
>> Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
>> are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
>>
>> (where TYPE may also be *VAR)
>>
>> The resulting allocations no longer return "void *", instead returning
>> "TYPE *".
>>
>> Signed-off-by: Kees Cook <kees@kernel.org>
>> ---
>> diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c
>> index 37455e74d314..42f392e6add3 100644
>> --- a/arch/um/drivers/ubd_kern.c
>> +++ b/arch/um/drivers/ubd_kern.c
>> @@ -1069,20 +1069,16 @@ static int __init ubd_init(void)
>> if (register_blkdev(UBD_MAJOR, "ubd"))
>> return -1;
>>
>> - irq_req_buffer = kmalloc_array(UBD_REQ_BUFFER_SIZE,
>> - sizeof(struct io_thread_req *),
>> - GFP_KERNEL
>> - );
>> + irq_req_buffer = kmalloc_objs(struct io_thread_req *,
>> + UBD_REQ_BUFFER_SIZE, GFP_KERNEL);
>> irq_remainder = 0;
>>
>> if (irq_req_buffer == NULL) {
>> printk(KERN_ERR "Failed to initialize ubd buffering\n");
>> return -ENOMEM;
>> }
>> - io_req_buffer = kmalloc_array(UBD_REQ_BUFFER_SIZE,
>> - sizeof(struct io_thread_req *),
>> - GFP_KERNEL
>> - );
>> + io_req_buffer = kmalloc_objs(struct io_thread_req *,
>> + UBD_REQ_BUFFER_SIZE, GFP_KERNEL);
>
>Building um:defconfig ... failed
>--------------
>Error log:
>arch/um/drivers/ubd_kern.c: In function 'ubd_init':
>arch/um/drivers/ubd_kern.c:1072:24: error: assignment to 'struct io_thread_req * (*)[]' from incompatible pointer type 'struct io_thread_req **' [-Wincompatible-pointer-types]
> 1072 | irq_req_buffer = kmalloc_objs(struct io_thread_req *,
> | ^
>arch/um/drivers/ubd_kern.c:1080:23: error: assignment to 'struct io_thread_req * (*)[]' from incompatible pointer type 'struct io_thread_req **' [-Wincompatible-pointer-types]
> 1080 | io_req_buffer = kmalloc_objs(struct io_thread_req *,
Thanks for finding this! I'll get these fixed up today; I missed um in my build testing. Doing these tree-wide changes is tricky without having a sane way to get them into -next first.
-Kees
--
Kees Cook
next prev parent reply other threads:[~2026-02-23 17:48 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-23 16:05 Guenter Roeck
2026-02-23 17:48 ` Kees Cook [this message]
2026-02-23 22:23 ` Kees Cook
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=8DBEF986-6446-4EF8-9570-C898BD301B1E@kernel.org \
--to=kees@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@roeck-us.net \
--cc=nathan@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®