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 /ipc/mqueue.c | |
| 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 'ipc/mqueue.c')
| -rw-r--r-- | ipc/mqueue.c | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/ipc/mqueue.c b/ipc/mqueue.c index bb7c9e5d2b90..a90aa6803f1b 100644 --- a/ipc/mqueue.c +++ b/ipc/mqueue.c @@ -210,7 +210,7 @@ static int msg_insert(struct msg_msg *msg, struct mqueue_inode_info *info) leaf = info->node_cache; info->node_cache = NULL; } else { - leaf = kmalloc(sizeof(*leaf), GFP_ATOMIC); + leaf = kmalloc_obj(*leaf, GFP_ATOMIC); if (!leaf) return -ENOMEM; INIT_LIST_HEAD(&leaf->msg_list); @@ -449,7 +449,7 @@ static int mqueue_init_fs_context(struct fs_context *fc) { struct mqueue_fs_context *ctx; - ctx = kzalloc(sizeof(struct mqueue_fs_context), GFP_KERNEL); + ctx = kzalloc_obj(struct mqueue_fs_context, GFP_KERNEL); if (!ctx) return -ENOMEM; @@ -1088,7 +1088,7 @@ static int do_mq_timedsend(mqd_t mqdes, const char __user *u_msg_ptr, * fall back to that if necessary. */ if (!info->node_cache) - new_leaf = kmalloc(sizeof(*new_leaf), GFP_KERNEL); + new_leaf = kmalloc_obj(*new_leaf, GFP_KERNEL); spin_lock(&info->lock); @@ -1181,7 +1181,7 @@ static int do_mq_timedreceive(mqd_t mqdes, char __user *u_msg_ptr, * fall back to that if necessary. */ if (!info->node_cache) - new_leaf = kmalloc(sizeof(*new_leaf), GFP_KERNEL); + new_leaf = kmalloc_obj(*new_leaf, GFP_KERNEL); spin_lock(&info->lock); |
