usb: gadget: f_ncm: replace kzalloc with kzalloc_obj
PATCH 1/1 usb: gadget: f_ncm: replace kzalloc with kzalloc_obj
Replace kzalloc(sizeof(*ptr)) with kzalloc_obj(), to improve type safety.
--- drivers/usb/gadget/function/f_ncm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/usb/gadget/function/f_ncm.c +2 -2
@@ -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 );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,GFP_KERNEL );if (!ncm)return ERR_PTR (-ENOMEM );
Signature · 1 line
2.53.0
Greg KH
maintainerQuoted 12 lines · Loke Forsberg
Replace kzalloc(sizeof(*ptr)) with
kzalloc_obj(), to improve type safety.Signed-off-by Loke Forsberg <[email protected]>--- drivers/usb/gadget/function/f_ncm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/usb/gadget/function/f_ncm.c +0
-0
drivers/usb/gadget/function/f_ncm.c static int ncm_bind(struct usb_configuration *c, struct usb_function *f) · line 1459
Quoted 5 lines
drivers/usb/gadget/function/f_ncm.c +1
-1@@ -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 );
Why have you used GFP_KERNEL when kzalloc_obj() does not need that for the default case?
drivers/usb/gadget/function/f_ncm.c static struct usb_function *ncm_alloc(struct usb_function_instance *fi) · line 1756
Quoted 9 lines
drivers/usb/gadget/function/f_ncm.c +1
-1if (!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,GFP_KERNEL );
Same here.
thanks,
greg k-h
Quoted 2 lines
Why have you used
GFP_KERNELwhenkzalloc_obj()does not need that for the default case?
I was following the pattern from the original kzalloc and didnt realize it defaults to it. I will fix it and send a v2
Regards,
Loke Forsberg
Quoted 12 lines · Loke Forsberg
Replace kzalloc(sizeof(*ptr)) with
kzalloc_obj(), to improve type safety.Signed-off-by Loke Forsberg <[email protected]>--- drivers/usb/gadget/function/f_ncm.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)drivers/usb/gadget/function/f_ncm.c +0
-0
drivers/usb/gadget/function/f_ncm.c static int ncm_bind(struct usb_configuration *c, struct usb_function *f) · line 1459
Quoted 5 lines
drivers/usb/gadget/function/f_ncm.c +1
-1@@ -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...
Signature · 1 line
Kees Cook
Quoted 4 lines · Kees Cook
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:
Quoted 8 lines
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...
Ah, it's not so bad. Latest Coccinelle handles the cleanup attributes correctly:
72 files changed, 104 insertions(+), 117 deletions(-)
Signature · 1 line
Kees Cook