From 6124c04c1344497e0cbfb505ddbd3b83090a4d51 Mon Sep 17 00:00:00 2001 From: Masahiro Yamada Date: Wed, 6 Sep 2017 16:19:05 -0700 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(). Link: http://lkml.kernel.org/r/1502248721-22009-1-git-send-email-yamada.masahiro@socionext.com Signed-off-by: Masahiro Yamada Reviewed-by: Kees Cook Cc: Nicholas Piggin Cc: Jessica Yu Cc: Chris Metcalf Cc: Heinrich Schuchardt Cc: Ingo Molnar Cc: Ard Biesheuvel Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/mod/modpost.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) (limited to 'scripts') diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c index 48397fe..b920d18 100644 --- a/scripts/mod/modpost.c +++ b/scripts/mod/modpost.c @@ -261,7 +261,17 @@ static enum export export_no(const char *s) return 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_info *elf, Elf_Sym *sym) return "(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; -} - /* The pattern is an array of simple patterns. * "foo" will match an exact string equal to "foo" * "*foo" will match a string that ends with "foo" -- cgit v1.1