Commit 189f164e authored by Kees Cook's avatar Kees Cook Committed by Linus Torvalds
Browse files

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: default avatarKees Cook <kees@kernel.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 32a92f8c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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)
{
	coverage.base = kmalloc_objs(struct coverage_entry,
				     MAX_COVERAGE_ENTRIES, GFP_KERNEL);
				     MAX_COVERAGE_ENTRIES);
	coverage.num_entries = 0;
	coverage.nesting = 0;
	return table_iter(table, coverage_start_fn, &coverage);
+2 −3
Original line number Diff line number Diff line
@@ -342,7 +342,7 @@ static void __init cps_prepare_cpus(unsigned int max_cpus)
	/* Allocate cluster boot configuration structs */
	nclusters = mips_cps_numclusters();
	mips_cps_cluster_bootcfg = kzalloc_objs(*mips_cps_cluster_bootcfg,
						nclusters, GFP_KERNEL);
						nclusters);
	if (!mips_cps_cluster_bootcfg)
		goto err_out;

@@ -368,8 +368,7 @@ static void __init cps_prepare_cpus(unsigned int max_cpus)
			int v;
			core_vpes = core_vpe_count(cl, c);
			core_bootcfg[c].vpe_config = kzalloc_objs(*core_bootcfg[c].vpe_config,
								  core_vpes,
								  GFP_KERNEL);
								  core_vpes);
			for (v = 0; v < core_vpes; v++)
				cpumask_set_cpu(nvpe++, &mips_cps_cluster_bootcfg[cl].cpumask);
			if (!core_bootcfg[c].vpe_config)
+3 −6
Original line number Diff line number Diff line
@@ -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_arch = kmalloc_objs(*vcpu_e500->gtlb_arch,
					    KVM_E500_TLB0_SIZE + KVM_E500_TLB1_SIZE,
					    GFP_KERNEL);
					    KVM_E500_TLB0_SIZE + KVM_E500_TLB1_SIZE);
	if (!vcpu_e500->gtlb_arch)
		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_priv[0] = kzalloc_objs(struct tlbe_ref,
					       vcpu_e500->gtlb_params[0].entries,
					       GFP_KERNEL);
					       vcpu_e500->gtlb_params[0].entries);
	if (!vcpu_e500->gtlb_priv[0])
		goto free_vcpu;

	vcpu_e500->gtlb_priv[1] = kzalloc_objs(struct tlbe_ref,
					       vcpu_e500->gtlb_params[1].entries,
					       GFP_KERNEL);
					       vcpu_e500->gtlb_params[1].entries);
	if (!vcpu_e500->gtlb_priv[1])
		goto free_vcpu;

+1 −2
Original line number Diff line number Diff line
@@ -1699,8 +1699,7 @@ static int imc_mem_init(struct imc_pmu *pmu_ptr, struct device_node *parent,
		/* Needed for hotplug/migration */
		if (!per_nest_pmu_arr) {
			per_nest_pmu_arr = kzalloc_objs(struct imc_pmu *,
							get_max_nest_dev() + 1,
							GFP_KERNEL);
							get_max_nest_dev() + 1);
			if (!per_nest_pmu_arr)
				goto err;
		}
+1 −1
Original line number Diff line number Diff line
@@ -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,
				       SWITCH_LOG_BUFSIZE, GFP_KERNEL);
				       SWITCH_LOG_BUFSIZE);

	if (!ctx->switch_log) {
		rc = -ENOMEM;
Loading