diff mbox series

remoteproc: Remove unneeded check in elf_strtbl_add()

Message ID 20240705160252.9628-1-amishin@t-argos.ru (mailing list archive)
State New
Headers show
Series remoteproc: Remove unneeded check in elf_strtbl_add() | expand

Commit Message

Aleksandr Mishin July 5, 2024, 4:02 p.m. UTC
In elf_strtbl_add() pointer 'strtab', which value is a result of shifting
after dereference of another pointer 'ehdr', is compared to NULL, which is
useless.

Fix this issue by removing unneeded check.

Found by Linux Verification Center (linuxtesting.org) with SVACE.

Fixes: abc72b646066 ("remoteproc: coredump: Add minidump functionality")
Signed-off-by: Aleksandr Mishin <amishin@t-argos.ru>
---
 drivers/remoteproc/remoteproc_elf_helpers.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Markus Elfring July 6, 2024, 4:11 p.m. UTC | #1
> useless.

         because …?


> Fix this issue by removing unneeded check.

Another wording suggestion:
  Thus remove a redundant check.


…
> +++ b/drivers/remoteproc/remoteproc_elf_helpers.h
> @@ -107,7 +107,7 @@ static inline unsigned int elf_strtbl_add(const char *name, void *ehdr, u8 class
>  	shdr = ehdr + elf_size_of_hdr(class) + shstrndx * elf_size_of_shdr(class);
>  	strtab = ehdr + elf_shdr_get_sh_offset(class, shdr);
>  	idx = index ? *index : 0;
> -	if (!strtab || !name)
> +	if (!name)
>  		return 0;
…

How do you think about to perform the remaining null pointer check
as the first statement (because of input parameter validation in
this function implementation)?

Regards,
Markus
diff mbox series

Patch

diff --git a/drivers/remoteproc/remoteproc_elf_helpers.h b/drivers/remoteproc/remoteproc_elf_helpers.h
index e6de53a5000c..7c57fb553466 100644
--- a/drivers/remoteproc/remoteproc_elf_helpers.h
+++ b/drivers/remoteproc/remoteproc_elf_helpers.h
@@ -107,7 +107,7 @@  static inline unsigned int elf_strtbl_add(const char *name, void *ehdr, u8 class
 	shdr = ehdr + elf_size_of_hdr(class) + shstrndx * elf_size_of_shdr(class);
 	strtab = ehdr + elf_shdr_get_sh_offset(class, shdr);
 	idx = index ? *index : 0;
-	if (!strtab || !name)
+	if (!name)
 		return 0;
 
 	ret = idx;