modpost: simplify sec_name()
PATCH 10/119 modpost: simplify sec_name()
From: Masahiro Yamada <[email protected]>
Subject: modpost: simplify sec_name()
There is code duplication between sec_name() and sech_name(). Simplify sec_name() by re-using sech_name(). Also, move them up to remove the forward declaration of sec_name().
Signed-off-by Masahiro Yamada <[email protected]>
Reviewed-by Kees Cook <[email protected]>
Cc Nicholas Piggin <[email protected]>
Cc Jessica Yu <[email protected]>
Cc Chris Metcalf <[email protected]>
Cc Heinrich Schuchardt <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Ard Biesheuvel <[email protected]>
Signed-off-by Andrew Morton <[email protected]>
---
scripts/mod/modpost.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-)
scripts/mod/modpost.c renamed from scripts/mod/modpost.c~modpost-simplify-sec_name +11 -15
@@ -261,7 +261,17 @@ static enum export export_no(const charreturn export_unknown; } -static const char *sec_name (struct elf_info *elf,int secindex); +static const char *sech_name (struct elf_info *elf,Elf_Shdr *sechdr) +{ +return (void *)elf->hdr + + elf->sechdrs[elf->secindex_strings].sh_offset + + sechdr->sh_name; +} + +static const char *sec_name (struct elf_info *elf,int secindex) +{ +return sech_name (elf, &elf->sechdrs[secindex]); +}#define strstarts (str, prefix) (strncmp(str, prefix, strlen(prefix)) == 0)
@@ -775,21 +785,6 @@ static const char *sym_name(struct elf_ireturn "(unknown)" ; } -static const char *sec_name (struct elf_info *elf,int secindex) -{ -Elf_Shdr *sechdrs = elf->sechdrs; -return (void *)elf->hdr + - elf->sechdrs[elf->secindex_strings].sh_offset + - sechdrs[secindex].sh_name; -} - -static const char *sech_name (struct elf_info *elf,Elf_Shdr *sechdr) -{ -return (void *)elf->hdr + - elf->sechdrs[elf->secindex_strings].sh_offset + - sechdr->sh_name; -}