diff mbox series

[1/2] modpost: refactor check_sec_ref()

Message ID 20231001054736.1586001-1-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series [1/2] modpost: refactor check_sec_ref() | expand

Commit Message

Masahiro Yamada Oct. 1, 2023, 5:47 a.m. UTC
We can replace &elf->sechdrs[i] with &sechdrs[i] to slightly shorten
the code because we already have the local variable 'sechdrs'.

However, defining 'sechdr' instead shortens the code further.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
---

 scripts/mod/modpost.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

Comments

Nick Desaulniers Oct. 2, 2023, 3:55 p.m. UTC | #1
On Sat, Sep 30, 2023 at 10:47 PM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> We can replace &elf->sechdrs[i] with &sechdrs[i] to slightly shorten
> the code because we already have the local variable 'sechdrs'.
>
> However, defining 'sechdr' instead shortens the code further.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

Thanks for the patch!
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>

> ---
>
>  scripts/mod/modpost.c | 13 +++++++------
>  1 file changed, 7 insertions(+), 6 deletions(-)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 2f3b0fe6f68d..15d78fe152ac 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -1523,16 +1523,17 @@ static void section_rel(struct module *mod, struct elf_info *elf,
>  static void check_sec_ref(struct module *mod, struct elf_info *elf)
>  {
>         int i;
> -       Elf_Shdr *sechdrs = elf->sechdrs;
>
>         /* Walk through all sections */
>         for (i = 0; i < elf->num_sections; i++) {
> -               check_section(mod->name, elf, &elf->sechdrs[i]);
> +               Elf_Shdr *sechdr = &elf->sechdrs[i];
> +
> +               check_section(mod->name, elf, sechdr);
>                 /* We want to process only relocation sections and not .init */
> -               if (sechdrs[i].sh_type == SHT_RELA)
> -                       section_rela(mod, elf, &elf->sechdrs[i]);
> -               else if (sechdrs[i].sh_type == SHT_REL)
> -                       section_rel(mod, elf, &elf->sechdrs[i]);
> +               if (sechdr->sh_type == SHT_RELA)
> +                       section_rela(mod, elf, sechdr);
> +               else if (sechdr->sh_type == SHT_REL)
> +                       section_rel(mod, elf, sechdr);
>         }
>  }
>
> --
> 2.39.2
>
diff mbox series

Patch

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 2f3b0fe6f68d..15d78fe152ac 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1523,16 +1523,17 @@  static void section_rel(struct module *mod, struct elf_info *elf,
 static void check_sec_ref(struct module *mod, struct elf_info *elf)
 {
 	int i;
-	Elf_Shdr *sechdrs = elf->sechdrs;
 
 	/* Walk through all sections */
 	for (i = 0; i < elf->num_sections; i++) {
-		check_section(mod->name, elf, &elf->sechdrs[i]);
+		Elf_Shdr *sechdr = &elf->sechdrs[i];
+
+		check_section(mod->name, elf, sechdr);
 		/* We want to process only relocation sections and not .init */
-		if (sechdrs[i].sh_type == SHT_RELA)
-			section_rela(mod, elf, &elf->sechdrs[i]);
-		else if (sechdrs[i].sh_type == SHT_REL)
-			section_rel(mod, elf, &elf->sechdrs[i]);
+		if (sechdr->sh_type == SHT_RELA)
+			section_rela(mod, elf, sechdr);
+		else if (sechdr->sh_type == SHT_REL)
+			section_rel(mod, elf, sechdr);
 	}
 }