summaryrefslogtreecommitdiff
path: root/security/tomoyo
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 /security/tomoyo
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 'security/tomoyo')
-rw-r--r--security/tomoyo/audit.c2
-rw-r--r--security/tomoyo/common.c4
-rw-r--r--security/tomoyo/domain.c2
3 files changed, 4 insertions, 4 deletions
diff --git a/security/tomoyo/audit.c b/security/tomoyo/audit.c
index 610c1536cf70..bfacb3f2e2ed 100644
--- a/security/tomoyo/audit.c
+++ b/security/tomoyo/audit.c
@@ -376,7 +376,7 @@ void tomoyo_write_log2(struct tomoyo_request_info *r, int len, const char *fmt,
buf = tomoyo_init_log(r, len, fmt, args);
if (!buf)
goto out;
- entry = kzalloc(sizeof(*entry), GFP_NOFS);
+ entry = kzalloc_obj(*entry, GFP_NOFS);
if (!entry) {
kfree(buf);
goto out;
diff --git a/security/tomoyo/common.c b/security/tomoyo/common.c
index 7e1f825d903b..fdaeaff01fc1 100644
--- a/security/tomoyo/common.c
+++ b/security/tomoyo/common.c
@@ -493,7 +493,7 @@ static struct tomoyo_profile *tomoyo_assign_profile
ptr = ns->profile_ptr[profile];
if (ptr)
return ptr;
- entry = kzalloc(sizeof(*entry), GFP_NOFS | __GFP_NOWARN);
+ entry = kzalloc_obj(*entry, GFP_NOFS | __GFP_NOWARN);
if (mutex_lock_interruptible(&tomoyo_policy_lock))
goto out;
ptr = ns->profile_ptr[profile];
@@ -2553,7 +2553,7 @@ static int tomoyo_write_stat(struct tomoyo_io_buffer *head)
*/
int tomoyo_open_control(const u8 type, struct file *file)
{
- struct tomoyo_io_buffer *head = kzalloc(sizeof(*head), GFP_NOFS);
+ struct tomoyo_io_buffer *head = kzalloc_obj(*head, GFP_NOFS);
if (!head)
return -ENOMEM;
diff --git a/security/tomoyo/domain.c b/security/tomoyo/domain.c
index 0612eac7f2f2..eeaad421f15b 100644
--- a/security/tomoyo/domain.c
+++ b/security/tomoyo/domain.c
@@ -708,7 +708,7 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
bool reject_on_transition_failure = false;
const struct tomoyo_path_info *candidate;
struct tomoyo_path_info exename;
- struct tomoyo_execve *ee = kzalloc(sizeof(*ee), GFP_NOFS);
+ struct tomoyo_execve *ee = kzalloc_obj(*ee, GFP_NOFS);
if (!ee)
return -ENOMEM;