diff options
| author | Kees Cook <kees@kernel.org> | 2026-02-20 23:49:23 -0800 |
|---|---|---|
| committer | Kees Cook <kees@kernel.org> | 2026-02-21 01:02:28 -0800 |
| commit | 69050f8d6d075dc01af7a5f2f550a8067510366f (patch) | |
| tree | bb265f94d9dfa7876c06a5d9f88673d496a15341 /drivers/perf | |
| parent | d39a1d7486d98668dd34aaa6732aad7977c45f5a (diff) | |
treewide: Replace kmalloc with kmalloc_obj for non-scalar types
This is the result of running the Coccinelle script from
scripts/coccinelle/api/kmalloc_objs.cocci. The script is designed to
avoid scalar types (which need careful case-by-case checking), and
instead replace kmalloc-family calls that allocate struct or union
object instances:
Single allocations: kmalloc(sizeof(TYPE), ...)
are replaced with: kmalloc_obj(TYPE, ...)
Array allocations: kmalloc_array(COUNT, sizeof(TYPE), ...)
are replaced with: kmalloc_objs(TYPE, COUNT, ...)
Flex array allocations: kmalloc(struct_size(PTR, FAM, COUNT), ...)
are replaced with: kmalloc_flex(*PTR, FAM, COUNT, ...)
(where TYPE may also be *VAR)
The resulting allocations no longer return "void *", instead returning
"TYPE *".
Signed-off-by: Kees Cook <kees@kernel.org>
Diffstat (limited to 'drivers/perf')
| -rw-r--r-- | drivers/perf/alibaba_uncore_drw_pmu.c | 2 | ||||
| -rw-r--r-- | drivers/perf/arm-cmn.c | 2 | ||||
| -rw-r--r-- | drivers/perf/arm_dmc620_pmu.c | 2 | ||||
| -rw-r--r-- | drivers/perf/arm_pmu.c | 2 | ||||
| -rw-r--r-- | drivers/perf/arm_spe_pmu.c | 2 | ||||
| -rw-r--r-- | drivers/perf/dwc_pcie_pmu.c | 2 | ||||
| -rw-r--r-- | drivers/perf/riscv_pmu.c | 2 | ||||
| -rw-r--r-- | drivers/perf/riscv_pmu_sbi.c | 5 |
8 files changed, 10 insertions, 9 deletions
diff --git a/drivers/perf/alibaba_uncore_drw_pmu.c b/drivers/perf/alibaba_uncore_drw_pmu.c index 99a0ef9817e0..3c5ec82f0454 100644 --- a/drivers/perf/alibaba_uncore_drw_pmu.c +++ b/drivers/perf/alibaba_uncore_drw_pmu.c @@ -431,7 +431,7 @@ static struct ali_drw_pmu_irq *__ali_drw_pmu_init_irq(struct platform_device return irq; } - irq = kzalloc(sizeof(*irq), GFP_KERNEL); + irq = kzalloc_obj(*irq, GFP_KERNEL); if (!irq) return ERR_PTR(-ENOMEM); diff --git a/drivers/perf/arm-cmn.c b/drivers/perf/arm-cmn.c index 4fbafc4b7984..dd87d29c395a 100644 --- a/drivers/perf/arm-cmn.c +++ b/drivers/perf/arm-cmn.c @@ -1700,7 +1700,7 @@ static int arm_cmn_validate_group(struct arm_cmn *cmn, struct perf_event *event) if (event->pmu != leader->pmu && !is_software_event(leader)) return -EINVAL; - val = kzalloc(sizeof(*val), GFP_KERNEL); + val = kzalloc_obj(*val, GFP_KERNEL); if (!val) return -ENOMEM; diff --git a/drivers/perf/arm_dmc620_pmu.c b/drivers/perf/arm_dmc620_pmu.c index 619cf937602f..3354ef908a56 100644 --- a/drivers/perf/arm_dmc620_pmu.c +++ b/drivers/perf/arm_dmc620_pmu.c @@ -432,7 +432,7 @@ static struct dmc620_pmu_irq *__dmc620_pmu_get_irq(int irq_num) if (irq->irq_num == irq_num && refcount_inc_not_zero(&irq->refcount)) return irq; - irq = kzalloc(sizeof(*irq), GFP_KERNEL); + irq = kzalloc_obj(*irq, GFP_KERNEL); if (!irq) return ERR_PTR(-ENOMEM); diff --git a/drivers/perf/arm_pmu.c b/drivers/perf/arm_pmu.c index 973a027d9063..5e7da5286d2c 100644 --- a/drivers/perf/arm_pmu.c +++ b/drivers/perf/arm_pmu.c @@ -864,7 +864,7 @@ struct arm_pmu *armpmu_alloc(void) struct arm_pmu *pmu; int cpu; - pmu = kzalloc(sizeof(*pmu), GFP_KERNEL); + pmu = kzalloc_obj(*pmu, GFP_KERNEL); if (!pmu) goto out; diff --git a/drivers/perf/arm_spe_pmu.c b/drivers/perf/arm_spe_pmu.c index 5410fb7428d0..eca2955693dc 100644 --- a/drivers/perf/arm_spe_pmu.c +++ b/drivers/perf/arm_spe_pmu.c @@ -1020,7 +1020,7 @@ static void *arm_spe_pmu_setup_aux(struct perf_event *event, void **pages, if (!buf) return NULL; - pglist = kcalloc(nr_pages, sizeof(*pglist), GFP_KERNEL); + pglist = kzalloc_objs(*pglist, nr_pages, GFP_KERNEL); if (!pglist) goto out_free_buf; diff --git a/drivers/perf/dwc_pcie_pmu.c b/drivers/perf/dwc_pcie_pmu.c index 22f73ac894e9..ceb039306bb6 100644 --- a/drivers/perf/dwc_pcie_pmu.c +++ b/drivers/perf/dwc_pcie_pmu.c @@ -649,7 +649,7 @@ static int dwc_pcie_register_dev(struct pci_dev *pdev) if (IS_ERR(plat_dev)) return PTR_ERR(plat_dev); - dev_info = kzalloc(sizeof(*dev_info), GFP_KERNEL); + dev_info = kzalloc_obj(*dev_info, GFP_KERNEL); if (!dev_info) { platform_device_unregister(plat_dev); return -ENOMEM; diff --git a/drivers/perf/riscv_pmu.c b/drivers/perf/riscv_pmu.c index 7644147d50b4..e5e43899ea74 100644 --- a/drivers/perf/riscv_pmu.c +++ b/drivers/perf/riscv_pmu.c @@ -389,7 +389,7 @@ struct riscv_pmu *riscv_pmu_alloc(void) int cpuid, i; struct cpu_hw_events *cpuc; - pmu = kzalloc(sizeof(*pmu), GFP_KERNEL); + pmu = kzalloc_obj(*pmu, GFP_KERNEL); if (!pmu) goto out; diff --git a/drivers/perf/riscv_pmu_sbi.c b/drivers/perf/riscv_pmu_sbi.c index 9dcc22fd48ef..09acac7ae073 100644 --- a/drivers/perf/riscv_pmu_sbi.c +++ b/drivers/perf/riscv_pmu_sbi.c @@ -309,7 +309,8 @@ static int pmu_sbi_check_event_info(void) int i, j, k, result = 0, count = 0; struct sbiret ret; - event_info_shmem = kcalloc(num_events, sizeof(*event_info_shmem), GFP_KERNEL); + event_info_shmem = kzalloc_objs(*event_info_shmem, num_events, + GFP_KERNEL); if (!event_info_shmem) return -ENOMEM; @@ -872,7 +873,7 @@ static int pmu_sbi_get_ctrinfo(int nctr, unsigned long *mask) int i, num_hw_ctr = 0, num_fw_ctr = 0; union sbi_pmu_ctr_info cinfo; - pmu_ctr_list = kcalloc(nctr, sizeof(*pmu_ctr_list), GFP_KERNEL); + pmu_ctr_list = kzalloc_objs(*pmu_ctr_list, nctr, GFP_KERNEL); if (!pmu_ctr_list) return -ENOMEM; |
