Commit e6302d5a authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Kees Cook

binfmt: Use struct_size()

Use struct_size() instead of hand-writing it. It is less verbose, more
robust and more informative.
Signed-off-by: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Acked-by: default avatar"Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: default avatarKees Cook <keescook@chromium.org>
Link: https://lore.kernel.org/r/53150beae5dc04dac513dba391a2e4ae8696a7f3.1685290790.git.christophe.jaillet@wanadoo.fr
parent 60592fb6
...@@ -748,7 +748,6 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, ...@@ -748,7 +748,6 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
struct elf32_phdr *phdr; struct elf32_phdr *phdr;
unsigned long load_addr, stop; unsigned long load_addr, stop;
unsigned nloads, tmp; unsigned nloads, tmp;
size_t size;
int loop, ret; int loop, ret;
/* allocate a load map table */ /* allocate a load map table */
...@@ -760,8 +759,7 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params, ...@@ -760,8 +759,7 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
if (nloads == 0) if (nloads == 0)
return -ELIBBAD; return -ELIBBAD;
size = sizeof(*loadmap) + nloads * sizeof(*seg); loadmap = kzalloc(struct_size(loadmap, segs, nloads), GFP_KERNEL);
loadmap = kzalloc(size, GFP_KERNEL);
if (!loadmap) if (!loadmap)
return -ENOMEM; return -ENOMEM;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment