Skip to content

Commit

Permalink
modpost: add PATTERNS() helper macro
Browse files Browse the repository at this point in the history
This will be useful to define a NULL-terminated array inside a function
call.

Currently, string arrays passed to match() are defined in separate
places:

    static const char *const init_sections[] = { ALL_INIT_SECTIONS, NULL };
    static const char *const text_sections[] = { ALL_TEXT_SECTIONS, NULL };
    static const char *const optim_symbols[] = { "*.constprop.*", NULL };

            ...

            /* Check for pattern 5 */
            if (match(fromsec, text_sections) &&
                match(tosec, init_sections) &&
                match(fromsym, optim_symbols))
                    return 0;

With the new helper macro, you can list the patterns directly in the
function call, like this:

            /* Check for pattern 5 */
            if (match(fromsec, PATTERNS(ALL_TEXT_SECTIONS)) &&
                match(tosec, PATTERNS(ALL_INIT_SECTIONS)) &&
                match(fromsym, PATTERNS("*.contprop.*")))
                    return 0;

Signed-off-by: Masahiro Yamada <[email protected]>
  • Loading branch information
masahir0y committed Aug 4, 2022
1 parent 072dd2c commit 7452dd2
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions scripts/mod/modpost.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,13 @@ static bool match(const char *string, const char *const patterns[])
return false;
}

/* useful to pass patterns to match() directly */
#define PATTERNS(...) \
({ \
static const char *const patterns[] = {__VA_ARGS__, NULL}; \
patterns; \
})

/* sections that we do not want to do full section mismatch check on */
static const char *const section_white_list[] =
{
Expand Down

0 comments on commit 7452dd2

Please sign in to comment.