Lines Matching +full:files +full:- +full:exclude

2 # SPDX-License-Identifier: GPL-2.0
7 # (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
8 # (c) 2010-2018 Joe Perches <joe@perches.com>
52 my @exclude = ();
67 my $git_command ='export LANGUAGE=en_US.UTF-8; git';
78 -q, --quiet quiet
79 --no-tree run without a kernel tree
80 --no-signoff do not check for 'Signed-off-by' line
81 --patch treat FILE as patchfile (default)
82 --emacs emacs compile window format
83 --terse one line per report
84 --showfile emit diffed file position, not input file position
85 -g, --git treat FILE as a single commit or git revision range
93 <rev>-<count>
95 -f, --file treat FILE as regular source file
96 --subjective, --strict enable more subjective tests
97 --list-types list the possible message types
98 --types TYPE(,TYPE2...) show only these comma separated message types
99 --ignore TYPE(,TYPE2...) ignore various comma separated message types
100 --exclude DIR (--exclude DIR2...) exclude directories
101 --show-types show the specific message type in the output
102 --max-line-length=n set the maximum line length, (default $max_line_length)
104 requires --strict for use with --file
105 --min-conf-desc-length=n set the min description length, if shorter, warn
106 --tab-size=n set the number of spaces for tab (default $tabsize)
107 --root=PATH PATH to the kernel tree root
108 --no-summary suppress the per-file summary
109 --mailback only produce a report in case of warnings/errors
110 --summary-file include the filename in summary
111 --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
114 --test-only=WORD report only warnings/errors containing WORD
116 --fix EXPERIMENTAL - may create horrible results
117 If correctable single-line errors exist, create
118 "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
121 --fix-inplace EXPERIMENTAL - may create horrible results
122 Is the same as --fix, but overwrites the input
124 --ignore-perl-version override checking of perl version. expect
126 --codespell Use the codespell dictionary for spelling/typos
128 --codespellfile Use this codespell dictionary
129 --typedefsfile Read additional types from this file
130 --color[=WHEN] Use colors 'always', 'never', or only when output
132 -h, --help, --version display this help and exit
134 When FILE is - read standard input.
173 if (-f $conf) {
199 # Prevent --color by itself from consuming other arguments
201 if ($_ eq "--color" || $_ eq "-color") {
202 $_ = "--color=$color";
219 'exclude=s' => \@exclude,
221 'show-types!' => \$show_types,
222 'list-types!' => \$list_types,
223 'max-line-length=i' => \$max_line_length,
224 'min-conf-desc-length=i' => \$min_conf_desc_length,
225 'tab-size=i' => \$tabsize,
229 'summary-file!' => \$summary_file,
231 'fix-inplace!' => \$fix_inplace,
232 'ignore-perl-version!' => \$ignore_perl_version,
234 'test-only=s' => \$tst_only,
239 'no-color' => \$color, #keep old behaviors of -nocolor
240 'nocolor' => \$color, #keep old behaviors of -nocolor
252 die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix));
263 #if no filenames are given, push '-' to read patch from stdin
265 push(@ARGV, '-');
275 $color = (-t STDOUT);
280 # skip TAB size 1 to avoid additional checks on $tabsize - 1
291 $word =~ tr/[a-z]/[A-Z]/;
296 $hashRef->{$word}++;
335 die "$P: $root: --root does not point at a valid tree\n";
347 print "Must be run from the top-level dir. of a kernel tree\n";
355 [A-Za-z_][A-Za-z\d_]*
356 (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
409 our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
414 our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
415 our $Int = qr{[0-9]+$Int_type?};
416 our $Octal = qr{0[0-7]+$Int_type?};
418 our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
419 our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
420 our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
423 our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
424 our $Compare = qr{<=|>=|==|!=|<|(?<!-)>};
425 our $Arithmetic = qr{\+|-|\*|\/|%};
428 =>|->|<<|>>|<|>|!|~|
429 &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
444 [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
445 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
446 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
447 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
448 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
449 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
450 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
454 [\x09\x0A\x0D\x20-\x7E] # ASCII
477 …(?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|co…
481 MODULE_[A-Z_]+|
496 Signed-off-by:|
497 Co-authored-by:|
498 Co-developed-by:|
499 Acked-by:|
500 Tested-by:|
501 Reviewed-by:|
502 Reported-by:|
503 Suggested-by:|
590 ["IIO_DEV_ATTR_[A-Z_]+", 1],
608 my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';
614 $mode_perms_search .= $entry->[0];
644 0[0-7][0-7][2367]
681 return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/);
692 last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos));
732 warn "No typos will be found - file '$spelling_file': $!\n";
749 my ($suspect, $fix) = split(/->/, $line);
755 warn "No codespell typos will be found - file '$codespellfile': $!\n";
774 print("$file: '$line' invalid - ignored\n");
791 # or warn "No structs that should be const will be found - file '$conststructsfile': $!\n";
797 or warn "No additional types will be considered - file '$typedefsfile': $!\n";
857 our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
862 (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
884 return if (!(-f $file));
896 next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
897 if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
899 } elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
901 } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
912 return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl"));
915 …s{$filename} = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback…
924 …return 1 if (!$tree || which("python") eq "" || !(-e "$root/scripts/spdxcheck.py") || !(-e "$root/…
927 my $status = `cd "$root_path"; echo "$license" | python scripts/spdxcheck.py -`;
936 my $files;
942 if (-e ".git") {
943 …my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include…
945 $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
948 $files = `find $root/include -name "*.h"`;
949 @include_files = split('\n', $files);
955 $camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
958 if ($camelcase_cache ne "" && -f $camelcase_cache) {
970 if (-e ".git") {
971 $files = `${git_command} ls-files "include/*.h"`;
972 @include_files = split('\n', $files);
980 unlink glob ".checkpatch-camelcase.*";
993 return ($id, $desc) if ((which("git") eq "") || !(-e ".git"));
995 my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`;
1006 # git rev-list --remotes | grep -i "^$1" |
1008 # git log --format='%H %s' -1 $line |
1009 # echo "commit $(cut -c 1-12,41-)"
1028 my $fixlinenr = -1;
1031 # For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.
1032 die "$P: No git repository found\n" if ($git && !-e ".git");
1038 if ($commit_expr =~ m/^(.*)-(\d+)$/) {
1039 $git_range = "-$2 $1";
1043 $git_range = "-1 $commit_expr";
1045 my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`;
1047 $line =~ /^([0-9a-fA-F]{40,40}) (.*)$/;
1064 open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||
1065 die "$P: $filename: git format-patch failed - $!\n";
1067 open($FILE, '-|', "diff -u /dev/null $filename") ||
1068 die "$P: $filename: diff failed - $!\n";
1069 } elsif ($filename eq '-') {
1073 die "$P: $filename: open failed - $!\n";
1075 if ($filename eq '-') {
1085 $vname = qq("$1") if ($filename eq '-' && $_ =~ m/^Subject:\s+(.+)/i);
1090 print '-' x length($vname) . "\n";
1092 print '-' x length($vname) . "\n";
1103 $fixlinenr = -1;
1141 if (! -e $root . '/' . $check) {
1187 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
1204 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
1222 if (-e "$path/$bin") {
1234 if (-e "$path/$conf") {
1389 return substr($rawline, $-[0], $+[0] - $-[0]);
1394 my $line = $linenr - 1;
1397 my $coff = $off - 1;
1411 @stack = (['', 0]) if ($#stack == -1);
1419 next if ($lines[$line] =~ /^-/);
1420 $remain--;
1447 ($type, $level) = @{$stack[$#stack - 1]};
1463 $coff = $off + length($1) - 1;
1466 #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
1474 $level--;
1488 $level--;
1500 $level--;
1511 $remain--;
1514 my $statement = substr($blk, $soff, $off - $soff + 1);
1515 my $condition = substr($blk, $soff, $coff - $soff + 1);
1523 $line, $remain + 1, $off - $loff + 1, $level);
1580 if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
1590 last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
1601 my $start = $linenr - 1;
1610 next if ($rawlines[$line] =~ /^-/);
1611 $remain--;
1619 $level = $stack[$#stack - 1];
1627 $off--;
1632 $level--;
1681 my ($current_comment) = ($rawlines[$end_line - 1] =~ m@^\+.*(//.*$)@);
1683 ($current_comment) = ($rawlines[$end_line - 2] =~ m@^[\+ ].*(//.*$)@);
1689 ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
1697 my $line = $rawlines[$linenr - 1];
1721 ##print "LINE: $rawlines[$end_line - 1 ]\n";
1730 my $offset = $linenr - 1;
1736 next if (defined($line) && $line =~ /^-/);
1737 $cnt--;
1907 print "PAREN('$1') -> $type\n"
1963 } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
1978 if ($1 ne '++' && $1 ne '--') {
2046 $type =~ tr/[a-z]/[A-Z]/;
2079 my @lines = split("\n", $output, -1);
2097 if ($$lineRef =~ /^\@\@ -\d+,\d+ \+(\d+),(\d+) \@\@/) {
2126 if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename
2128 } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk
2136 fixup_current_range(\$lines[$range_last_linenr], $delta_offset--, -1);
2217 if (-f "$root/$file") {
2222 if (! -f _) {
2228 substr($prefix, -length($file)) = '';
2273 my $max_spaces_before_tab = $source_indent - 1;
2295 return -1;
2303 $pos += length($1) - 1;
2306 } elsif (index($string, '(') == -1) {
2333 my $is_binding_patch = -1;
2336 my $has_patch_separator = 0; #Found a --- line
2346 my $last_coalesced_string_linenr = -1;
2375 # Pre-scan the patch sanitizing the lines.
2376 # Pre-scan the patch looking for any __setup documentation.
2395 if ($1 =~ m@Documentation/admin-guide/kernel-parameters.txt$@) {
2400 if ($rawline =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
2401 $realline=$1-1;
2416 next if (defined $rawlines[$ln - 1] &&
2417 $rawlines[$ln - 1] =~ /^-/);
2418 $cnt--;
2419 #print "RAW<$rawlines[$ln - 1]>\n";
2420 last if (!defined $rawlines[$ln - 1]);
2421 if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
2422 $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
2445 # simplify matching -- only bother with positive lines.
2451 $realcnt-- if ($line =~ /^(?:\+| |$)/);
2457 #print "-->$line\n";
2468 $fixlinenr = -1;
2475 my $rawline = $rawlines[$linenr - 1];
2479 ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ ||
2481 $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) {
2487 $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
2491 $realline=$1-1;
2516 $realcnt-- if ($realcnt != 0);
2529 $realcnt--;
2539 if ($line =~ /^diff --git.*?(\S+)$/) {
2551 -e "$root/$p1_prefix") {
2553 "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
2558 …"do not modify files in include/asm, change architecture specific files in include/asm-<architectu…
2563 foreach (@exclude) {
2598 $is_binding_patch = () = $realfile =~ m@^(?:Documentation/devicetree/|include/dt-bindings/)@;
2600 if (($last_binding_patch != -1) &&
2603 …udes should be a separate patch. See: Documentation/devicetree/bindings/submitting-patches.rst\n");
2626 "Missing commit description - Add an appropriate one\n");
2634 $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
2635 $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
2637 "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
2647 "do not set execute permissions for source files\n" . $permhere);
2652 if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) {
2654 $author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i);
2659 if ($line =~ /^\s*signed-off-by:/i) {
2665 if ($l =~ /^\s*signed-off-by:\s*\Q$author\E/i) {
2672 if ($line =~ /^---$/) {
2685 $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
2694 "Non-standard signature: $sign_off\n" . $herecurr);
2704 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
2752 # Check Co-developed-by: immediately followed by Signed-off-by: with same name and email
2753 if ($sign_off =~ /^co-developed-by:$/i) {
2756 …"Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . "$here\n" . …
2760 … "Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline);
2761 } elsif ($rawlines[$linenr] !~ /^\s*signed-off-by:\s*(.*)/i) {
2763 …"Co-developed-by: must be immediately followed by Signed-off-by:\n" . "$here\n" . $rawline . "\n" …
2766 …"Co-developed-by and Signed-off-by: name/email do not match \n" . "$here\n" . $rawline . "\n" .$ra…
2778 # Check for Gerrit Change-Ids not in any patch context
2779 if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) {
2781 "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr);
2789 $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/) ||
2790 $line =~ /^(?:\s+\w+:\s+[0-9a-fA-F]+){3,3}/ ||
2791 $line =~ /^\s*\#\d+\s*\[[0-9a-fA-F]+\]\s*\w+ at [0-9a-fA-F]+/) {
2799 !($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ ||
2801 $line =~ /^\s*(?:[\w\.\-]+\/)++[\w\.\-]+:/ ||
2819 $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
2820 $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
2821 ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
2822 ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
2823 $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
2824 $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
2837 if ($line =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
2840 } elsif ($line =~ /\b([0-9a-f]{12,40})\b/i) {
2844 $short = 0 if ($line =~ /\bcommit\s+[0-9a-f]{12,40}/i);
2845 $long = 1 if ($line =~ /\bcommit\s+[0-9a-f]{41,}/i);
2846 $space = 0 if ($line =~ /\bcommit [0-9a-f]/i);
2847 $case = 0 if ($line =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
2848 if ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)"\)/i) {
2851 } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s*$/i &&
2856 } elsif ($line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("[^"]+$/i &&
2859 $line =~ /\bcommit\s+[0-9a-f]{5,}\s+\("([^"]+)$/i;
2872 …it commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}omm…
2876 # Check for added, moved or deleted files
2879 $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
2880 ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
2893 … "DT bindings should be in DT schema format. See: Documentation/devicetree/writing-schema.rst\n");
2897 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
2903 # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
2913 "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
2920 $rawline =~ /^(?:commit\b|from\b|[\w-]+:)/i)) {
2926 # Check if there is UTF-8 in a commit log when a mail header has explicitly
2929 $rawline =~ /^Content-Type:.+charset="(.+)".*$/ &&
2930 $1 !~ /utf-8/i) {
2937 "8-bit UTF-8 used in possible commit log\n" . $herecurr);
2958 while ($rawline =~ /(?:^|[^a-z@])($misspellings)(?:\b|$|[^a-z@])/gi) {
2961 $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
2962 $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
2966 "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $herecurr) &&
2968 $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
2974 if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) {
2984 # ignore non-hunk lines and lines being removed
2985 next if (!$hunk_line || $line =~ /^-/);
3032 for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {
3033 $f = $lines[$ln - 1];
3034 $cnt-- if ($lines[$ln - 1] !~ /^-/);
3035 $is_end = $lines[$ln - 1] =~ /^\+/;
3037 next if ($f =~ /^-/);
3040 if ($lines[$ln - 1] =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
3042 } elsif ($lines[$ln - 1] =~ /^\+\s*(?:---)?help(?:---)?$/) {
3043 $length = -1;
3072 if ($rawline =~ /^\+[A-Z]:/ &&
3073 $rawline !~ /^\+[A-Z]:\t\S/) {
3077 $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/;
3082 if ($rawline =~ /^\+[A-Z]:/ &&
3083 $prevrawline =~ /^[\+ ][A-Z]:/) {
3084 $rawline =~ /^\+([A-Z]):\s*(.*)/;
3087 $prevrawline =~ /^[\+ ]([A-Z]):\s*(.*)/;
3098 "Misordered MAINTAINERS entry - list '$cur:' before '$prev:'\n" . $hereprev);
3103 "Misordered MAINTAINERS entry - list file patterns in alphabetic order\n" . $hereprev);
3117 ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
3120 'EXTRA_AFLAGS' => 'asflags-y',
3121 'EXTRA_CFLAGS' => 'ccflags-y',
3122 'EXTRA_CPPFLAGS' => 'cppflags-y',
3123 'EXTRA_LDFLAGS' => 'ldflags-y',
3127 … of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacem…
3141 my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g;
3144 my $vp_file = $dt_path . "vendor-prefixes.txt";
3148 $compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
3150 $compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/;
3151 `grep -Erq "$compat|$compat2|$compat3" $dt_path`;
3154 "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr);
3157 next if $compat !~ /^([a-zA-Z0-9\-]+)\,/;
3159 `grep -Eq "^$vendor\\b" $vp_file`;
3162 … "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr);
3167 # check for using SPDX license tag at beginning of files
3183 # check SPDX comment style for .[chsS] files
3185 $rawline =~ /SPDX-License-Identifier:/ &&
3192 $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
3194 … "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
3195 } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
3202 not $spdx_license =~ /GPL-2\.0.*BSD-2-Clause/) {
3207 "DT binding documents should be licensed (GPL-2.0-only OR BSD-2-Clause)\n" . $herecurr) &&
3209 …$fixed[$fixlinenr] =~ s/SPDX-License-Identifier: .*/SPDX-License-Identifier: (GPL-2.0-only OR BSD-
3219 # check for using SPDX-License-Identifier on the wrong line number
3221 $rawline =~ /\bSPDX-License-Identifier:/ &&
3222 substr($line, @-, @+ - @-) eq "$;" x (@+ - @-)) {
3224 "Misplaced SPDX-License-Identifier tag - use line $checklicenseline instead\n" . $herecurr);
3251 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3266 } elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) {
3273 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3278 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3301 # more than $tabsize must use tabs, except multi-line macros which may start
3389 # check multi-line statement indentation matches previous line
3497 $line =~ /^\+[a-z_]*init/ ||
3498 $line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ ||
3512 $last_blank_line != ($linenr - 1)) {
3568 # 4) empty lines in multi-line macros
3659 (!defined $lines[$realline_next - 1] ||
3660 substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
3740 …if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[A-Z_]+|)FOR_EACH(?!_NONEMPTY_TERM)[A-Z_]+)\s*\(|do…
3747 "Too many leading tabs - consider code refactoring\n" . $herecurr);
3750 my $ctx_cnt = $realcnt - $#ctx - 1;
3757 defined $lines[$ctx_ln - 1] &&
3758 $lines[$ctx_ln - 1] =~ /^-/)) {
3760 $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
3765 #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
3767 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
3770 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
3774 defined $lines[$ctx_ln - 1])
3776 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
3780 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
3786 …if ($line =~ /\b(?:(?:if|while|for|(?:[A-Z_]+|)FOR_EACH(?!_NONEMPTY_TERM|_IDX|_FIXED_ARG|_IDX_FIXE…
3834 my $cond_ptr = -1;
3897 $prev_values = substr($curr_values, -1);
3903 if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
3905 $prevline =~ /($Lval\s*(?:\.|->))\s*$/;
3911 "Avoid multiple line dereference - prefer '$ref'\n" . $hereprev);
3967 fix_delete_line($fixlinenr - 1, $prevrawline);
4013 #print "APW <$lines[$realline_next - 1]>\n";
4015 exists $lines[$realline_next - 1] &&
4017 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
4018 $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
4024 if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
4037 #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
4047 #print "FOO B <$lines[$linenr - 1]>\n";
4136 # check for non-global char *foo[] = {"bar", ...} declarations.
4159 "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
4239 …"Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()\n" . …
4255 if ($line =~ /\bprintk\s*\(\s*(?!KERN_[A-Z]+\b)/) {
4260 if ($line =~ /\bprintk\s*\(\s*KERN_([A-Z]+)/) {
4270 if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
4280 # number of false positives, but assembly files are not checked, so at
4326 fix_delete_line($fixlinenr - 1, $prevrawline);
4419 # 1. with a type on the left -- int [] a;
4420 # 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
4421 # 3. inside a curly brace -- = { [0...10] = 5 }
4424 my ($where, $prefix) = ($-[1], $1);
4442 my $ctx_before = substr($line, 0, $-[1]);
4452 # cpp #define statements have non-optional spaces, ie
4481 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
4482 =>|->|<<|>>|<|>|=|!|~|
4483 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
4504 my $last_after = -1;
4583 # ->
4584 } elsif ($op eq '->') {
4626 # '*' as part of a type definition -- reported already.
4634 $opv eq '*U' || $opv eq '-U' ||
4636 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
4659 # unary ++ and unary -- are allowed no space on one side.
4660 } elsif ($op eq '++' or $op eq '--') {
4690 $op eq '+' or $op eq '-' or
4792 # check for whitespace before a non-naked semicolon
4893 # ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
4905 # ie: (foo->bar)(); should be foo->bar();
4906 # but not "if (foo->bar) (" to avoid some false positives
4919 # when !drivers/staging or command-line uses --strict
4924 my $test = substr($2, 1, -1);
4948 if ($sline =~ /^.\s+[A-Za-z_][A-Za-z\d_]*:(?!\s*\d+)/ &&
4949 $sline !~ /^. [A-Za-z\d_][A-Za-z\d_]*:/ &&
4977 # at end-of-function, with the previous line a single leading tab, then return;
4982 $lines[$linenr - 3] =~ /^[ +]/ &&
4983 $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
4988 # if statements using unnecessary parentheses - ie: if ((foo == bar))
4996 $msg = " - maybe == should be = ?" if ($comp eq "==");
5007 …!($line =~ /^\+(.*)($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*(.*)($Constant|[A-Z_][A-Z0-9_]*)(.*…
5008 $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
5015 $to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
5033 if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
5039 "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
5054 # Check for illegal assignment in if conditional -- and check for trailing
5069 ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
5071 statement_rawlines($whitespace) - 1;
5137 \s*0[xX][0-9]+\s*
5141 \s*0[xX][0-9]+\s*
5182 fix_delete_line($fixlinenr - 1, $prevrawline);
5208 fix_delete_line($fixlinenr - 1, $prevrawline);
5226 $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
5228 $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
5231 $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ &&
5233 $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
5236 next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
5267 if (-f "$root/$checkfile" &&
5271 my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
5284 # multi-statement macros should be enclosed in a do while loop, grab the
5299 #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
5310 $define_args = substr($define_args, 1, length($define_args) - 2);
5357 $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
5358 $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
5359 …$dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // f…
5366 $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
5373 …"Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic d…
5376 … "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx");
5384 # Make $define_stmt single line, comment-free, etc
5412 "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");
5446 # single-statement macros do not need to be enclosed in do while (0) loop,
5500 my $ln = $linenr - 1;
5505 my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
5506 my $offset = statement_rawlines($whitespace) - 1;
5515 $ln += statement_rawlines($block) - 1;
5552 if (!defined $suppress_ifbraces{$linenr - 1} &&
5556 # Check the pre-context.
5557 if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
5563 ctx_statement_full($linenr, $realcnt, $-[0]);
5583 # Check the post-context.
5590 #print "APW: ALLOWED: chunk-1 block<$block>\n";
5614 fix_delete_line($fixlinenr - 1, $prevrawline);
5629 …"Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst\n" . …
5632 # Check for user-visible strings broken across lines, which breaks the ability
5638 $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) {
5643 $last_coalesced_string_linenr != $linenr - 1) {
5650 fix_delete_line($fixlinenr - 1, $prevrawline);
5655 fix_insert_line($fixlinenr - 1, $fixedline);
5672 # This does not work very well for -f --file checking as it depends on patch
5673 # context providing the function name or a single line form for in-file
5694 if ($line =~ /$String[A-Za-z0-9_]/ || $line =~ /[A-Za-z0-9_]$String/) {
5699 my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
5700 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/;
5701 $fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/;
5712 my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
5713 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e;
5718 # check for non-standard and hex prefixed decimal printf formats
5722 my $string = substr($rawline, $-[1], $+[1] - $-[1]);
5727 "\%L$1 is non-standard C, use %ll$1\n" . $herecurr);
5733 "%Z$1 is non-standard C, use %z$1\n" . $herecurr);
5773 if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
5778 if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
5787 fix_delete_line($fixlinenr - 1, $prevrawline);
5800 my $testline = $lines[$linenr - 3];
5802 my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0);
5814 $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
5834 … "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr);
5898 # check for __read_mostly with const non-pointer (should just be const)
5927 … "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.rst\n" . $herecurr);
5931 "long udelay - prefer mdelay; see arch/arm/include/asm/delay.h\n" . $herecurr);
5939 …"msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.rst\n" . $herecurr);
5955 # warn about #ifdefs in C files
5957 # print "#ifdef in C files should be avoided\n";
6012 if ($realfile !~ m@^include/asm-generic/@ &&
6017 "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . $herecurr);
6037 … m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
6092 my $old = substr($rawline, $-[1], $+[1] - $-[1]);
6093 my $new = substr($old, 1, -1);
6105 …"__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-ind…
6116 …"__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index…
6217 my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
6243 $use = " - use %pS instead";
6345 …"usleep_range should not use min == max args; see Documentation/timers/timers-howto.rst\n" . "$her…
6349 …"usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.rst\n" . "$he…
6385 # check for new externs in .h files.
6389 "extern prototypes should be avoided in .h files\n" . $herecurr) &&
6395 # check for new externs in .c files.
6409 "externs should be avoided in .c files\n" . $herecurr);
6421 "externs should be avoided in .c files\n" . $herecurr);
6467 …"__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.txt\n" . $here…
6474 … "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
6501 !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
6553 "do not specify non-standard feature test macros for embedded code\n" . "$here$rawline\n");
6563 …if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(CONFIG_[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*…
6595 "Use of the '$1' macro makes the build non-deterministic\n" . $herecurr);
6607 "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr);
6688 …"usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_po…
6694 … "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
6734 "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
6741 …"Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $…
6749 …E_ATTR\s*\(\s*(\w+)\s*,\s*\(?\s*(\s*(?:${multi_mode_perms_string_search}|0[0-7]{3,3})\s*)\s*\)?\s*…
6811 my $func = $entry->[0];
6812 my $arg_pos = $entry->[1];
6820 $arg_pos--;
6835 …"Exporting writable files is usually an error. Consider more restrictive permissions.\n" . "$here\…
6879 if ($#rawlines == -1) {
6889 # This is not a patch, and we are are in 'no-patch' mode so
6895 if (!$is_patch && $filename !~ /cover-letter\.patch$/) {
6897 "Does not appear to be a unified-diff format patch\n");
6902 "Missing Signed-off-by: line(s)\n");
6905 "Missing Signed-off-by: line by nominal patch author '$author'\n");
6923 mechanically convert to the typical style using --fix or --fix-inplace.
6942 $newfile .= ".EXPERIMENTAL-checkpatch-fixes" if (!$fix_inplace);
6966 Wrote EXPERIMENTAL --fix correction(s) to '$newfile'