summaryrefslogtreecommitdiff
path: root/fs/binfmt_elf_fdpic.c
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/binfmt_elf_fdpic.c
parentd39a1d7486d98668dd34aaa6732aad7977c45f5a (diff)
downloadlinux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.tar.gz
linux-next-69050f8d6d075dc01af7a5f2f550a8067510366f.zip
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/binfmt_elf_fdpic.c')
-rw-r--r--fs/binfmt_elf_fdpic.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index 48fd2de3bca0..cee0871b0164 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -761,7 +761,7 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
if (nloads == 0)
return -ELIBBAD;
- loadmap = kzalloc(struct_size(loadmap, segs, nloads), GFP_KERNEL);
+ loadmap = kzalloc_flex(*loadmap, segs, nloads, GFP_KERNEL);
if (!loadmap)
return -ENOMEM;
@@ -1391,7 +1391,7 @@ static struct elf_thread_status *elf_dump_thread_status(long signr, struct task_
struct elf_thread_status *t;
int i, ret;
- t = kzalloc(sizeof(struct elf_thread_status), GFP_KERNEL);
+ t = kzalloc_obj(struct elf_thread_status, GFP_KERNEL);
if (!t)
return t;
@@ -1486,10 +1486,10 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
struct elf_thread_status *tmp;
/* alloc memory for large data structures: too large to be on stack */
- elf = kmalloc(sizeof(*elf), GFP_KERNEL);
+ elf = kmalloc_obj(*elf, GFP_KERNEL);
if (!elf)
goto end_coredump;
- psinfo = kmalloc(sizeof(*psinfo), GFP_KERNEL);
+ psinfo = kmalloc_obj(*psinfo, GFP_KERNEL);
if (!psinfo)
goto end_coredump;
@@ -1547,7 +1547,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
offset += segs * sizeof(struct elf_phdr); /* Program headers */
/* Write notes phdr entry */
- phdr4note = kmalloc(sizeof(*phdr4note), GFP_KERNEL);
+ phdr4note = kmalloc_obj(*phdr4note, GFP_KERNEL);
if (!phdr4note)
goto end_coredump;
@@ -1562,7 +1562,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
e_shoff = offset;
if (e_phnum == PN_XNUM) {
- shdr4extnum = kmalloc(sizeof(*shdr4extnum), GFP_KERNEL);
+ shdr4extnum = kmalloc_obj(*shdr4extnum, GFP_KERNEL);
if (!shdr4extnum)
goto end_coredump;
fill_extnum_info(elf, shdr4extnum, e_shoff, segs);