Skip to content

Commit c5c468d

Browse files
committed
modpost: reuse ARRAY_SIZE() macro for section_mismatch()
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 <[email protected]> Reviewed-by: Nick Desaulniers <[email protected]>
1 parent 7695452 commit c5c468d

File tree

3 files changed

+6
-6
lines changed

3 files changed

+6
-6
lines changed

scripts/mod/file2alias.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -734,8 +734,6 @@ static int do_vio_entry(const char *filename, void *symval,
734734
return 1;
735735
}
736736

737-
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
738-
739737
static void do_input(char *alias,
740738
kernel_ulong_t *arr, unsigned int min, unsigned int max)
741739
{

scripts/mod/modpost.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,8 +1049,6 @@ static const struct sectioncheck *section_mismatch(
10491049
const char *fromsec, const char *tosec)
10501050
{
10511051
int i;
1052-
int elems = sizeof(sectioncheck) / sizeof(struct sectioncheck);
1053-
const struct sectioncheck *check = &sectioncheck[0];
10541052

10551053
/*
10561054
* The target section could be the SHT_NUL section when we're
@@ -1061,14 +1059,15 @@ static const struct sectioncheck *section_mismatch(
10611059
if (*tosec == '\0')
10621060
return NULL;
10631061

1064-
for (i = 0; i < elems; i++) {
1062+
for (i = 0; i < ARRAY_SIZE(sectioncheck); i++) {
1063+
const struct sectioncheck *check = &sectioncheck[i];
1064+
10651065
if (match(fromsec, check->fromsec)) {
10661066
if (check->bad_tosec[0] && match(tosec, check->bad_tosec))
10671067
return check;
10681068
if (check->good_tosec[0] && !match(tosec, check->good_tosec))
10691069
return check;
10701070
}
1071-
check++;
10721071
}
10731072
return NULL;
10741073
}

scripts/mod/modpost.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,9 @@ static inline void __endian(const void *src, void *dest, unsigned int size)
9797
#endif
9898

9999
#define NOFAIL(ptr) do_nofail((ptr), #ptr)
100+
101+
#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
102+
100103
void *do_nofail(void *ptr, const char *expr);
101104

102105
struct buffer {

0 commit comments

Comments
 (0)