linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] binfmt: Use struct_size()
@ 2023-05-28 16:20 Christophe JAILLET
  2023-05-28 16:20 ` [PATCH 2/2] binfmt: Slightly simplify elf_fdpic_map_file() Christophe JAILLET
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Christophe JAILLET @ 2023-05-28 16:20 UTC (permalink / raw)
  To: Alexander Viro, Christian Brauner, Eric Biederman, Kees Cook
  Cc: linux-kernel, kernel-janitors, Christophe JAILLET, linux-fsdevel,
	linux-mm

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>
---
Compile tested on arm
---
 fs/binfmt_elf_fdpic.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/fs/binfmt_elf_fdpic.c b/fs/binfmt_elf_fdpic.c
index d76ad3d4f676..237ce388d06d 100644
--- a/fs/binfmt_elf_fdpic.c
+++ b/fs/binfmt_elf_fdpic.c
@@ -748,7 +748,6 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
 	struct elf32_phdr *phdr;
 	unsigned long load_addr, stop;
 	unsigned nloads, tmp;
-	size_t size;
 	int loop, ret;
 
 	/* allocate a load map table */
@@ -760,8 +759,7 @@ static int elf_fdpic_map_file(struct elf_fdpic_params *params,
 	if (nloads == 0)
 		return -ELIBBAD;
 
-	size = sizeof(*loadmap) + nloads * sizeof(*seg);
-	loadmap = kzalloc(size, GFP_KERNEL);
+	loadmap = kzalloc(struct_size(loadmap, segs, nloads), GFP_KERNEL);
 	if (!loadmap)
 		return -ENOMEM;
 
-- 
2.34.1



^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-05-30 22:52 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-28 16:20 [PATCH 1/2] binfmt: Use struct_size() Christophe JAILLET
2023-05-28 16:20 ` [PATCH 2/2] binfmt: Slightly simplify elf_fdpic_map_file() Christophe JAILLET
2023-05-28 16:34   ` Eric W. Biederman
2023-05-28 16:32 ` [PATCH 1/2] binfmt: Use struct_size() Eric W. Biederman
2023-05-30 22:52 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox