summaryrefslogtreecommitdiff
path: root/arch/s390/kernel
diff options
context:
space:
mode:
authorKees Cook <kees@kernel.org>2026-02-20 23:49:23 -0800
committerKees Cook <kees@kernel.org>2026-02-21 01:02:28 -0800
commit69050f8d6d075dc01af7a5f2f550a8067510366f (patch)
treebb265f94d9dfa7876c06a5d9f88673d496a15341 /arch/s390/kernel
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (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 'arch/s390/kernel')
-rw-r--r--arch/s390/kernel/cert_store.c2
-rw-r--r--arch/s390/kernel/debug.c15
-rw-r--r--arch/s390/kernel/guarded_storage.c4
-rw-r--r--arch/s390/kernel/irq.c2
-rw-r--r--arch/s390/kernel/os_info.c2
-rw-r--r--arch/s390/kernel/perf_cpum_cf.c4
-rw-r--r--arch/s390/kernel/perf_cpum_cf_events.c2
-rw-r--r--arch/s390/kernel/perf_cpum_sf.c2
-rw-r--r--arch/s390/kernel/perf_pai.c14
-rw-r--r--arch/s390/kernel/ptrace.c6
-rw-r--r--arch/s390/kernel/runtime_instr.c2
-rw-r--r--arch/s390/kernel/smp.c2
-rw-r--r--arch/s390/kernel/vdso.c2
13 files changed, 29 insertions, 30 deletions
diff --git a/arch/s390/kernel/cert_store.c b/arch/s390/kernel/cert_store.c
index c217a5e64094..8e3964c33ebb 100644
--- a/arch/s390/kernel/cert_store.c
+++ b/arch/s390/kernel/cert_store.c
@@ -322,7 +322,7 @@ static int invalidate_keyring_keys(struct key *keyring)
keyring_payload_len = key_type_keyring.read(keyring, NULL, 0);
num_keys = keyring_payload_len / sizeof(key_serial_t);
- key_array = kcalloc(num_keys, sizeof(key_serial_t), GFP_KERNEL);
+ key_array = kzalloc_objs(key_serial_t, num_keys, GFP_KERNEL);
if (!key_array)
return -ENOMEM;
diff --git a/arch/s390/kernel/debug.c b/arch/s390/kernel/debug.c
index e722243841f8..a917b4c899ef 100644
--- a/arch/s390/kernel/debug.c
+++ b/arch/s390/kernel/debug.c
@@ -181,14 +181,13 @@ static debug_entry_t ***debug_areas_alloc(int pages_per_area, int nr_areas)
debug_entry_t ***areas;
int i, j;
- areas = kmalloc_array(nr_areas, sizeof(debug_entry_t **), GFP_KERNEL);
+ areas = kmalloc_objs(debug_entry_t **, nr_areas, GFP_KERNEL);
if (!areas)
goto fail_malloc_areas;
for (i = 0; i < nr_areas; i++) {
/* GFP_NOWARN to avoid user triggerable WARN, we handle fails */
- areas[i] = kmalloc_array(pages_per_area,
- sizeof(debug_entry_t *),
- GFP_KERNEL | __GFP_NOWARN);
+ areas[i] = kmalloc_objs(debug_entry_t *, pages_per_area,
+ GFP_KERNEL | __GFP_NOWARN);
if (!areas[i])
goto fail_malloc_areas2;
for (j = 0; j < pages_per_area; j++) {
@@ -225,13 +224,13 @@ static debug_info_t *debug_info_alloc(const char *name, int pages_per_area,
debug_info_t *rc;
/* alloc everything */
- rc = kmalloc(sizeof(debug_info_t), GFP_KERNEL);
+ rc = kmalloc_obj(debug_info_t, GFP_KERNEL);
if (!rc)
goto fail_malloc_rc;
- rc->active_entries = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
+ rc->active_entries = kzalloc_objs(int, nr_areas, GFP_KERNEL);
if (!rc->active_entries)
goto fail_malloc_active_entries;
- rc->active_pages = kcalloc(nr_areas, sizeof(int), GFP_KERNEL);
+ rc->active_pages = kzalloc_objs(int, nr_areas, GFP_KERNEL);
if (!rc->active_pages)
goto fail_malloc_active_pages;
if ((mode == ALL_AREAS) && (pages_per_area != 0)) {
@@ -631,7 +630,7 @@ static file_private_info_t *debug_file_private_alloc(debug_info_t *debug_info,
if (!debug_info_snapshot)
return NULL;
- p_info = kmalloc(sizeof(file_private_info_t), GFP_KERNEL);
+ p_info = kmalloc_obj(file_private_info_t, GFP_KERNEL);
if (!p_info) {
debug_info_free(debug_info_snapshot);
return NULL;
diff --git a/arch/s390/kernel/guarded_storage.c b/arch/s390/kernel/guarded_storage.c
index cf26d7a37425..4d4101f19e3c 100644
--- a/arch/s390/kernel/guarded_storage.c
+++ b/arch/s390/kernel/guarded_storage.c
@@ -24,7 +24,7 @@ static int gs_enable(void)
struct gs_cb *gs_cb;
if (!current->thread.gs_cb) {
- gs_cb = kzalloc(sizeof(*gs_cb), GFP_KERNEL);
+ gs_cb = kzalloc_obj(*gs_cb, GFP_KERNEL);
if (!gs_cb)
return -ENOMEM;
gs_cb->gsd = 25;
@@ -55,7 +55,7 @@ static int gs_set_bc_cb(struct gs_cb __user *u_gs_cb)
gs_cb = current->thread.gs_bc_cb;
if (!gs_cb) {
- gs_cb = kzalloc(sizeof(*gs_cb), GFP_KERNEL);
+ gs_cb = kzalloc_obj(*gs_cb, GFP_KERNEL);
if (!gs_cb)
return -ENOMEM;
current->thread.gs_bc_cb = gs_cb;
diff --git a/arch/s390/kernel/irq.c b/arch/s390/kernel/irq.c
index bdf9c7cb5685..f81723bc8856 100644
--- a/arch/s390/kernel/irq.c
+++ b/arch/s390/kernel/irq.c
@@ -312,7 +312,7 @@ int register_external_irq(u16 code, ext_int_handler_t handler)
unsigned long flags;
int index;
- p = kmalloc(sizeof(*p), GFP_ATOMIC);
+ p = kmalloc_obj(*p, GFP_ATOMIC);
if (!p)
return -ENOMEM;
p->code = code;
diff --git a/arch/s390/kernel/os_info.c b/arch/s390/kernel/os_info.c
index 94fa44776d0c..37ab1c671b4d 100644
--- a/arch/s390/kernel/os_info.c
+++ b/arch/s390/kernel/os_info.c
@@ -154,7 +154,7 @@ static void os_info_old_init(void)
goto fail;
if (addr == 0 || addr % PAGE_SIZE)
goto fail;
- os_info_old = kzalloc(sizeof(*os_info_old), GFP_KERNEL);
+ os_info_old = kzalloc_obj(*os_info_old, GFP_KERNEL);
if (!os_info_old)
goto fail;
if (copy_oldmem_kernel(os_info_old, addr, sizeof(*os_info_old)))
diff --git a/arch/s390/kernel/perf_cpum_cf.c b/arch/s390/kernel/perf_cpum_cf.c
index 408ab93112bf..0c4074e717d4 100644
--- a/arch/s390/kernel/perf_cpum_cf.c
+++ b/arch/s390/kernel/perf_cpum_cf.c
@@ -252,7 +252,7 @@ static int cpum_cf_alloc_cpu(int cpu)
cpuhw = p->cpucf;
if (!cpuhw) {
- cpuhw = kzalloc(sizeof(*cpuhw), GFP_KERNEL);
+ cpuhw = kzalloc_obj(*cpuhw, GFP_KERNEL);
if (cpuhw) {
p->cpucf = cpuhw;
refcount_set(&cpuhw->refcnt, 1);
@@ -1616,7 +1616,7 @@ static long cfset_ioctl_start(unsigned long arg, struct file *file)
if (!start.counter_sets)
return -EINVAL; /* No counter set at all? */
- preq = kzalloc(sizeof(*preq), GFP_KERNEL);
+ preq = kzalloc_obj(*preq, GFP_KERNEL);
if (!preq)
return -ENOMEM;
cpumask_clear(&preq->mask);
diff --git a/arch/s390/kernel/perf_cpum_cf_events.c b/arch/s390/kernel/perf_cpum_cf_events.c
index 7ace1f9e4ccf..eb067beb5c51 100644
--- a/arch/s390/kernel/perf_cpum_cf_events.c
+++ b/arch/s390/kernel/perf_cpum_cf_events.c
@@ -976,7 +976,7 @@ static __init struct attribute **merge_attr(struct attribute **a,
j++;
j++;
- new = kmalloc_array(j, sizeof(struct attribute *), GFP_KERNEL);
+ new = kmalloc_objs(struct attribute *, j, GFP_KERNEL);
if (!new)
return NULL;
j = 0;
diff --git a/arch/s390/kernel/perf_cpum_sf.c b/arch/s390/kernel/perf_cpum_sf.c
index e8bd19ac82c7..d0adeabfce0c 100644
--- a/arch/s390/kernel/perf_cpum_sf.c
+++ b/arch/s390/kernel/perf_cpum_sf.c
@@ -1609,7 +1609,7 @@ static void *aux_buffer_setup(struct perf_event *event, void **pages,
}
/* Allocate aux_buffer struct for the event */
- aux = kzalloc(sizeof(struct aux_buffer), GFP_KERNEL);
+ aux = kzalloc_obj(struct aux_buffer, GFP_KERNEL);
if (!aux)
goto no_aux;
sfb = &aux->sfb;
diff --git a/arch/s390/kernel/perf_pai.c b/arch/s390/kernel/perf_pai.c
index 810f5b6c5e01..4c2ce0a2a8e4 100644
--- a/arch/s390/kernel/perf_pai.c
+++ b/arch/s390/kernel/perf_pai.c
@@ -252,7 +252,7 @@ static int pai_alloc_cpu(struct perf_event *event, int cpu)
cpump = mp->mapptr;
if (!cpump) { /* Paicrypt_map allocated? */
rc = -ENOMEM;
- cpump = kzalloc(sizeof(*cpump), GFP_KERNEL);
+ cpump = kzalloc_obj(*cpump, GFP_KERNEL);
if (!cpump)
goto undo;
/* Allocate memory for counter page and counter extraction.
@@ -281,9 +281,9 @@ static int pai_alloc_cpu(struct perf_event *event, int cpu)
cpump->paiext_cb = kzalloc(PAIE1_CB_SZ, GFP_KERNEL);
need_paiext_cb = true;
}
- cpump->save = kvmalloc_array(pai_pmu[idx].num_avail + 1,
- sizeof(struct pai_userdata),
- GFP_KERNEL);
+ cpump->save = kvmalloc_objs(struct pai_userdata,
+ pai_pmu[idx].num_avail + 1,
+ GFP_KERNEL);
if (!cpump->area || !cpump->save ||
(need_paiext_cb && !cpump->paiext_cb)) {
pai_free(mp);
@@ -315,7 +315,7 @@ static int pai_alloc(struct perf_event *event)
struct cpumask *maskptr;
int cpu, rc = -ENOMEM;
- maskptr = kzalloc(sizeof(*maskptr), GFP_KERNEL);
+ maskptr = kzalloc_obj(*maskptr, GFP_KERNEL);
if (!maskptr)
goto out;
@@ -1070,7 +1070,7 @@ static struct attribute * __init attr_event_init_one(int num,
{
struct perf_pmu_events_attr *pa;
- pa = kzalloc(sizeof(*pa), GFP_KERNEL);
+ pa = kzalloc_obj(*pa, GFP_KERNEL);
if (!pa)
return NULL;
@@ -1089,7 +1089,7 @@ static struct attribute ** __init attr_event_init(struct pai_pmu *p)
struct attribute **attrs;
unsigned int i;
- attrs = kmalloc_array(min_attr + 1, sizeof(*attrs), GFP_KERNEL | __GFP_ZERO);
+ attrs = kmalloc_objs(*attrs, min_attr + 1, GFP_KERNEL | __GFP_ZERO);
if (!attrs)
goto out;
for (i = 0; i < min_attr; i++) {
diff --git a/arch/s390/kernel/ptrace.c b/arch/s390/kernel/ptrace.c
index ceaa1726e328..3a08f8f6c865 100644
--- a/arch/s390/kernel/ptrace.c
+++ b/arch/s390/kernel/ptrace.c
@@ -749,7 +749,7 @@ static int s390_gs_cb_set(struct task_struct *target,
if (!cpu_has_gs())
return -ENODEV;
if (!target->thread.gs_cb) {
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return -ENOMEM;
}
@@ -800,7 +800,7 @@ static int s390_gs_bc_set(struct task_struct *target,
if (!cpu_has_gs())
return -ENODEV;
if (!data) {
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return -ENOMEM;
target->thread.gs_bc_cb = data;
@@ -861,7 +861,7 @@ static int s390_runtime_instr_set(struct task_struct *target,
return -ENODEV;
if (!target->thread.ri_cb) {
- data = kzalloc(sizeof(*data), GFP_KERNEL);
+ data = kzalloc_obj(*data, GFP_KERNEL);
if (!data)
return -ENOMEM;
}
diff --git a/arch/s390/kernel/runtime_instr.c b/arch/s390/kernel/runtime_instr.c
index 1788a5454b6f..0331ee7af39d 100644
--- a/arch/s390/kernel/runtime_instr.c
+++ b/arch/s390/kernel/runtime_instr.c
@@ -83,7 +83,7 @@ SYSCALL_DEFINE2(s390_runtime_instr, int, command, int, signum)
return -EINVAL;
if (!current->thread.ri_cb) {
- cb = kzalloc(sizeof(*cb), GFP_KERNEL);
+ cb = kzalloc_obj(*cb, GFP_KERNEL);
if (!cb)
return -ENOMEM;
} else {
diff --git a/arch/s390/kernel/smp.c b/arch/s390/kernel/smp.c
index eb334539444a..615b76a7f2a0 100644
--- a/arch/s390/kernel/smp.c
+++ b/arch/s390/kernel/smp.c
@@ -1145,7 +1145,7 @@ int __ref smp_rescan_cpus(bool early)
struct sclp_core_info *info;
int nr;
- info = kzalloc(sizeof(*info), GFP_KERNEL);
+ info = kzalloc_obj(*info, GFP_KERNEL);
if (!info)
return -ENOMEM;
smp_get_core_info(info, 0);
diff --git a/arch/s390/kernel/vdso.c b/arch/s390/kernel/vdso.c
index a27a90a199be..1838a4696747 100644
--- a/arch/s390/kernel/vdso.c
+++ b/arch/s390/kernel/vdso.c
@@ -132,7 +132,7 @@ static struct page ** __init vdso_setup_pages(void *start, void *end)
struct page **pagelist;
int i;
- pagelist = kcalloc(pages + 1, sizeof(struct page *), GFP_KERNEL);
+ pagelist = kzalloc_objs(struct page *, pages + 1, GFP_KERNEL);
if (!pagelist)
panic("%s: Cannot allocate page list for VDSO", __func__);
for (i = 0; i < pages; i++)