summaryrefslogtreecommitdiff
path: root/fs/resctrl
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 /fs/resctrl
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 'fs/resctrl')
-rw-r--r--fs/resctrl/monitor.c2
-rw-r--r--fs/resctrl/pseudo_lock.c4
-rw-r--r--fs/resctrl/rdtgroup.c8
3 files changed, 7 insertions, 7 deletions
diff --git a/fs/resctrl/monitor.c b/fs/resctrl/monitor.c
index 0cd5476a483a..6fd5c0e8a0dd 100644
--- a/fs/resctrl/monitor.c
+++ b/fs/resctrl/monitor.c
@@ -923,7 +923,7 @@ int setup_rmid_lru_list(void)
return 0;
idx_limit = resctrl_arch_system_num_rmid_idx();
- rmid_ptrs = kcalloc(idx_limit, sizeof(struct rmid_entry), GFP_KERNEL);
+ rmid_ptrs = kzalloc_objs(struct rmid_entry, idx_limit, GFP_KERNEL);
if (!rmid_ptrs)
return -ENOMEM;
diff --git a/fs/resctrl/pseudo_lock.c b/fs/resctrl/pseudo_lock.c
index e81d71abfe54..55e71d257324 100644
--- a/fs/resctrl/pseudo_lock.c
+++ b/fs/resctrl/pseudo_lock.c
@@ -154,7 +154,7 @@ static int pseudo_lock_cstates_constrain(struct pseudo_lock_region *plr)
int ret;
for_each_cpu(cpu, &plr->d->hdr.cpu_mask) {
- pm_req = kzalloc(sizeof(*pm_req), GFP_KERNEL);
+ pm_req = kzalloc_obj(*pm_req, GFP_KERNEL);
if (!pm_req) {
rdt_last_cmd_puts("Failure to allocate memory for PM QoS\n");
ret = -ENOMEM;
@@ -270,7 +270,7 @@ static int pseudo_lock_init(struct rdtgroup *rdtgrp)
{
struct pseudo_lock_region *plr;
- plr = kzalloc(sizeof(*plr), GFP_KERNEL);
+ plr = kzalloc_obj(*plr, GFP_KERNEL);
if (!plr)
return -ENOMEM;
diff --git a/fs/resctrl/rdtgroup.c b/fs/resctrl/rdtgroup.c
index ba8d503551cd..1135208adafb 100644
--- a/fs/resctrl/rdtgroup.c
+++ b/fs/resctrl/rdtgroup.c
@@ -2686,7 +2686,7 @@ static int schemata_list_add(struct rdt_resource *r, enum resctrl_conf_type type
const char *suffix = "";
int ret, cl;
- s = kzalloc(sizeof(*s), GFP_KERNEL);
+ s = kzalloc_obj(*s, GFP_KERNEL);
if (!s)
return -ENOMEM;
@@ -2966,7 +2966,7 @@ static int rdt_init_fs_context(struct fs_context *fc)
{
struct rdt_fs_context *ctx;
- ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
+ ctx = kzalloc_obj(*ctx, GFP_KERNEL);
if (!ctx)
return -ENOMEM;
@@ -3117,7 +3117,7 @@ static struct mon_data *mon_get_kn_priv(enum resctrl_res_level rid, int domid,
return priv;
}
- priv = kzalloc(sizeof(*priv), GFP_KERNEL);
+ priv = kzalloc_obj(*priv, GFP_KERNEL);
if (!priv)
return NULL;
@@ -3753,7 +3753,7 @@ static int mkdir_rdt_prepare(struct kernfs_node *parent_kn,
}
/* allocate the rdtgroup. */
- rdtgrp = kzalloc(sizeof(*rdtgrp), GFP_KERNEL);
+ rdtgrp = kzalloc_obj(*rdtgrp, GFP_KERNEL);
if (!rdtgrp) {
ret = -ENOSPC;
rdt_last_cmd_puts("Kernel out of memory\n");