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

From: Loke Forsberg

Date: Mon Mar 16 2026 - 05:25:37 EST


Replace kzalloc(sizeof(*ptr)) with kzalloc_obj(), to improve type safety.

Signed-off-by: Loke Forsberg <Loke.Forsberg@xxxxxxxxx>
---
Changes in v2:
- Remove GFP_KERNEL flag as kzalloc_obj() defaults to it

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..1bec7e99b04f 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);
if (!os_desc_table)
return -ENOMEM;
}
@@ -1753,7 +1753,7 @@ static struct usb_function *ncm_alloc(struct usb_function_instance *fi)
struct f_ncm_opts *opts;

/* allocate and initialize one new instance */
- ncm = kzalloc(sizeof(*ncm), GFP_KERNEL);
+ ncm = kzalloc_obj(ncm);
if (!ncm)
return ERR_PTR(-ENOMEM);

--
2.53.0