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>
This commit is contained in:
Kees Cook
2026-02-20 23:49:23 -08:00
parent d39a1d7486
commit 69050f8d6d
8016 changed files with 20055 additions and 20913 deletions

View File

@@ -1903,7 +1903,7 @@ static int guc_exec_queue_init(struct xe_exec_queue *q)
xe_gt_assert(guc_to_gt(guc), xe_device_uc_enabled(guc_to_xe(guc)));
ge = kzalloc(sizeof(*ge), GFP_KERNEL);
ge = kzalloc_obj(*ge, GFP_KERNEL);
if (!ge)
return -ENOMEM;
@@ -2057,7 +2057,7 @@ static int guc_exec_queue_set_priority(struct xe_exec_queue *q,
exec_queue_killed_or_banned_or_wedged(q))
return 0;
msg = kmalloc(sizeof(*msg), GFP_KERNEL);
msg = kmalloc_obj(*msg, GFP_KERNEL);
if (!msg)
return -ENOMEM;
@@ -2075,7 +2075,7 @@ static int guc_exec_queue_set_timeslice(struct xe_exec_queue *q, u32 timeslice_u
exec_queue_killed_or_banned_or_wedged(q))
return 0;
msg = kmalloc(sizeof(*msg), GFP_KERNEL);
msg = kmalloc_obj(*msg, GFP_KERNEL);
if (!msg)
return -ENOMEM;
@@ -2094,7 +2094,7 @@ static int guc_exec_queue_set_preempt_timeout(struct xe_exec_queue *q,
exec_queue_killed_or_banned_or_wedged(q))
return 0;
msg = kmalloc(sizeof(*msg), GFP_KERNEL);
msg = kmalloc_obj(*msg, GFP_KERNEL);
if (!msg)
return -ENOMEM;
@@ -2115,7 +2115,7 @@ static int guc_exec_queue_set_multi_queue_priority(struct xe_exec_queue *q,
exec_queue_killed_or_banned_or_wedged(q))
return 0;
msg = kmalloc(sizeof(*msg), GFP_KERNEL);
msg = kmalloc_obj(*msg, GFP_KERNEL);
if (!msg)
return -ENOMEM;
@@ -3128,7 +3128,7 @@ xe_guc_exec_queue_snapshot_capture(struct xe_exec_queue *q)
struct xe_guc_submit_exec_queue_snapshot *snapshot;
int i;
snapshot = kzalloc(sizeof(*snapshot), GFP_ATOMIC);
snapshot = kzalloc_obj(*snapshot, GFP_ATOMIC);
if (!snapshot)
return NULL;
@@ -3144,8 +3144,8 @@ xe_guc_exec_queue_snapshot_capture(struct xe_exec_queue *q)
snapshot->sched_props.preempt_timeout_us =
q->sched_props.preempt_timeout_us;
snapshot->lrc = kmalloc_array(q->width, sizeof(struct xe_lrc_snapshot *),
GFP_ATOMIC);
snapshot->lrc = kmalloc_objs(struct xe_lrc_snapshot *, q->width,
GFP_ATOMIC);
if (snapshot->lrc) {
for (i = 0; i < q->width; ++i) {