mirror of
https://gitlab.com/d3tn/ud3tn.git
synced 2026-08-13 12:33:27 +02:00
external/checkpatch: Import new version from linux v6.10
Commit: 0c3836482481200ead7b416ca80c68a29cfdaabd Signed-off-by: Felix Walter <felix.walter@d3tn.com>
This commit is contained in:
parent
241732ee6f
commit
f2c78e5d13
2 changed files with 828 additions and 20 deletions
152
external/checkpatch/checkpatch.pl
vendored
152
external/checkpatch/checkpatch.pl
vendored
|
|
@ -74,6 +74,8 @@ my $git_command ='export LANGUAGE=en_US.UTF-8; git';
|
|||
my $tabsize = 8;
|
||||
my ${CONFIG_} = "CONFIG_";
|
||||
|
||||
my %maybe_linker_symbol; # for externs in c exceptions, when seen in *vmlinux.lds.h
|
||||
|
||||
sub help {
|
||||
my ($exitcode) = @_;
|
||||
|
||||
|
|
@ -510,6 +512,7 @@ our $Attribute = qr{
|
|||
__ro_after_init|
|
||||
__kprobes|
|
||||
$InitAttribute|
|
||||
__aligned\s*\(.*\)|
|
||||
____cacheline_aligned|
|
||||
____cacheline_aligned_in_smp|
|
||||
____cacheline_internodealigned_in_smp|
|
||||
|
|
@ -620,6 +623,22 @@ our $signature_tags = qr{(?xi:
|
|||
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:
|
||||
[=-]*> |
|
||||
<[=-]* |
|
||||
|
|
@ -3158,14 +3177,14 @@ sub process {
|
|||
}
|
||||
}
|
||||
|
||||
# check if Reported-by: is followed by a Link:
|
||||
# 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 Link: to the report\n" . $herecurr . $rawlines[$linenr] . "\n");
|
||||
} elsif ($rawlines[$linenr] !~ m{^link:\s*https?://}i) {
|
||||
"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 Link: with a URL to the report\n" . $herecurr . $rawlines[$linenr] . "\n");
|
||||
"Reported-by: should be immediately followed by Closes: with a URL to the report\n" . $herecurr . $rawlines[$linenr] . "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -3250,11 +3269,11 @@ 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);
|
||||
"Prefer a maximum 75 chars per line (possible unwrapped commit description?)\n" . $herecurr);
|
||||
$commit_log_long_line = 1;
|
||||
}
|
||||
|
||||
|
|
@ -3266,13 +3285,24 @@ sub process {
|
|||
|
||||
# Check for odd tags before a URI/URL
|
||||
if ($in_commit_log &&
|
||||
$line =~ /^\s*(\w+):\s*http/ && $1 ne 'Link') {
|
||||
$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:' instead\n" . $herecurr);
|
||||
"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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -3736,7 +3766,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",
|
||||
|
|
@ -3746,6 +3776,11 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -4020,7 +4055,7 @@ sub process {
|
|||
if ($prevline =~ /^[\+ ]};?\s*$/ &&
|
||||
$line =~ /^\+/ &&
|
||||
!($line =~ /^\+\s*$/ ||
|
||||
$line =~ /^\+\s*(?:EXPORT_SYMBOL|early_param)/ ||
|
||||
$line =~ /^\+\s*(?:EXPORT_SYMBOL|early_param|ALLOW_ERROR_INJECTION)/ ||
|
||||
$line =~ /^\+\s*MODULE_/i ||
|
||||
$line =~ /^\+\s*\#\s*(?:end|elif|else)/ ||
|
||||
$line =~ /^\+[a-z_]*init/ ||
|
||||
|
|
@ -5014,7 +5049,7 @@ sub process {
|
|||
if|for|while|switch|return|case|
|
||||
volatile|__volatile__|
|
||||
__attribute__|format|__extension__|
|
||||
asm|__asm__)$/x)
|
||||
asm|__asm__|scoped_guard)$/x)
|
||||
{
|
||||
# cpp #define statements have non-optional spaces, ie
|
||||
# if there is a space between the name and the open
|
||||
|
|
@ -5809,6 +5844,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_]+)?$/ &&
|
||||
|
|
@ -6003,6 +6040,12 @@ sub process {
|
|||
CHK("MACRO_ARG_PRECEDENCE",
|
||||
"Macro argument '$arg' may be better as '($arg)' to avoid precedence issues\n" . "$herectx");
|
||||
}
|
||||
|
||||
# check if this is an unused argument
|
||||
if ($define_stmt !~ /\b$arg\b/) {
|
||||
WARN("MACRO_ARG_UNUSED",
|
||||
"Argument '$arg' is not used in function-like macro\n" . "$herectx");
|
||||
}
|
||||
}
|
||||
|
||||
# check for macros with flow control, but without ## concatenation
|
||||
|
|
@ -6017,6 +6060,9 @@ sub process {
|
|||
|
||||
# check for line continuations outside of #defines, preprocessor #, and asm
|
||||
|
||||
} elsif ($realfile =~ m@/vmlinux.lds.h$@) {
|
||||
$line =~ s/(\w+)/$maybe_linker_symbol{$1}++/ge;
|
||||
#print "REAL: $realfile\nln: $line\nkeys:", sort keys %maybe_linker_symbol;
|
||||
} else {
|
||||
if ($prevline !~ /^..*\\$/ &&
|
||||
$line !~ /^\+\s*\#.*\\$/ && # preprocessor
|
||||
|
|
@ -6954,12 +7000,43 @@ sub process {
|
|||
# }
|
||||
# }
|
||||
|
||||
# strcpy uses that should likely be strscpy
|
||||
if ($line =~ /\bstrcpy\s*\(/) {
|
||||
WARN("STRCPY",
|
||||
"Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr);
|
||||
}
|
||||
|
||||
# strlcpy uses that should likely be strscpy
|
||||
if ($line =~ /\bstrlcpy\s*\(/) {
|
||||
WARN("STRLCPY",
|
||||
"Prefer strscpy over strlcpy - see: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw\@mail.gmail.com/\n" . $herecurr);
|
||||
"Prefer strscpy over strlcpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr);
|
||||
}
|
||||
|
||||
# strncpy uses that should likely be strscpy or strscpy_pad
|
||||
if ($line =~ /\bstrncpy\s*\(/) {
|
||||
WARN("STRNCPY",
|
||||
"Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/issues/90\n" . $herecurr);
|
||||
}
|
||||
|
||||
# ethtool_sprintf uses that should likely be ethtool_puts
|
||||
if ($line =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
|
||||
if (WARN("PREFER_ETHTOOL_PUTS",
|
||||
"Prefer ethtool_puts over ethtool_sprintf with only two arguments\n" . $herecurr) &&
|
||||
$fix) {
|
||||
$fixed[$fixlinenr] =~ s/\bethtool_sprintf\s*\(\s*($FuncArg)\s*,\s*($FuncArg)/ethtool_puts($1, $7)/;
|
||||
}
|
||||
}
|
||||
|
||||
# use $rawline because $line loses %s via sanitization and thus we can't match against it.
|
||||
if ($rawline =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*\"\%s\"\s*,\s*$FuncArg\s*\)/) {
|
||||
if (WARN("PREFER_ETHTOOL_PUTS",
|
||||
"Prefer ethtool_puts over ethtool_sprintf with standalone \"%s\" specifier\n" . $herecurr) &&
|
||||
$fix) {
|
||||
$fixed[$fixlinenr] =~ s/\bethtool_sprintf\s*\(\s*($FuncArg)\s*,\s*"\%s"\s*,\s*($FuncArg)/ethtool_puts($1, $7)/;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
# typecasts on min/max could be min_t/max_t
|
||||
if ($perl_version_ok &&
|
||||
defined $stat &&
|
||||
|
|
@ -7064,6 +7141,21 @@ sub process {
|
|||
"arguments for function declarations should follow identifier\n" . $herecurr);
|
||||
}
|
||||
|
||||
} elsif ($realfile =~ /\.c$/ && defined $stat &&
|
||||
$stat =~ /^\+extern struct\s+(\w+)\s+(\w+)\[\];/)
|
||||
{
|
||||
my ($st_type, $st_name) = ($1, $2);
|
||||
|
||||
for my $s (keys %maybe_linker_symbol) {
|
||||
#print "Linker symbol? $st_name : $s\n";
|
||||
goto LIKELY_LINKER_SYMBOL
|
||||
if $st_name =~ /$s/;
|
||||
}
|
||||
WARN("AVOID_EXTERNS",
|
||||
"found a file-scoped extern type:$st_type name:$st_name in .c file\n"
|
||||
. "is this a linker symbol ?\n" . $herecurr);
|
||||
LIKELY_LINKER_SYMBOL:
|
||||
|
||||
} elsif ($realfile =~ /\.c$/ && defined $stat &&
|
||||
$stat =~ /^.\s*extern\s+/)
|
||||
{
|
||||
|
|
@ -7375,6 +7467,16 @@ sub process {
|
|||
}
|
||||
}
|
||||
|
||||
# check for array definition/declarations that should use flexible arrays instead
|
||||
if ($sline =~ /^[\+ ]\s*\}(?:\s*__packed)?\s*;\s*$/ &&
|
||||
$prevline =~ /^\+\s*(?:\}(?:\s*__packed\s*)?|$Type)\s*$Ident\s*\[\s*(0|1)\s*\]\s*;\s*$/) {
|
||||
if (ERROR("FLEXIBLE_ARRAY",
|
||||
"Use C99 flexible arrays - see https://docs.kernel.org/process/deprecated.html#zero-length-and-one-element-arrays\n" . $hereprev) &&
|
||||
$1 == '0' && $fix) {
|
||||
$fixed[$fixlinenr - 1] =~ s/\[\s*0\s*\]/[]/;
|
||||
}
|
||||
}
|
||||
|
||||
# nested likely/unlikely calls
|
||||
if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) {
|
||||
WARN("LIKELY_MISUSE",
|
||||
|
|
@ -7392,6 +7494,30 @@ sub process {
|
|||
}
|
||||
}
|
||||
|
||||
# Complain about RCU Tasks Trace used outside of BPF (and of course, RCU).
|
||||
our $rcu_trace_funcs = qr{(?x:
|
||||
rcu_read_lock_trace |
|
||||
rcu_read_lock_trace_held |
|
||||
rcu_read_unlock_trace |
|
||||
call_rcu_tasks_trace |
|
||||
synchronize_rcu_tasks_trace |
|
||||
rcu_barrier_tasks_trace |
|
||||
rcu_request_urgent_qs_task
|
||||
)};
|
||||
our $rcu_trace_paths = qr{(?x:
|
||||
kernel/bpf/ |
|
||||
include/linux/bpf |
|
||||
net/bpf/ |
|
||||
kernel/rcu/ |
|
||||
include/linux/rcu
|
||||
)};
|
||||
if ($line =~ /\b($rcu_trace_funcs)\s*\(/) {
|
||||
if ($realfile !~ m{^$rcu_trace_paths}) {
|
||||
WARN("RCU_TASKS_TRACE",
|
||||
"use of RCU tasks trace is incorrect outside BPF or core RCU code\n" . $herecurr);
|
||||
}
|
||||
}
|
||||
|
||||
# check for lockdep_set_novalidate_class
|
||||
if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
|
||||
$line =~ /__lockdep_no_validate__\s*\)/ ) {
|
||||
|
|
|
|||
696
external/checkpatch/spelling.txt
vendored
696
external/checkpatch/spelling.txt
vendored
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue