Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1707033 > unrolled thread

[PATCH] modpost: simplify sec_name()

Started byMasahiro Yamada <yamada.masahiro@socionext.com>
First post2017-08-09 05:30 +0200
Last post2017-08-09 07:20 +0200
Articles 2 — 2 participants

Back to article view | Back to linux.kernel


Contents

  [PATCH] modpost: simplify sec_name() Masahiro Yamada <yamada.masahiro@socionext.com> - 2017-08-09 05:30 +0200
    Re: [PATCH] modpost: simplify sec_name() Kees Cook <keescook@chromium.org> - 2017-08-09 07:20 +0200

#1707033 — [PATCH] modpost: simplify sec_name()

FromMasahiro Yamada <yamada.masahiro@socionext.com>
Date2017-08-09 05:30 +0200
Subject[PATCH] modpost: simplify sec_name()
Message-ID<ucpQZ-1d8-5@gated-at.bofh.it>
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 <yamada.masahiro@socionext.com>
---

 scripts/mod/modpost.c | 27 +++++++++++----------------
 1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 48397feb08fb..b920d186ad4a 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"
-- 
2.7.4

[toc] | [next] | [standalone]


#1707063

FromKees Cook <keescook@chromium.org>
Date2017-08-09 07:20 +0200
Message-ID<ucrzs-2kZ-5@gated-at.bofh.it>
In reply to#1707033
On Tue, Aug 8, 2017 at 8:18 PM, Masahiro Yamada
<yamada.masahiro@socionext.com> wrote:
> 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 <yamada.masahiro@socionext.com>

Reviewed-by: Kees Cook <keescook@chromium.org>

-Kees

> ---
>
>  scripts/mod/modpost.c | 27 +++++++++++----------------
>  1 file changed, 11 insertions(+), 16 deletions(-)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 48397feb08fb..b920d186ad4a 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"
> --
> 2.7.4
>



-- 
Kees Cook
Pixel Security

[toc] | [prev] | [standalone]


Back to top | Article view | linux.kernel


csiph-web