diff mbox series

[4/5] modpost: reuse ARRAY_SIZE() macro for section_mismatch()

Message ID 20220523164626.858340-4-masahiroy@kernel.org (mailing list archive)
State New, archived
Headers show
Series [1/5] modpost: fix undefined behavior of is_arm_mapping_symbol() | expand

Commit Message

Masahiro Yamada May 23, 2022, 4:46 p.m. UTC
Move ARRAY_SIZE() from file2alias.c to modpost.h to reuse it in
section_mismatch().

Also, move the variable 'check' inside the for-loop.

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

 scripts/mod/file2alias.c | 2 --
 scripts/mod/modpost.c    | 7 +++----
 scripts/mod/modpost.h    | 3 +++
 3 files changed, 6 insertions(+), 6 deletions(-)

Comments

Nick Desaulniers May 24, 2022, 8:49 p.m. UTC | #1
On Mon, May 23, 2022 at 9:48 AM Masahiro Yamada <masahiroy@kernel.org> wrote:
>
> Move ARRAY_SIZE() from file2alias.c to modpost.h to reuse it in
> section_mismatch().
>
> Also, move the variable 'check' inside the for-loop.
>
> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

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

> ---
>
>  scripts/mod/file2alias.c | 2 --
>  scripts/mod/modpost.c    | 7 +++----
>  scripts/mod/modpost.h    | 3 +++
>  3 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
> index 5258247d78ac..e8a9c6816fec 100644
> --- a/scripts/mod/file2alias.c
> +++ b/scripts/mod/file2alias.c
> @@ -734,8 +734,6 @@ static int do_vio_entry(const char *filename, void *symval,
>         return 1;
>  }
>
> -#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
> -
>  static void do_input(char *alias,
>                      kernel_ulong_t *arr, unsigned int min, unsigned int max)
>  {
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 77c315dea1a3..48a18b59f908 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -1049,8 +1049,6 @@ static const struct sectioncheck *section_mismatch(
>                 const char *fromsec, const char *tosec)
>  {
>         int i;
> -       int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck);
> -       const struct sectioncheck *check = &sectioncheck[0];
>
>         /*
>          * The target section could be the SHT_NUL section when we're
> @@ -1061,14 +1059,15 @@ static const struct sectioncheck *section_mismatch(
>         if (*tosec == '\0')
>                 return NULL;
>
> -       for (i = 0; i < elems; i++) {
> +       for (i = 0; i < ARRAY_SIZE(sectioncheck); i++) {
> +               const struct sectioncheck *check = &sectioncheck[i];
> +
>                 if (match(fromsec, check->fromsec)) {
>                         if (check->bad_tosec[0] && match(tosec, check->bad_tosec))
>                                 return check;
>                         if (check->good_tosec[0] && !match(tosec, check->good_tosec))
>                                 return check;
>                 }
> -               check++;
>         }
>         return NULL;
>  }
> diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
> index d9daeff07b83..044bdfb894b7 100644
> --- a/scripts/mod/modpost.h
> +++ b/scripts/mod/modpost.h
> @@ -97,6 +97,9 @@ static inline void __endian(const void *src, void *dest, unsigned int size)
>  #endif
>
>  #define NOFAIL(ptr)   do_nofail((ptr), #ptr)
> +
> +#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
> +
>  void *do_nofail(void *ptr, const char *expr);
>
>  struct buffer {
> --
> 2.32.0
>
diff mbox series

Patch

diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 5258247d78ac..e8a9c6816fec 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -734,8 +734,6 @@  static int do_vio_entry(const char *filename, void *symval,
 	return 1;
 }
 
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-
 static void do_input(char *alias,
 		     kernel_ulong_t *arr, unsigned int min, unsigned int max)
 {
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 77c315dea1a3..48a18b59f908 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -1049,8 +1049,6 @@  static const struct sectioncheck *section_mismatch(
 		const char *fromsec, const char *tosec)
 {
 	int i;
-	int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck);
-	const struct sectioncheck *check = &sectioncheck[0];
 
 	/*
 	 * The target section could be the SHT_NUL section when we're
@@ -1061,14 +1059,15 @@  static const struct sectioncheck *section_mismatch(
 	if (*tosec == '\0')
 		return NULL;
 
-	for (i = 0; i < elems; i++) {
+	for (i = 0; i < ARRAY_SIZE(sectioncheck); i++) {
+		const struct sectioncheck *check = &sectioncheck[i];
+
 		if (match(fromsec, check->fromsec)) {
 			if (check->bad_tosec[0] && match(tosec, check->bad_tosec))
 				return check;
 			if (check->good_tosec[0] && !match(tosec, check->good_tosec))
 				return check;
 		}
-		check++;
 	}
 	return NULL;
 }
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index d9daeff07b83..044bdfb894b7 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -97,6 +97,9 @@  static inline void __endian(const void *src, void *dest, unsigned int size)
 #endif
 
 #define NOFAIL(ptr)   do_nofail((ptr), #ptr)
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
 void *do_nofail(void *ptr, const char *expr);
 
 struct buffer {