From 189f164e573e18d9f8876dbd3ad8fcbe11f93037 Mon Sep 17 00:00:00 2001 From: Kees Cook Date: Sat, 21 Feb 2026 23:46:04 -0800 Subject: Convert remaining multi-line kmalloc_obj/flex GFP_KERNEL uses Conversion performed via this Coccinelle script: // SPDX-License-Identifier: GPL-2.0-only // Options: --include-headers-for-types --all-includes --include-headers --keep-comments virtual patch @gfp depends on patch && !(file in "tools") && !(file in "samples")@ identifier ALLOC = {kmalloc_obj,kmalloc_objs,kmalloc_flex, kzalloc_obj,kzalloc_objs,kzalloc_flex, kvmalloc_obj,kvmalloc_objs,kvmalloc_flex, kvzalloc_obj,kvzalloc_objs,kvzalloc_flex}; @@ ALLOC(... - , GFP_KERNEL ) $ make coccicheck MODE=patch COCCI=gfp.cocci Build and boot tested x86_64 with Fedora 42's GCC and Clang: Linux version 6.19.0+ (user@host) (gcc (GCC) 15.2.1 20260123 (Red Hat 15.2.1-7), GNU ld version 2.44-12.fc42) #1 SMP PREEMPT_DYNAMIC 1970-01-01 Linux version 6.19.0+ (user@host) (clang version 20.1.8 (Fedora 20.1.8-4.fc42), LLD 20.1.8) #1 SMP PREEMPT_DYNAMIC 1970-01-01 Signed-off-by: Kees Cook Signed-off-by: Linus Torvalds --- drivers/usb/gadget/configfs.c | 5 ++--- drivers/usb/gadget/function/f_midi2.c | 2 +- drivers/usb/gadget/function/u_audio.c | 4 ++-- drivers/usb/isp1760/isp1760-hcd.c | 4 ++-- drivers/usb/storage/ene_ub6250.c | 3 +-- 5 files changed, 8 insertions(+), 10 deletions(-) (limited to 'drivers/usb') diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c index 06e892beda88..183a25f65ac8 100644 --- a/drivers/usb/gadget/configfs.c +++ b/drivers/usb/gadget/configfs.c @@ -1629,8 +1629,7 @@ configfs_attach_gadget_strings(struct gadget_info *gi) if (!nlangs) return NULL; - gadget_strings = kzalloc_objs(struct usb_gadget_strings *, nlangs + 1, - GFP_KERNEL)/* including NULL terminator */; + gadget_strings = kzalloc_objs(struct usb_gadget_strings *, nlangs + 1)/* including NULL terminator */; if (!gadget_strings) return ERR_PTR(-ENOMEM); @@ -1646,7 +1645,7 @@ configfs_attach_gadget_strings(struct gadget_info *gi) } stringtab = kzalloc_objs(struct usb_string, - language->nstrings + 1, GFP_KERNEL); + language->nstrings + 1); if (!stringtab) { us = ERR_PTR(-ENOMEM); goto cleanup; diff --git a/drivers/usb/gadget/function/f_midi2.c b/drivers/usb/gadget/function/f_midi2.c index 4c663431e99f..b5f0defde95d 100644 --- a/drivers/usb/gadget/function/f_midi2.c +++ b/drivers/usb/gadget/function/f_midi2.c @@ -2855,7 +2855,7 @@ static struct usb_function *f_midi2_alloc(struct usb_function_instance *fi) } midi2->string_defs = kzalloc_objs(*midi2->string_defs, - midi2->total_blocks + 1, GFP_KERNEL); + midi2->total_blocks + 1); if (!midi2->string_defs) { do_f_midi2_free(midi2, opts); return ERR_PTR(-ENOMEM); diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c index 36d2fedbda11..e53f2927b539 100644 --- a/drivers/usb/gadget/function/u_audio.c +++ b/drivers/usb/gadget/function/u_audio.c @@ -1210,7 +1210,7 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, prm->srate = params->c_srates[0]; prm->reqs = kzalloc_objs(struct usb_request *, - params->req_number, GFP_KERNEL); + params->req_number); if (!prm->reqs) { err = -ENOMEM; goto fail; @@ -1234,7 +1234,7 @@ int g_audio_setup(struct g_audio *g_audio, const char *pcm_name, prm->srate = params->p_srates[0]; prm->reqs = kzalloc_objs(struct usb_request *, - params->req_number, GFP_KERNEL); + params->req_number); if (!prm->reqs) { err = -ENOMEM; goto fail; diff --git a/drivers/usb/isp1760/isp1760-hcd.c b/drivers/usb/isp1760/isp1760-hcd.c index fbb83c84beee..6c52c6f59d69 100644 --- a/drivers/usb/isp1760/isp1760-hcd.c +++ b/drivers/usb/isp1760/isp1760-hcd.c @@ -2573,14 +2573,14 @@ int isp1760_hcd_register(struct isp1760_hcd *priv, struct resource *mem, priv->hcd = hcd; priv->atl_slots = kzalloc_objs(struct isp1760_slotinfo, - mem_layout->slot_num, GFP_KERNEL); + mem_layout->slot_num); if (!priv->atl_slots) { ret = -ENOMEM; goto put_hcd; } priv->int_slots = kzalloc_objs(struct isp1760_slotinfo, - mem_layout->slot_num, GFP_KERNEL); + mem_layout->slot_num); if (!priv->int_slots) { ret = -ENOMEM; goto free_atl_slots; diff --git a/drivers/usb/storage/ene_ub6250.c b/drivers/usb/storage/ene_ub6250.c index 7622bc0426cd..8770de01a384 100644 --- a/drivers/usb/storage/ene_ub6250.c +++ b/drivers/usb/storage/ene_ub6250.c @@ -1120,8 +1120,7 @@ static int ms_lib_alloc_writebuf(struct us_data *us) info->MS_Lib.BytesPerSector, GFP_KERNEL); info->MS_Lib.blkext = kmalloc_objs(struct ms_lib_type_extdat, - info->MS_Lib.PagesPerBlock, - GFP_KERNEL); + info->MS_Lib.PagesPerBlock); if ((info->MS_Lib.blkpag == NULL) || (info->MS_Lib.blkext == NULL)) { ms_lib_free_writebuf(us); -- cgit v1.2.3