Skip to content

Commit

Permalink
tests: update checkpatch.pl from Linux kernel
Browse files Browse the repository at this point in the history
  • Loading branch information
DimitriPapadopoulos committed May 6, 2023
1 parent f1b810f commit 5111cae
Showing 1 changed file with 78 additions and 9 deletions.
87 changes: 78 additions & 9 deletions tests/ci/checkpatch/checkpatch.pl
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,22 @@ sub hash_show_words {
Cc:
)};

our @link_tags = qw(Link Closes);

#Create a search and print patterns for all these strings to be used directly below
our $link_tags_search = "";
our $link_tags_print = "";
foreach my $entry (@link_tags) {
if ($link_tags_search ne "") {
$link_tags_search .= '|';
$link_tags_print .= ' or ';
}
$entry .= ':';
$link_tags_search .= $entry;
$link_tags_print .= "'$entry'";
}
$link_tags_search = "(?:${link_tags_search})";

our $tracing_logging_tags = qr{(?xi:
[=-]*> |
<[=-]* |
Expand Down Expand Up @@ -823,7 +839,9 @@ sub find_standard_signature {
"get_state_synchronize_sched" => "get_state_synchronize_rcu",
"cond_synchronize_sched" => "cond_synchronize_rcu",
"kmap" => "kmap_local_page",
"kunmap" => "kunmap_local",
"kmap_atomic" => "kmap_local_page",
"kunmap_atomic" => "kunmap_local",
);

#Create a search pattern for all these strings to speed up a loop below
Expand Down Expand Up @@ -3142,21 +3160,33 @@ sub process {
if ($sign_off =~ /^co-developed-by:$/i) {
if ($email eq $author) {
WARN("BAD_SIGN_OFF",
"Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . "$here\n" . $rawline);
"Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . $herecurr);
}
if (!defined $lines[$linenr]) {
WARN("BAD_SIGN_OFF",
"Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline);
} elsif ($rawlines[$linenr] !~ /^\s*signed-off-by:\s*(.*)/i) {
"Co-developed-by: must be immediately followed by Signed-off-by:\n" . $herecurr);
} elsif ($rawlines[$linenr] !~ /^signed-off-by:\s*(.*)/i) {
WARN("BAD_SIGN_OFF",
"Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]);
"Co-developed-by: must be immediately followed by Signed-off-by:\n" . $herecurr . $rawlines[$linenr] . "\n");
} elsif ($1 ne $email) {
WARN("BAD_SIGN_OFF",
"Co-developed-by and Signed-off-by: name/email do not match \n" . "$here\n" . $rawline . "\n" .$rawlines[$linenr]);
"Co-developed-by and Signed-off-by: name/email do not match\n" . $herecurr . $rawlines[$linenr] . "\n");
}
}

# check if Reported-by: is followed by a Closes: tag
if ($sign_off =~ /^reported(?:|-and-tested)-by:$/i) {
if (!defined $lines[$linenr]) {
WARN("BAD_REPORTED_BY_LINK",
"Reported-by: should be immediately followed by Closes: with a URL to the report\n" . $herecurr . "\n");
} elsif ($rawlines[$linenr] !~ /^closes:\s*/i) {
WARN("BAD_REPORTED_BY_LINK",
"Reported-by: should be immediately followed by Closes: with a URL to the report\n" . $herecurr . $rawlines[$linenr] . "\n");
}
}
}


# Check Fixes: styles is correct
if (!$in_header_lines &&
$line =~ /^\s*fixes:?\s*(?:commit\s*)?[0-9a-f]{5,}\b/i) {
Expand Down Expand Up @@ -3236,8 +3266,8 @@ sub process {
# file delta changes
$line =~ /^\s*(?:[\w\.\-\+]*\/)++[\w\.\-\+]+:/ ||
# filename then :
$line =~ /^\s*(?:Fixes:|Link:|$signature_tags)/i ||
# A Fixes: or Link: line or signature tag line
$line =~ /^\s*(?:Fixes:|$link_tags_search|$signature_tags)/i ||
# A Fixes:, link or signature tag line
$commit_log_possible_stack_dump)) {
WARN("COMMIT_LOG_LONG_LINE",
"Possible unwrapped commit description (prefer a maximum 75 chars per line)\n" . $herecurr);
Expand All @@ -3250,6 +3280,29 @@ sub process {
$commit_log_possible_stack_dump = 0;
}

# Check for odd tags before a URI/URL
if ($in_commit_log &&
$line =~ /^\s*(\w+:)\s*http/ && $1 !~ /^$link_tags_search$/) {
if ($1 =~ /^v(?:ersion)?\d+/i) {
WARN("COMMIT_LOG_VERSIONING",
"Patch version information should be after the --- line\n" . $herecurr);
} else {
WARN("COMMIT_LOG_USE_LINK",
"Unknown link reference '$1', use $link_tags_print instead\n" . $herecurr);
}
}

# Check for misuse of the link tags
if ($in_commit_log &&
$line =~ /^\s*(\w+:)\s*(\S+)/) {
my $tag = $1;
my $value = $2;
if ($tag =~ /^$link_tags_search$/ && $value !~ m{^https?://}) {
WARN("COMMIT_LOG_WRONG_LINK",
"'$tag' should be followed by a public http(s) link\n" . $herecurr);
}
}

# Check for lines starting with a #
if ($in_commit_log && $line =~ /^#/) {
if (WARN("COMMIT_COMMENT_SYMBOL",
Expand Down Expand Up @@ -3710,7 +3763,7 @@ sub process {
"'$spdx_license' is not supported in LICENSES/...\n" . $herecurr);
}
if ($realfile =~ m@^Documentation/devicetree/bindings/@ &&
not $spdx_license =~ /GPL-2\.0.*BSD-2-Clause/) {
$spdx_license !~ /GPL-2\.0(?:-only)? OR BSD-2-Clause/) {
my $msg_level = \&WARN;
$msg_level = \&CHK if ($file);
if (&{$msg_level}("SPDX_LICENSE_TAG",
Expand All @@ -3720,12 +3773,17 @@ sub process {
$fixed[$fixlinenr] =~ s/SPDX-License-Identifier: .*/SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)/;
}
}
if ($realfile =~ m@^include/dt-bindings/@ &&
$spdx_license !~ /GPL-2\.0(?:-only)? OR \S+/) {
WARN("SPDX_LICENSE_TAG",
"DT binding headers should be licensed (GPL-2.0-only OR .*)\n" . $herecurr);
}
}
}
}

# check for embedded filenames
if ($rawline =~ /^\+.*\Q$realfile\E/) {
if ($rawline =~ /^\+.*\b\Q$realfile\E\b/) {
WARN("EMBEDDED_FILENAME",
"It's generally not useful to have the filename in the file\n" . $herecurr);
}
Expand Down Expand Up @@ -5783,6 +5841,8 @@ sub process {
$var !~ /^(?:[A-Z]+_){1,5}[A-Z]{1,3}[a-z]/ &&
#Ignore Page<foo> variants
$var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
#Ignore ETHTOOL_LINK_MODE_<foo> variants
$var !~ /^ETHTOOL_LINK_MODE_/ &&
#Ignore SI style variants like nS, mV and dB
#(ie: max_uV, regulator_min_uA_show, RANGE_mA_VALUE)
$var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ &&
Expand Down Expand Up @@ -6362,6 +6422,15 @@ sub process {
}
}

# check for soon-to-be-deprecated single-argument k[v]free_rcu() API
if ($line =~ /\bk[v]?free_rcu\s*\([^(]+\)/) {
if ($line =~ /\bk[v]?free_rcu\s*\([^,]+\)/) {
ERROR("DEPRECATED_API",
"Single-argument k[v]free_rcu() API is deprecated, please pass rcu_head object or call k[v]free_rcu_mightsleep()." . $herecurr);
}
}


# check for unnecessary "Out of Memory" messages
if ($line =~ /^\+.*\b$logFunctions\s*\(/ &&
$prevline =~ /^[ \+]\s*if\s*\(\s*(\!\s*|NULL\s*==\s*)?($Lval)(\s*==\s*NULL\s*)?\s*\)/ &&
Expand Down

0 comments on commit 5111cae

Please sign in to comment.