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

@@ -109,11 +109,11 @@ struct xe_pt *xe_pt_create(struct xe_vm *vm, struct xe_tile *tile,
int err;
if (level) {
struct xe_pt_dir *dir = kzalloc(sizeof(*dir), GFP_KERNEL);
struct xe_pt_dir *dir = kzalloc_obj(*dir, GFP_KERNEL);
pt = (dir) ? &dir->pt : NULL;
} else {
pt = kzalloc(sizeof(*pt), GFP_KERNEL);
pt = kzalloc_obj(*pt, GFP_KERNEL);
}
if (!pt)
return ERR_PTR(-ENOMEM);
@@ -368,9 +368,8 @@ xe_pt_new_shared(struct xe_walk_update *wupd, struct xe_pt *parent,
entry->pt_bo->update_index = -1;
if (alloc_entries) {
entry->pt_entries = kmalloc_array(XE_PDES,
sizeof(*entry->pt_entries),
GFP_KERNEL);
entry->pt_entries = kmalloc_objs(*entry->pt_entries, XE_PDES,
GFP_KERNEL);
if (!entry->pt_entries)
return -ENOMEM;
}
@@ -2574,7 +2573,7 @@ xe_pt_update_ops_run(struct xe_tile *tile, struct xe_vma_ops *vops)
}
}
rfence = kzalloc(sizeof(*rfence), GFP_KERNEL);
rfence = kzalloc_obj(*rfence, GFP_KERNEL);
if (!rfence) {
err = -ENOMEM;
goto free_ijob;