diff mbox series

[v5,05/21] modpost: squash report_sec_mismatch() into default_mismatch_handler()

Message ID 20230514152739.962109-6-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series Unify <linux/export.h> and <asm/export.h>, remove EXPORT_DATA_SYMBOL(), faster TRIM_UNUSED_KSYMS | expand

Commit Message

Masahiro Yamada May 14, 2023, 3:27 p.m. UTC
report_sec_mismatch() and default_mismatch_handler() are small enough
to be merged together.

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

 scripts/mod/modpost.c | 55 ++++++++++++++++---------------------------
 1 file changed, 20 insertions(+), 35 deletions(-)

Comments

Nick Desaulniers May 17, 2023, 9:53 p.m. UTC | #1
On Sun, May 14, 2023 at 8:28 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> report_sec_mismatch() and default_mismatch_handler() are small enough
> to be merged together.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

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

> ---
>
>  scripts/mod/modpost.c | 55 ++++++++++++++++---------------------------
>  1 file changed, 20 insertions(+), 35 deletions(-)
>
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 7a9a3ef8ca0d..bb7d1d87bae7 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -1207,17 +1207,27 @@ static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
>         return near;
>  }
>
> -/*
> - * Print a warning about a section mismatch.
> - * Try to find symbols near it so user can find it.
> - * Check whitelist before warning - it may be a false positive.
> - */
> -static void report_sec_mismatch(const char *modname,
> -                               const struct sectioncheck *mismatch,
> -                               const char *fromsec,
> -                               const char *fromsym,
> -                               const char *tosec, const char *tosym)
> +static void default_mismatch_handler(const char *modname, struct elf_info *elf,
> +                                    const struct sectioncheck* const mismatch,
> +                                    Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
>  {
> +       const char *tosec;
> +       Elf_Sym *to;
> +       Elf_Sym *from;
> +       const char *tosym;
> +       const char *fromsym;
> +
> +       from = find_elf_symbol2(elf, r->r_offset, fromsec);
> +       fromsym = sym_name(elf, from);
> +
> +       tosec = sec_name(elf, get_secindex(elf, sym));
> +       to = find_elf_symbol(elf, r->r_addend, sym);
> +       tosym = sym_name(elf, to);
> +
> +       /* check whitelist - we may ignore it */
> +       if (!secref_whitelist(mismatch, fromsec, fromsym, tosec, tosym))
> +               return;
> +
>         sec_mismatch_count++;
>
>         switch (mismatch->mismatch) {
> @@ -1242,31 +1252,6 @@ static void report_sec_mismatch(const char *modname,
>         }
>  }
>
> -static void default_mismatch_handler(const char *modname, struct elf_info *elf,
> -                                    const struct sectioncheck* const mismatch,
> -                                    Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
> -{
> -       const char *tosec;
> -       Elf_Sym *to;
> -       Elf_Sym *from;
> -       const char *tosym;
> -       const char *fromsym;
> -
> -       from = find_elf_symbol2(elf, r->r_offset, fromsec);
> -       fromsym = sym_name(elf, from);
> -
> -       tosec = sec_name(elf, get_secindex(elf, sym));
> -       to = find_elf_symbol(elf, r->r_addend, sym);
> -       tosym = sym_name(elf, to);
> -
> -       /* check whitelist - we may ignore it */
> -       if (secref_whitelist(mismatch,
> -                            fromsec, fromsym, tosec, tosym)) {
> -               report_sec_mismatch(modname, mismatch,
> -                                   fromsec, fromsym, tosec, tosym);
> -       }
> -}
> -
>  static int is_executable_section(struct elf_info* elf, unsigned int section_index)
>  {
>         if (section_index > elf->num_sections)
> --
> 2.39.2
>
diff mbox series

Patch

diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 7a9a3ef8ca0d..bb7d1d87bae7 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1207,17 +1207,27 @@  static Elf_Sym *find_elf_symbol2(struct elf_info *elf, Elf_Addr addr,
 	return near;
 }
 
-/*
- * Print a warning about a section mismatch.
- * Try to find symbols near it so user can find it.
- * Check whitelist before warning - it may be a false positive.
- */
-static void report_sec_mismatch(const char *modname,
-				const struct sectioncheck *mismatch,
-				const char *fromsec,
-				const char *fromsym,
-				const char *tosec, const char *tosym)
+static void default_mismatch_handler(const char *modname, struct elf_info *elf,
+				     const struct sectioncheck* const mismatch,
+				     Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
 {
+	const char *tosec;
+	Elf_Sym *to;
+	Elf_Sym *from;
+	const char *tosym;
+	const char *fromsym;
+
+	from = find_elf_symbol2(elf, r->r_offset, fromsec);
+	fromsym = sym_name(elf, from);
+
+	tosec = sec_name(elf, get_secindex(elf, sym));
+	to = find_elf_symbol(elf, r->r_addend, sym);
+	tosym = sym_name(elf, to);
+
+	/* check whitelist - we may ignore it */
+	if (!secref_whitelist(mismatch, fromsec, fromsym, tosec, tosym))
+		return;
+
 	sec_mismatch_count++;
 
 	switch (mismatch->mismatch) {
@@ -1242,31 +1252,6 @@  static void report_sec_mismatch(const char *modname,
 	}
 }
 
-static void default_mismatch_handler(const char *modname, struct elf_info *elf,
-				     const struct sectioncheck* const mismatch,
-				     Elf_Rela *r, Elf_Sym *sym, const char *fromsec)
-{
-	const char *tosec;
-	Elf_Sym *to;
-	Elf_Sym *from;
-	const char *tosym;
-	const char *fromsym;
-
-	from = find_elf_symbol2(elf, r->r_offset, fromsec);
-	fromsym = sym_name(elf, from);
-
-	tosec = sec_name(elf, get_secindex(elf, sym));
-	to = find_elf_symbol(elf, r->r_addend, sym);
-	tosym = sym_name(elf, to);
-
-	/* check whitelist - we may ignore it */
-	if (secref_whitelist(mismatch,
-			     fromsec, fromsym, tosec, tosym)) {
-		report_sec_mismatch(modname, mismatch,
-				    fromsec, fromsym, tosec, tosym);
-	}
-}
-
 static int is_executable_section(struct elf_info* elf, unsigned int section_index)
 {
 	if (section_index > elf->num_sections)