Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scripts/checkpatch: Check for patches adding #defines for libc APIs #60487

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions scripts/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,20 @@ sub hash_show_words {
["__ATTR", 2],
);

our $api_defines = qr{(?x:
_ATFILE_SOURCE|
_BSD_SOURCE|
_DEFAULT_SOURCE
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keith-packard missing pipe might be the culprit?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It actually got moved to the end of the pattern when I sorted the symbols upon request from a reviewer... Checkout #60551 for the fix.

_GNU_SOURCE|
_ISOC11_SOURCE|
_ISOC99_SOURCE|
_POSIX_C_SOURCE|
_POSIX_SOURCE|
_SVID_SOURCE|
_XOPEN_SOURCE|
_XOPEN_SOURCE_EXTENDED|
)};

my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';

#Create a search pattern for all these functions to speed up a loop below
Expand Down Expand Up @@ -6527,6 +6541,13 @@ sub process {
}
}

# check for feature test macros that request C library API extensions, violating rules A.4 and A.5

if ($line =~ /#\s*define\s+$api_defines/) {
ERROR("API_DEFINE",
"do not specify a non-Zephyr API for libc\n" . "$here$rawline\n");
}

# check for IS_ENABLED() without CONFIG_<FOO> ($rawline for comments too)
if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^CONFIG_/) {
WARN("IS_ENABLED_CONFIG",
Expand Down