summaryrefslogtreecommitdiff
path: root/arch
diff options
context:
space:
mode:
authorKees Cook <kees+treewide@kernel.org>2026-09-02 15:31:14 -0700
committerKees Cook <kees@kernel.org>2026-09-04 21:37:00 -0700
commit3a2c4d55e32ad65efebdb6de44eef3bfa08bb49d (patch)
treec65086f9bdcd48c6360fb7cb4598bca084da1f32 /arch
parent90feea391c64fc43bf44184fcf2b243ab991ce47 (diff)
treewide: refresh kmalloc_obj() conversions
This is another run of the Coccinelle script for converting kmalloc() family of allocations to kmalloc_obj() via the existing rules in scripts/coccinelle/api/kmalloc_objs.cocci This catches both the set of kmalloc() uses added since the first kmalloc_obj() conversions in v7.0 and adds a large group missed in the first pass due to Coccinelle not interacting well with the cleanup.h scoped_...() family of macros[1]. I worked around this with spatch's "--macro-file" argument to a file with all the scoped_...() macros mapped to Coccinelle's YACFE_ITERATOR[2] as that was the closest viable control flow indicator I could find. Build tested allmodconfig on x86, arm64, arm, loongarch, mips, powerpc, riscv, and s390 with no new warnings. Link: https://lore.kernel.org/lkml/202609021314.8A9C0B8@keescook/ [1] Link: https://github.com/coccinelle/coccinelle/blob/master/standard.h [2] Signed-off-by: Kees Cook <kees+treewide@kernel.org>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm64/crypto/aes-neonbs-glue.c4
-rw-r--r--arch/arm64/kvm/nested.c2
-rw-r--r--arch/loongarch/kvm/intc/dmsintc.c2
-rw-r--r--arch/mips/bcm47xx/buttons.c8
-rw-r--r--arch/powerpc/sysdev/xive/common.c2
-rw-r--r--arch/riscv/kvm/vcpu_pmu.c4
-rw-r--r--arch/s390/kvm/s390/s390.c4
7 files changed, 13 insertions, 13 deletions
diff --git a/arch/arm64/crypto/aes-neonbs-glue.c b/arch/arm64/crypto/aes-neonbs-glue.c
index 5bcbac979893..7cb1aede9a48 100644
--- a/arch/arm64/crypto/aes-neonbs-glue.c
+++ b/arch/arm64/crypto/aes-neonbs-glue.c
@@ -66,7 +66,7 @@ static int aesbs_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
struct crypto_aes_ctx *rk;
int err;
- rk = kmalloc(sizeof(*rk), GFP_KERNEL);
+ rk = kmalloc_obj(*rk);
if (!rk)
return -ENOMEM;
@@ -128,7 +128,7 @@ static int aesbs_cbc_ctr_setkey(struct crypto_skcipher *tfm, const u8 *in_key,
struct crypto_aes_ctx *rk;
int err;
- rk = kmalloc(sizeof(*rk), GFP_KERNEL);
+ rk = kmalloc_obj(*rk);
if (!rk)
return -ENOMEM;
diff --git a/arch/arm64/kvm/nested.c b/arch/arm64/kvm/nested.c
index 17123f0b6dab..3c4fc566eafc 100644
--- a/arch/arm64/kvm/nested.c
+++ b/arch/arm64/kvm/nested.c
@@ -93,7 +93,7 @@ int kvm_vcpu_init_nested(struct kvm_vcpu *vcpu)
num_mmus = atomic_read(&kvm->online_vcpus) * S2_MMU_PER_VCPU;
if (num_mmus > kvm->arch.nested_mmus_size) {
- tmp = kvcalloc(num_mmus, sizeof(*tmp), GFP_KERNEL_ACCOUNT);
+ tmp = kvzalloc_objs(*tmp, num_mmus, GFP_KERNEL_ACCOUNT);
if (!tmp)
return -ENOMEM;
diff --git a/arch/loongarch/kvm/intc/dmsintc.c b/arch/loongarch/kvm/intc/dmsintc.c
index bb7285c49df3..5518cafada55 100644
--- a/arch/loongarch/kvm/intc/dmsintc.c
+++ b/arch/loongarch/kvm/intc/dmsintc.c
@@ -149,7 +149,7 @@ static int kvm_dmsintc_create(struct kvm_device *dev, u32 type)
return -EINVAL;
}
- s = kzalloc(sizeof(struct loongarch_dmsintc), GFP_KERNEL);
+ s = kzalloc_obj(struct loongarch_dmsintc);
if (!s)
return -ENOMEM;
diff --git a/arch/mips/bcm47xx/buttons.c b/arch/mips/bcm47xx/buttons.c
index 151a4ee2803f..7bb338da8e42 100644
--- a/arch/mips/bcm47xx/buttons.c
+++ b/arch/mips/bcm47xx/buttons.c
@@ -523,24 +523,24 @@ bcm47xx_buttons_add(const struct bcm47xx_gpio_key *buttons, int nbuttons)
/* 1 node for gpio-keys device, 1 node for each button, 1 terminator */
const struct software_node **node_group __free(kfree) =
- kcalloc(1 + nbuttons + 1, sizeof(*node_group), GFP_KERNEL);
+ kzalloc_objs(*node_group, 1 + nbuttons + 1);
if (!node_group)
return -ENOMEM;
/* 1 code property, 1 gpio property, 1 terminator */
struct property_entry *props __free(kfree) =
- kcalloc(nbuttons * 3, sizeof(*props), GFP_KERNEL);
+ kzalloc_objs(*props, nbuttons * 3);
if (!props)
return -ENOMEM;
/* 1 node for gpio-keys device, 1 node for each button */
struct software_node *nodes __free(kfree) =
- kcalloc(1 + nbuttons, sizeof(*nodes), GFP_KERNEL);
+ kzalloc_objs(*nodes, 1 + nbuttons);
if (!nodes)
return -ENOMEM;
struct software_node_ref_args *ref_args __free(kfree) =
- kcalloc(nbuttons, sizeof(*ref_args), GFP_KERNEL);
+ kzalloc_objs(*ref_args, nbuttons);
if (!ref_args)
return -ENOMEM;
diff --git a/arch/powerpc/sysdev/xive/common.c b/arch/powerpc/sysdev/xive/common.c
index 8ae088632337..ed3d3e26c136 100644
--- a/arch/powerpc/sysdev/xive/common.c
+++ b/arch/powerpc/sysdev/xive/common.c
@@ -1134,7 +1134,7 @@ static int __init xive_init_ipis(void)
if (!ipi_domain)
goto out_free_fwnode;
- xive_ipis = kzalloc_objs(*xive_ipis, nr_node_ids, GFP_KERNEL);
+ xive_ipis = kzalloc_objs(*xive_ipis, nr_node_ids);
if (!xive_ipis)
goto out_free_domain;
diff --git a/arch/riscv/kvm/vcpu_pmu.c b/arch/riscv/kvm/vcpu_pmu.c
index 752f1014d633..6ff741ee7803 100644
--- a/arch/riscv/kvm/vcpu_pmu.c
+++ b/arch/riscv/kvm/vcpu_pmu.c
@@ -503,8 +503,8 @@ int kvm_riscv_vcpu_pmu_event_info(struct kvm_vcpu *vcpu, unsigned long saddr_low
}
}
- einfo = kvcalloc(num_events, sizeof(*einfo),
- GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
+ einfo = kvzalloc_objs(*einfo, num_events,
+ GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
if (!einfo) {
ret = SBI_ERR_FAILURE;
goto out;
diff --git a/arch/s390/kvm/s390/s390.c b/arch/s390/kvm/s390/s390.c
index b0839e887221..5c73f43782a7 100644
--- a/arch/s390/kvm/s390/s390.c
+++ b/arch/s390/kvm/s390/s390.c
@@ -2168,7 +2168,7 @@ static int kvm_s390_get_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX)
return -EINVAL;
- keys = kvmalloc_array(args->count, sizeof(*keys), GFP_KERNEL_ACCOUNT);
+ keys = kvmalloc_objs(*keys, args->count, GFP_KERNEL_ACCOUNT);
if (!keys)
return -ENOMEM;
@@ -2205,7 +2205,7 @@ static int kvm_s390_set_skeys(struct kvm *kvm, struct kvm_s390_skeys *args)
if (args->count < 1 || args->count > KVM_S390_SKEYS_MAX)
return -EINVAL;
- keys = kvmalloc_array(args->count, sizeof(*keys), GFP_KERNEL_ACCOUNT);
+ keys = kvmalloc_objs(*keys, args->count, GFP_KERNEL_ACCOUNT);
if (!keys)
return -ENOMEM;