Skip to content

Commit

Permalink
modpost: simplify sec_name()
Browse files Browse the repository at this point in the history
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 <yamada.masahiro@socionext.com>
Reviewed-by: Kees Cook <keescook@chromium.org>
Cc: Nicholas Piggin <npiggin@gmail.com>
Cc: Jessica Yu <jeyu@redhat.com>
Cc: Chris Metcalf <cmetcalf@mellanox.com>
Cc: Heinrich Schuchardt <xypron.glpk@gmx.de>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
masahir0y authored and torvalds committed Sep 7, 2017
1 parent 2f52074 commit 6124c04
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 6124c04

Please sign in to comment.