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 <kees@kernel.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
Kees Cook
2026-02-22 08:26:33 -08:00
committed by Linus Torvalds
parent 32a92f8c89
commit 189f164e57
415 changed files with 612 additions and 833 deletions
+1 -1
View File
@@ -764,7 +764,7 @@ static int coverage_start_fn(const struct decode_header *h, void *args)
static int coverage_start(const union decode_item *table) static int coverage_start(const union decode_item *table)
{ {
coverage.base = kmalloc_objs(struct coverage_entry, coverage.base = kmalloc_objs(struct coverage_entry,
MAX_COVERAGE_ENTRIES, GFP_KERNEL); MAX_COVERAGE_ENTRIES);
coverage.num_entries = 0; coverage.num_entries = 0;
coverage.nesting = 0; coverage.nesting = 0;
return table_iter(table, coverage_start_fn, &coverage); return table_iter(table, coverage_start_fn, &coverage);
+2 -3
View File
@@ -342,7 +342,7 @@ static void __init cps_prepare_cpus(unsigned int max_cpus)
/* Allocate cluster boot configuration structs */ /* Allocate cluster boot configuration structs */
nclusters = mips_cps_numclusters(); nclusters = mips_cps_numclusters();
mips_cps_cluster_bootcfg = kzalloc_objs(*mips_cps_cluster_bootcfg, mips_cps_cluster_bootcfg = kzalloc_objs(*mips_cps_cluster_bootcfg,
nclusters, GFP_KERNEL); nclusters);
if (!mips_cps_cluster_bootcfg) if (!mips_cps_cluster_bootcfg)
goto err_out; goto err_out;
@@ -368,8 +368,7 @@ static void __init cps_prepare_cpus(unsigned int max_cpus)
int v; int v;
core_vpes = core_vpe_count(cl, c); core_vpes = core_vpe_count(cl, c);
core_bootcfg[c].vpe_config = kzalloc_objs(*core_bootcfg[c].vpe_config, core_bootcfg[c].vpe_config = kzalloc_objs(*core_bootcfg[c].vpe_config,
core_vpes, core_vpes);
GFP_KERNEL);
for (v = 0; v < core_vpes; v++) for (v = 0; v < core_vpes; v++)
cpumask_set_cpu(nvpe++, &mips_cps_cluster_bootcfg[cl].cpumask); cpumask_set_cpu(nvpe++, &mips_cps_cluster_bootcfg[cl].cpumask);
if (!core_bootcfg[c].vpe_config) if (!core_bootcfg[c].vpe_config)
+3 -6
View File
@@ -913,8 +913,7 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
vcpu_e500->gtlb_params[1].sets = 1; vcpu_e500->gtlb_params[1].sets = 1;
vcpu_e500->gtlb_arch = kmalloc_objs(*vcpu_e500->gtlb_arch, vcpu_e500->gtlb_arch = kmalloc_objs(*vcpu_e500->gtlb_arch,
KVM_E500_TLB0_SIZE + KVM_E500_TLB1_SIZE, KVM_E500_TLB0_SIZE + KVM_E500_TLB1_SIZE);
GFP_KERNEL);
if (!vcpu_e500->gtlb_arch) if (!vcpu_e500->gtlb_arch)
return -ENOMEM; return -ENOMEM;
@@ -922,14 +921,12 @@ int kvmppc_e500_tlb_init(struct kvmppc_vcpu_e500 *vcpu_e500)
vcpu_e500->gtlb_offset[1] = KVM_E500_TLB0_SIZE; vcpu_e500->gtlb_offset[1] = KVM_E500_TLB0_SIZE;
vcpu_e500->gtlb_priv[0] = kzalloc_objs(struct tlbe_ref, vcpu_e500->gtlb_priv[0] = kzalloc_objs(struct tlbe_ref,
vcpu_e500->gtlb_params[0].entries, vcpu_e500->gtlb_params[0].entries);
GFP_KERNEL);
if (!vcpu_e500->gtlb_priv[0]) if (!vcpu_e500->gtlb_priv[0])
goto free_vcpu; goto free_vcpu;
vcpu_e500->gtlb_priv[1] = kzalloc_objs(struct tlbe_ref, vcpu_e500->gtlb_priv[1] = kzalloc_objs(struct tlbe_ref,
vcpu_e500->gtlb_params[1].entries, vcpu_e500->gtlb_params[1].entries);
GFP_KERNEL);
if (!vcpu_e500->gtlb_priv[1]) if (!vcpu_e500->gtlb_priv[1])
goto free_vcpu; goto free_vcpu;
+1 -2
View File
@@ -1699,8 +1699,7 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
/* Needed for hotplug/migration */ /* Needed for hotplug/migration */
if (!per_nest_pmu_arr) { if (!per_nest_pmu_arr) {
per_nest_pmu_arr = kzalloc_objs(struct imc_pmu *, per_nest_pmu_arr = kzalloc_objs(struct imc_pmu *,
get_max_nest_dev() + 1, get_max_nest_dev() + 1);
GFP_KERNEL);
if (!per_nest_pmu_arr) if (!per_nest_pmu_arr)
goto err; goto err;
} }
+1 -1
View File
@@ -2282,7 +2282,7 @@ static int spufs_switch_log_open(struct inode *inode, struct file *file)
} }
ctx->switch_log = kmalloc_flex(*ctx->switch_log, log, ctx->switch_log = kmalloc_flex(*ctx->switch_log, log,
SWITCH_LOG_BUFSIZE, GFP_KERNEL); SWITCH_LOG_BUFSIZE);
if (!ctx->switch_log) { if (!ctx->switch_log) {
rc = -ENOMEM; rc = -ENOMEM;
+1 -1
View File
@@ -266,7 +266,7 @@ int __init opal_async_comp_init(void)
opal_max_async_tokens = be32_to_cpup(async); opal_max_async_tokens = be32_to_cpup(async);
opal_async_tokens = kzalloc_objs(*opal_async_tokens, opal_async_tokens = kzalloc_objs(*opal_async_tokens,
opal_max_async_tokens, GFP_KERNEL); opal_max_async_tokens);
if (!opal_async_tokens) { if (!opal_async_tokens) {
err = -ENOMEM; err = -ENOMEM;
goto out_opal_node; goto out_opal_node;
@@ -314,8 +314,7 @@ retry:
/* Allocate the groups before registering */ /* Allocate the groups before registering */
for (idx = 0; idx < num_attrs; idx++) { for (idx = 0; idx < num_attrs; idx++) {
papr_groups[idx].pg.attrs = kzalloc_objs(*papr_groups[idx].pg.attrs, papr_groups[idx].pg.attrs = kzalloc_objs(*papr_groups[idx].pg.attrs,
KOBJ_MAX_ATTRS + 1, KOBJ_MAX_ATTRS + 1);
GFP_KERNEL);
if (!papr_groups[idx].pg.attrs) if (!papr_groups[idx].pg.attrs)
goto out_pgattrs; goto out_pgattrs;
+1 -1
View File
@@ -754,7 +754,7 @@ initialize_relocation_hashtable(unsigned int num_relocations,
/* Number of relocations may be large, so kvmalloc it */ /* Number of relocations may be large, so kvmalloc it */
*relocation_hashtable = kvmalloc_objs(**relocation_hashtable, *relocation_hashtable = kvmalloc_objs(**relocation_hashtable,
hashtable_size, GFP_KERNEL); hashtable_size);
if (!*relocation_hashtable) if (!*relocation_hashtable)
return 0; return 0;
+1 -1
View File
@@ -353,7 +353,7 @@ static int kvm_sbi_ext_fwft_init(struct kvm_vcpu *vcpu)
int i; int i;
fwft->configs = kzalloc_objs(struct kvm_sbi_fwft_config, fwft->configs = kzalloc_objs(struct kvm_sbi_fwft_config,
ARRAY_SIZE(features), GFP_KERNEL); ARRAY_SIZE(features));
if (!fwft->configs) if (!fwft->configs)
return -ENOMEM; return -ENOMEM;
+1 -2
View File
@@ -282,8 +282,7 @@ static int pai_alloc_cpu(struct perf_event *event, int cpu)
need_paiext_cb = true; need_paiext_cb = true;
} }
cpump->save = kvmalloc_objs(struct pai_userdata, cpump->save = kvmalloc_objs(struct pai_userdata,
pai_pmu[idx].num_avail + 1, pai_pmu[idx].num_avail + 1);
GFP_KERNEL);
if (!cpump->area || !cpump->save || if (!cpump->area || !cpump->save ||
(need_paiext_cb && !cpump->paiext_cb)) { (need_paiext_cb && !cpump->paiext_cb)) {
pai_free(mp); pai_free(mp);
+2 -2
View File
@@ -1070,7 +1070,7 @@ static int __init ubd_init(void)
return -1; return -1;
irq_req_buffer = kmalloc_objs(struct io_thread_req *, irq_req_buffer = kmalloc_objs(struct io_thread_req *,
UBD_REQ_BUFFER_SIZE, GFP_KERNEL); UBD_REQ_BUFFER_SIZE);
irq_remainder = 0; irq_remainder = 0;
if (irq_req_buffer == NULL) { if (irq_req_buffer == NULL) {
@@ -1078,7 +1078,7 @@ static int __init ubd_init(void)
return -ENOMEM; return -ENOMEM;
} }
io_req_buffer = kmalloc_objs(struct io_thread_req *, io_req_buffer = kmalloc_objs(struct io_thread_req *,
UBD_REQ_BUFFER_SIZE, GFP_KERNEL); UBD_REQ_BUFFER_SIZE);
io_remainder = 0; io_remainder = 0;
+1 -1
View File
@@ -515,7 +515,7 @@ static void uml_vfio_open_device(struct uml_vfio_device *dev)
} }
dev->intr_ctx = kmalloc_objs(struct uml_vfio_intr_ctx, dev->intr_ctx = kmalloc_objs(struct uml_vfio_intr_ctx,
dev->udev.irq_count, GFP_KERNEL); dev->udev.irq_count);
if (!dev->intr_ctx) { if (!dev->intr_ctx) {
pr_err("Failed to allocate interrupt context (%s)\n", pr_err("Failed to allocate interrupt context (%s)\n",
dev->name); dev->name);
+1 -1
View File
@@ -7379,7 +7379,7 @@ static __always_inline int intel_pmu_init_hybrid(enum hybrid_pmu_type pmus)
x86_pmu.num_hybrid_pmus = hweight_long(pmus_mask); x86_pmu.num_hybrid_pmus = hweight_long(pmus_mask);
x86_pmu.hybrid_pmu = kzalloc_objs(struct x86_hybrid_pmu, x86_pmu.hybrid_pmu = kzalloc_objs(struct x86_hybrid_pmu,
x86_pmu.num_hybrid_pmus, GFP_KERNEL); x86_pmu.num_hybrid_pmus);
if (!x86_pmu.hybrid_pmu) if (!x86_pmu.hybrid_pmu)
return -ENOMEM; return -ENOMEM;
+1 -2
View File
@@ -745,8 +745,7 @@ intel_uncore_generic_init_uncores(enum uncore_access_type type_id, int num_extra
int i = 0; int i = 0;
uncores = kzalloc_objs(struct intel_uncore_type *, uncores = kzalloc_objs(struct intel_uncore_type *,
num_discovered_types[type_id] + num_extra + 1, num_discovered_types[type_id] + num_extra + 1);
GFP_KERNEL);
if (!uncores) if (!uncores)
return empty_uncore; return empty_uncore;
+1 -1
View File
@@ -2407,7 +2407,7 @@ static int __tdx_td_init(struct kvm *kvm, struct td_params *td_params,
/* TDVPS = TDVPR(4K page) + TDCX(multiple 4K pages), -1 for TDVPR. */ /* TDVPS = TDVPR(4K page) + TDCX(multiple 4K pages), -1 for TDVPR. */
kvm_tdx->td.tdcx_nr_pages = tdx_sysinfo->td_ctrl.tdvps_base_size / PAGE_SIZE - 1; kvm_tdx->td.tdcx_nr_pages = tdx_sysinfo->td_ctrl.tdvps_base_size / PAGE_SIZE - 1;
tdcs_pages = kzalloc_objs(*kvm_tdx->td.tdcs_pages, tdcs_pages = kzalloc_objs(*kvm_tdx->td.tdcs_pages,
kvm_tdx->td.tdcs_nr_pages, GFP_KERNEL); kvm_tdx->td.tdcs_nr_pages);
if (!tdcs_pages) if (!tdcs_pages)
goto free_tdr; goto free_tdr;
+1 -1
View File
@@ -574,7 +574,7 @@ static int blk_crypto_fallback_init(void)
goto fail_destroy_profile; goto fail_destroy_profile;
blk_crypto_keyslots = kzalloc_objs(blk_crypto_keyslots[0], blk_crypto_keyslots = kzalloc_objs(blk_crypto_keyslots[0],
blk_crypto_num_keyslots, GFP_KERNEL); blk_crypto_num_keyslots);
if (!blk_crypto_keyslots) if (!blk_crypto_keyslots)
goto fail_free_wq; goto fail_free_wq;
+1 -1
View File
@@ -1805,7 +1805,7 @@ static int disk_alloc_zone_resources(struct gendisk *disk,
disk->zone_wplugs_hash = disk->zone_wplugs_hash =
kzalloc_objs(struct hlist_head, kzalloc_objs(struct hlist_head,
disk_zone_wplugs_hash_size(disk), GFP_KERNEL); disk_zone_wplugs_hash_size(disk));
if (!disk->zone_wplugs_hash) if (!disk->zone_wplugs_hash)
return -ENOMEM; return -ENOMEM;
+1 -2
View File
@@ -210,8 +210,7 @@ int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx)
atomic_set(&ctx->thread_ctx_switch_token, 1); atomic_set(&ctx->thread_ctx_switch_token, 1);
ctx->thread_ctx_switch_wait_token = 0; ctx->thread_ctx_switch_wait_token = 0;
ctx->cs_pending = kzalloc_objs(struct hl_fence *, ctx->cs_pending = kzalloc_objs(struct hl_fence *,
hdev->asic_prop.max_pending_cs, hdev->asic_prop.max_pending_cs);
GFP_KERNEL);
if (!ctx->cs_pending) if (!ctx->cs_pending)
return -ENOMEM; return -ENOMEM;
+4 -7
View File
@@ -893,8 +893,7 @@ static int device_early_init(struct hl_device *hdev)
if (hdev->asic_prop.completion_queues_count) { if (hdev->asic_prop.completion_queues_count) {
hdev->cq_wq = kzalloc_objs(struct workqueue_struct *, hdev->cq_wq = kzalloc_objs(struct workqueue_struct *,
hdev->asic_prop.completion_queues_count, hdev->asic_prop.completion_queues_count);
GFP_KERNEL);
if (!hdev->cq_wq) { if (!hdev->cq_wq) {
rc = -ENOMEM; rc = -ENOMEM;
goto asid_fini; goto asid_fini;
@@ -2159,8 +2158,7 @@ int hl_device_init(struct hl_device *hdev)
if (user_interrupt_cnt) { if (user_interrupt_cnt) {
hdev->user_interrupt = kzalloc_objs(*hdev->user_interrupt, hdev->user_interrupt = kzalloc_objs(*hdev->user_interrupt,
user_interrupt_cnt, user_interrupt_cnt);
GFP_KERNEL);
if (!hdev->user_interrupt) { if (!hdev->user_interrupt) {
rc = -ENOMEM; rc = -ENOMEM;
goto early_fini; goto early_fini;
@@ -2227,7 +2225,7 @@ int hl_device_init(struct hl_device *hdev)
*/ */
if (cq_cnt) { if (cq_cnt) {
hdev->completion_queue = kzalloc_objs(*hdev->completion_queue, hdev->completion_queue = kzalloc_objs(*hdev->completion_queue,
cq_cnt, GFP_KERNEL); cq_cnt);
if (!hdev->completion_queue) { if (!hdev->completion_queue) {
dev_err(hdev->dev, dev_err(hdev->dev,
@@ -2249,8 +2247,7 @@ int hl_device_init(struct hl_device *hdev)
} }
hdev->shadow_cs_queue = kzalloc_objs(struct hl_cs *, hdev->shadow_cs_queue = kzalloc_objs(struct hl_cs *,
hdev->asic_prop.max_pending_cs, hdev->asic_prop.max_pending_cs);
GFP_KERNEL);
if (!hdev->shadow_cs_queue) { if (!hdev->shadow_cs_queue) {
rc = -ENOMEM; rc = -ENOMEM;
goto cq_fini; goto cq_fini;
+1 -1
View File
@@ -1083,7 +1083,7 @@ int hl_hw_queues_create(struct hl_device *hdev)
int i, rc, q_ready_cnt; int i, rc, q_ready_cnt;
hdev->kernel_queues = kzalloc_objs(*hdev->kernel_queues, hdev->kernel_queues = kzalloc_objs(*hdev->kernel_queues,
asic->max_queues, GFP_KERNEL); asic->max_queues);
if (!hdev->kernel_queues) { if (!hdev->kernel_queues) {
dev_err(hdev->dev, "Not enough memory for H/W queues\n"); dev_err(hdev->dev, "Not enough memory for H/W queues\n");

Some files were not shown because too many files have changed in this diff Show More