summaryrefslogtreecommitdiff
path: root/kernel/cgroup/cpuset.c
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 /kernel/cgroup/cpuset.c
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 'kernel/cgroup/cpuset.c')
-rw-r--r--kernel/cgroup/cpuset.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/kernel/cgroup/cpuset.c b/kernel/cgroup/cpuset.c
index 7607dfe516e6..384d9d6e323b 100644
--- a/kernel/cgroup/cpuset.c
+++ b/kernel/cgroup/cpuset.c
@@ -536,7 +536,7 @@ static struct cpuset *dup_or_alloc_cpuset(struct cpuset *cs)
/* Allocate base structure */
trial = cs ? kmemdup(cs, sizeof(*cs), GFP_KERNEL) :
- kzalloc(sizeof(*cs), GFP_KERNEL);
+ kzalloc_obj(*cs, GFP_KERNEL);
if (!trial)
return NULL;
@@ -791,7 +791,7 @@ static int generate_sched_domains(cpumask_var_t **domains,
goto generate_doms;
}
- csa = kmalloc_array(nr_cpusets(), sizeof(cp), GFP_KERNEL);
+ csa = kmalloc_objs(cp, nr_cpusets(), GFP_KERNEL);
if (!csa)
goto done;
@@ -835,8 +835,7 @@ generate_doms:
* The rest of the code, including the scheduler, can deal with
* dattr==NULL case. No need to abort if alloc fails.
*/
- dattr = kmalloc_array(ndoms, sizeof(struct sched_domain_attr),
- GFP_KERNEL);
+ dattr = kmalloc_objs(struct sched_domain_attr, ndoms, GFP_KERNEL);
/*
* Cgroup v2 doesn't support domain attributes, just set all of them
@@ -2479,7 +2478,7 @@ static void cpuset_migrate_mm(struct mm_struct *mm, const nodemask_t *from,
return;
}
- mwork = kzalloc(sizeof(*mwork), GFP_KERNEL);
+ mwork = kzalloc_obj(*mwork, GFP_KERNEL);
if (mwork) {
mwork->mm = mm;
mwork->from = *from;
@@ -2501,7 +2500,7 @@ static void schedule_flush_migrate_mm(void)
{
struct callback_head *flush_cb;
- flush_cb = kzalloc(sizeof(struct callback_head), GFP_KERNEL);
+ flush_cb = kzalloc_obj(struct callback_head, GFP_KERNEL);
if (!flush_cb)
return;