Re: [PATCH] usb: gadget: f_ncm: replace kzalloc with kzalloc_obj

From: Kees Cook

Date: Thu Mar 19 2026 - 16:46:57 EST


On Sun, Mar 15, 2026 at 12:18:27PM +0100, Loke Forsberg wrote:
> Replace kzalloc(sizeof(*ptr)) with kzalloc_obj(), to improve type safety.
>
> Signed-off-by: Loke Forsberg <Loke.Forsberg@xxxxxxxxx>
> ---
> drivers/usb/gadget/function/f_ncm.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/usb/gadget/function/f_ncm.c b/drivers/usb/gadget/function/f_ncm.c
> index 14fc7dce6f39..e1e6763293ef 100644
> --- a/drivers/usb/gadget/function/f_ncm.c
> +++ b/drivers/usb/gadget/function/f_ncm.c
> @@ -1456,7 +1456,7 @@ static int ncm_bind(struct usb_configuration *c, struct usb_function *f)
> return -EINVAL;
>
> if (cdev->use_os_string) {
> - os_desc_table = kzalloc(sizeof(*os_desc_table), GFP_KERNEL);
> + os_desc_table = kzalloc_obj(os_desc_table, GFP_KERNEL);

I was surprised to find this wasn't caught by the original conversion
script, but I suspect Coccinelle is choking on the use of the cleanup
attributes:

struct usb_os_desc_table *os_desc_table __free(kfree) = NULL;
...
if (cdev->use_os_string) {
os_desc_table = kzalloc(sizeof(*os_desc_table), GFP_KERNEL);


I'll see if I can figure this out. I may need to send another set of
bulk replacements...

--
Kees Cook