Skip to content

Commit e6302d5

Browse files
tititiou36kees
authored andcommitted
binfmt: Use struct_size()
Use struct_size() instead of hand-writing it. It is less verbose, more robust and more informative. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Acked-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Kees Cook <keescook@chromium.org> Link: https://lore.kernel.org/r/53150beae5dc04dac513dba391a2e4ae8696a7f3.1685290790.git.christophe.jaillet@wanadoo.fr
1 parent 60592fb commit e6302d5

1 file changed

Lines changed: 1 addition & 3 deletions

File tree

fs/binfmt_elf_fdpic.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,6 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
748748
struct elf32_phdr *phdr;
749749
unsigned long load_addr, stop;
750750
unsigned nloads, tmp;
751-
size_t size;
752751
int loop, ret;
753752

754753
/* allocate a load map table */
@@ -760,8 +759,7 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
760759
if (nloads == 0)
761760
return -ELIBBAD;
762761

763-
size = sizeof(*loadmap) + nloads * sizeof(*seg);
764-
loadmap = kzalloc(size, GFP_KERNEL);
762+
loadmap = kzalloc(struct_size(loadmap, segs, nloads), GFP_KERNEL);
765763
if (!loadmap)
766764
return -ENOMEM;
767765

0 commit comments

Comments
 (0)