diff mbox series

binfmt_elf: simplify error handling in load_elf_phdrs()

Message ID 4137126.7Qn9TF0dmF@mobilepool36.emlix.com (mailing list archive)
State New
Headers show
Series binfmt_elf: simplify error handling in load_elf_phdrs() | expand

Commit Message

Rolf Eike Beer Oct. 19, 2022, 7:52 a.m. UTC
The err variable was the same like retval, but capped to <= 0. This is the
same as retval as elf_read() never returns positive values.

Signed-off-by: Rolf Eike Beer <eb@emlix.com>
---
 fs/binfmt_elf.c | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

Comments

Kees Cook Oct. 25, 2022, 10:24 p.m. UTC | #1
On Wed, 19 Oct 2022 09:52:16 +0200, Rolf Eike Beer wrote:
> The err variable was the same like retval, but capped to <= 0. This is the
> same as retval as elf_read() never returns positive values.

Applied to for-next/execve, thanks!

[1/1] binfmt_elf: simplify error handling in load_elf_phdrs()
      https://git.kernel.org/kees/c/ef20c5139c31
diff mbox series

Patch

diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
index cfd5f7ad019d..1fdc92e95170 100644
--- a/fs/binfmt_elf.c
+++ b/fs/binfmt_elf.c
@@ -462,7 +462,7 @@  static struct elf_phdr *load_elf_phdrs(const struct elfhdr *elf_ex,
 				       struct file *elf_file)
 {
 	struct elf_phdr *elf_phdata = NULL;
-	int retval, err = -1;
+	int retval = -1;
 	unsigned int size;
 
 	/*
@@ -484,15 +484,9 @@  static struct elf_phdr *load_elf_phdrs(const struct elfhdr *elf_ex,
 
 	/* Read in the program headers */
 	retval = elf_read(elf_file, elf_phdata, size, elf_ex->e_phoff);
-	if (retval < 0) {
-		err = retval;
-		goto out;
-	}
 
-	/* Success! */
-	err = 0;
 out:
-	if (err) {
+	if (retval) {
 		kfree(elf_phdata);
 		elf_phdata = NULL;
 	}