Lines Matching +full:s +full:-

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>
69 my $docsfile = "$D/../Documentation/dev-tools/checkpatch.rst";
72 my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE
74 my $git_command ='export LANGUAGE=en_US.UTF-8; git';
88 -q, --quiet quiet
89 -v, --verbose verbose mode
90 --no-tree run without a kernel tree
91 --no-signoff do not check for 'Signed-off-by' line
92 --no-fixes-tag do not check for 'Fixes:' tag
93 --patch treat FILE as patchfile (default)
94 --emacs emacs compile window format
95 --terse one line per report
96 --showfile emit diffed file position, not input file position
97 -g, --git treat FILE as a single commit or git revision range
105 <rev>-<count>
107 -f, --file treat FILE as regular source file
108 --subjective, --strict enable more subjective tests
109 --list-types list the possible message types
110 --types TYPE(,TYPE2...) show only these comma separated message types
111 --ignore TYPE(,TYPE2...) ignore various comma separated message types
112 --show-types show the specific message type in the output
113 --max-line-length=n set the maximum line length, (default $max_line_length)
115 requires --strict for use with --file
116 --min-conf-desc-length=n set the minimum description length for config symbols
118 --tab-size=n set the number of spaces for tab (default $tabsize)
119 --root=PATH PATH to the kernel tree root
120 --no-summary suppress the per-file summary
121 --mailback only produce a report in case of warnings/errors
122 --summary-file include the filename in summary
123 --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
126 --test-only=WORD report only warnings/errors containing WORD
128 --fix EXPERIMENTAL - may create horrible results
129 If correctable single-line errors exist, create
130 "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
133 --fix-inplace EXPERIMENTAL - may create horrible results
134 Is the same as --fix, but overwrites the input
135 file. It's your fault if there's no backup or git
136 --ignore-perl-version override checking of perl version. expect
138 --codespell Use the codespell dictionary for spelling/typos
140 --codespellfile Use this codespell dictionary
141 --typedefsfile Read additional types from this file
142 --color[=WHEN] Use colors 'always', 'never', or only when output
144 --kconfig-prefix=WORD use WORD as a prefix for Kconfig symbols (default
146 -h, --help, --version display this help and exit
148 When FILE is - read standard input.
155 do {} while (0) advice is over-stated in a few situations:
158 file-scope, where C disallows code (it must be in functions). See
162 like DECLARE_PER_CPU. These might just compile with a do-while-0
167 expression. These cannot do-while, and need a ({}) wrapper.
192 while ($text =~ /(?:(\bCHK|\bWARN|\bERROR|&\{\$msg_level})\s*\(|\$msg_type\s*=)\s*"([^"]+)"/g) {
232 $message =~ s/\n/\n\t/g;
241 if (-f $conf) {
249 $line =~ s/\s*\n?$//g;
250 $line =~ s/^\s*//g;
251 $line =~ s/\s+/ /g;
253 next if ($line =~ m/^\s*#/);
254 next if ($line =~ m/^\s*$/);
277 $line =~ s/\s+$//;
279 if ($line =~ /^\s*\*\*(.+)\*\*$/) {
287 if ($line =~ /^(?:\s{4,}|$)/) {
288 $line =~ s/^\s{4}//;
306 # Perl's Getopt::Long allows options to take optional arguments after a space.
307 # Prevent --color by itself from consuming other arguments
309 if ($_ eq "--color" || $_ eq "-color") {
310 $_ = "--color=$color";
319 'fixes-tag!' => \$chk_fixes_tag,
328 'ignore=s' => \@ignore,
329 'types=s' => \@use,
330 'show-types!' => \$show_types,
331 'list-types!' => \$list_types,
332 'max-line-length=i' => \$max_line_length,
333 'min-conf-desc-length=i' => \$min_conf_desc_length,
334 'tab-size=i' => \$tabsize,
335 'root=s' => \$root,
338 'summary-file!' => \$summary_file,
340 'fix-inplace!' => \$fix_inplace,
341 'ignore-perl-version!' => \$ignore_perl_version,
342 'debug=s' => \%debug,
343 'test-only=s' => \$tst_only,
345 'codespellfile=s' => \$user_codespellfile,
346 'typedefsfile=s' => \$typedefsfile,
347 'color=s' => \$color,
348 'no-color' => \$color, #keep old behaviors of -nocolor
349 'nocolor' => \$color, #keep old behaviors of -nocolor
350 'kconfig-prefix=s' => \${CONFIG_},
358 } elsif (!(-f $codespellfile)) {
360 # under codespell's install directory: <codespell_root>/data/dictionary.txt
371 my $codespell_dict = `python3 -c "$python_codespell_dict" 2> /dev/null`;
372 $codespellfile = $codespell_dict if (-f $codespell_dict);
376 # $help is 1 if either -h, --help or --version is passed as option - exitcode: 0
377 # $help is 2 if invalid option is passed - exitcode: 1
378 help($help - 1) if ($help);
380 die "$P: --git cannot be used with --file or --fix\n" if ($git && ($file || $fix));
381 die "$P: --verbose cannot be used with --terse\n" if ($verbose && $terse);
390 $color = (-t STDOUT);
410 #if no filenames are given, push '-' to read patch from stdin
412 push(@ARGV, '-');
415 # skip TAB size 1 to avoid additional checks on $tabsize - 1
423 $word =~ s/\s*\n?$//g;
424 $word =~ s/^\s*//g;
425 $word =~ s/\s+/ /g;
426 $word =~ tr/[a-z]/[A-Z]/;
428 next if ($word =~ m/^\s*#/);
429 next if ($word =~ m/^\s*$/);
431 $hashRef->{$word}++;
470 die "$P: $root: --root does not point at a valid tree\n";
482 print "Must be run from the top-level dir. of a kernel tree\n";
490 [A-Za-z_][A-Za-z\d_]*
491 (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
537 __aligned\s*\(.*\)|
542 __alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\)
546 our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
551 our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
552 our $Int = qr{[0-9]+$Int_type?};
553 our $Octal = qr{0[0-7]+$Int_type?};
555 our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
556 our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
557 our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
560 our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
561 our $Compare = qr{<=|>=|==|!=|<|(?<!-)>};
562 our $Arithmetic = qr{\+|-|\*|\/|%};
565 =>|->|<<|>>|<|>|!|~|
566 &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
581 [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
582 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
583 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
584 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
585 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
586 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
587 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
591 [\x09\x0A\x0D\x20-\x7E] # ASCII
601 (?:__)?(?:u|s|be|le)(?:8|16|32|64)|
618 …(?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|co…
622 MODULE_[A-Z_]+|
637 Signed-off-by:|
638 Co-developed-by:|
639 Acked-by:|
640 Tested-by:|
641 Reviewed-by:|
642 Reported-by:|
643 Suggested-by:|
665 [=-]*> |
666 <[=-]* |
685 [\.\!:\s]*
689 our $dev_id_types = qr{\b[a-z]\w*_device_id\b};
699 for my $i (0 .. ($len-1)) {
711 $str1 =~ s/-//g;
712 $str2 =~ s/-//g;
723 } elsif (substr($str1, $i-1, 1) eq substr($str2, $j-1, 1)) {
724 $distance[$i][$j] = $distance[$i - 1][$j - 1];
726 my $dist1 = $distance[$i][$j - 1]; #insert distance
727 my $dist2 = $distance[$i - 1][$j]; # remove
728 my $dist3 = $distance[$i - 1][$j - 1]; #replace
739 'Signed-off-by:', 'Co-developed-by:', 'Acked-by:', 'Tested-by:',
740 'Reviewed-by:', 'Reported-by:', 'Suggested-by:'
750 \Qfreedesktop.org/archives/dri-devel\E |
753 \Qmail-archive.com\E |
754 \Qmailman.alsa-project.org/pipermail\E |
761 qr{char\s+(?:un)?signed},
762 qr{int\s+(?:(?:un)?signed\s+)?short\s},
763 qr{int\s+short(?:\s+(?:un)?signed)},
764 qr{short\s+int(?:\s+(?:un)?signed)},
765 qr{(?:un)?signed\s+int\s+short},
766 qr{short\s+(?:un)?signed},
767 qr{long\s+int\s+(?:un)?signed},
768 qr{int\s+long\s+(?:un)?signed},
769 qr{long\s+(?:un)?signed\s+int},
770 qr{int\s+(?:un)?signed\s+long},
771 qr{int\s+(?:un)?signed},
772 qr{int\s+long\s+long\s+(?:un)?signed},
773 qr{long\s+long\s+int\s+(?:un)?signed},
774 qr{long\s+long\s+(?:un)?signed\s+int},
775 qr{long\s+long\s+(?:un)?signed},
776 qr{long\s+(?:un)?signed},
781 qr{(?:(?:un)?signed\s+)?char},
782 qr{(?:(?:un)?signed\s+)?short\s+int},
783 qr{(?:(?:un)?signed\s+)?short},
784 qr{(?:(?:un)?signed\s+)?int},
785 qr{(?:(?:un)?signed\s+)?long\s+int},
786 qr{(?:(?:un)?signed\s+)?long\s+long\s+int},
787 qr{(?:(?:un)?signed\s+)?long\s+long},
788 qr{(?:(?:un)?signed\s+)?long},
793 qr{struct\s+$Ident},
794 qr{union\s+$Ident},
795 qr{enum\s+$Ident},
803 long\s+long\s+int\s+(?:un)?signed|
804 long\s+long\s+(?:un)?signed\s+int|
805 long\s+long\s+(?:un)?signed|
806 (?:(?:un)?signed\s+)?long\s+long\s+int|
807 (?:(?:un)?signed\s+)?long\s+long|
808 int\s+long\s+long\s+(?:un)?signed|
809 int\s+(?:(?:un)?signed\s+)?long\s+long|
811 long\s+int\s+(?:un)?signed|
812 long\s+(?:un)?signed\s+int|
813 long\s+(?:un)?signed|
814 (?:(?:un)?signed\s+)?long\s+int|
815 (?:(?:un)?signed\s+)?long|
816 int\s+long\s+(?:un)?signed|
817 int\s+(?:(?:un)?signed\s+)?long|
819 int\s+(?:un)?signed|
820 (?:(?:un)?signed\s+)?int
826 qr{struct\s+$InitAttribute\s+$Ident},
827 qr{union\s+$InitAttribute\s+$Ident},
842 ["IIO_DEV_ATTR_[A-Z_]+", 1],
848 my $word_pattern = '\b[A-Z]?[a-z]{2,}\b';
854 $mode_perms_search .= $entry->[0];
878 0[0-7][0-7][2367]
909 (?:\s*\|\s*${single_mode_perms_string_search})*
915 return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/);
922 while ($string =~ /\b(($single_mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) {
926 last if ($lastpos > 0 && ($curpos - length($omatch) != $lastpos));
929 $val .= '\s*\|\s*' if ($val ne "");
933 $oval =~ s/^\s*\|\s*//;
934 $oval =~ s/\s*\|\s*$//;
954 $line =~ s/\s*\n?$//g;
955 $line =~ s/^\s*//g;
957 next if ($line =~ m/^\s*#/);
958 next if ($line =~ m/^\s*$/);
966 warn "No typos will be found - file '$spelling_file': $!\n";
974 $line =~ s/\s*\n?$//g;
975 $line =~ s/^\s*//g;
977 next if ($line =~ m/^\s*#/);
978 next if ($line =~ m/^\s*$/);
981 $line =~ s/,.*$//;
983 my ($suspect, $fix) = split(/->/, $line);
989 warn "No codespell typos will be found - file '$codespellfile': $!\n";
1002 $line =~ s/\s*\n?$//g;
1003 $line =~ s/^\s*//g;
1005 next if ($line =~ m/^\s*#/);
1006 next if ($line =~ m/^\s*$/);
1007 if ($line =~ /\s/) {
1008 print("$file: '$line' invalid - ignored\n");
1025 or warn "No structs that should be const will be found - file '$conststructsfile': $!\n";
1031 or warn "No additional types will be considered - file '$typedefsfile': $!\n";
1046 (?:$Modifier\s+|const\s+)*
1048 (?:typeof|__typeof__)\s*\([^\)]*\)|
1052 (?:\s+$Modifier|\s+const)*
1055 (?:$Modifier\s+|const\s+)*
1059 (?:\s+$Modifier|\s+const)*
1062 (?:$Modifier\s+|const\s+)*
1064 (?:typeof|__typeof__)\s*\([^\)]*\)|
1068 (?:\s+$Modifier|\s+const)*
1072 (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4}
1073 (?:\s+$Inline|\s+$Modifier)*
1077 (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4}
1078 (?:\s+$Inline|\s+$Modifier)*
1080 $Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type};
1081 $DeclareMisordered = qr{(?:$Storage\s+(?:$Inline\s+)?)?$TypeMisordered};
1085 our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
1091 our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
1092 our $LvalOrFunc = qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*};
1096 (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
1097 (?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(|
1098 (?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\(|
1099 (?:$Storage\s+)?(?:XA_STATE|XA_STATE_ORDER)\s*\(
1113 while ($string =~ /^\s*\(.*\)\s*$/) {
1114 $string =~ s@^\s*\(\s*@@;
1115 $string =~ s@\s*\)\s*$@@;
1118 $string =~ s@\s+@ @g;
1126 return if (!(-f $file));
1138 next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
1139 if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
1141 } elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
1143 } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
1154 return 0 if (!$tree || !(-e "$root/scripts/get_maintainer.pl"));
1157 …s{$filename} = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback…
1166 …return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitr…
1169 my $status = `cd "$root_path"; echo "$license" | scripts/spdxcheck.py -`;
1184 if (-e "$gitroot") {
1185 …my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include…
1187 $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
1190 $files = `find $root/include -name "*.h"`;
1197 $camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
1200 if ($camelcase_cache ne "" && -f $camelcase_cache) {
1212 if (-e "$gitroot") {
1213 $files = `${git_command} ls-files "include/*.h"`;
1222 unlink glob ".checkpatch-camelcase.*";
1235 return 0 if ((which("git") eq "") || !(-e "$gitroot"));
1237 my $output = `${git_command} ls-files -- $filename 2>/dev/null`;
1245 return ($id, $desc) if ((which("git") eq "") || !(-e "$gitroot"));
1247 my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`;
1248 $output =~ s/^\s*//gm;
1255 # all matching commit ids, but it's very slow...
1258 # git rev-list --remotes | grep -i "^$1" |
1260 # git log --format='%H %s' -1 $line |
1261 # echo "commit $(cut -c 1-12,41-)"
1282 my $fixlinenr = -1;
1285 # For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.
1286 die "$P: No git repository found\n" if ($git && !-e "$gitroot");
1292 if ($commit_expr =~ m/^(.*)-(\d+)$/) {
1293 $git_range = "-$2 $1";
1297 $git_range = "-1 $commit_expr";
1299 my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`;
1301 $line =~ /^([0-9a-fA-F]{40,40}) (.*)$/;
1321 open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||
1322 die "$P: $filename: git format-patch failed - $!\n";
1324 open($FILE, '-|', "diff -u /dev/null $filename") ||
1325 die "$P: $filename: diff failed - $!\n";
1326 } elsif ($filename eq '-') {
1330 die "$P: $filename: open failed - $!\n";
1332 if ($filename eq '-') {
1342 $vname = qq("$1") if ($filename eq '-' && $_ =~ m/^Subject:\s+(.+)/i);
1347 print '-' x length($vname) . "\n";
1349 print '-' x length($vname) . "\n";
1360 $fixlinenr = -1;
1399 if (! -e $root . '/' . $check) {
1415 if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) {
1419 } elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) {
1422 } elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) {
1425 $formatted_email =~ s/\Q$address\E.*$//;
1428 $name =~ s/^\"|\"$//g;
1429 # If there's a name left after stripping spaces and
1443 # "John D. (Doe)" - Do not extract
1444 if ($name =~ s/\"(.+)\"//) {
1447 while ($name =~ s/\s*($balanced_parens)\s*/ /) {
1450 $name =~ s/^[ \"]+|[ \"]+$//g;
1454 $address =~ s/^\<|\>$//g;
1457 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
1458 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
1470 $name =~ s/^[ \"]+|[ \"]+$//g;
1472 $address =~ s/(?:\.|\,|\")+$//; ##trailing commas, dots or quotes
1474 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
1475 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
1516 if (-e "$path/$bin") {
1528 if (-e "$path/$conf") {
1565 $line =~ s/^.//;
1569 my ($white) = ($line =~ /^(\s*)/);
1660 if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {
1662 $res =~ s@\<.*\>@<$clean>@;
1665 } elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {
1667 $res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@;
1672 $res =~ s/\Q$match\E/"$;" x length($match)/e;
1683 return substr($rawline, $-[0], $+[0] - $-[0]);
1688 my $line = $linenr - 1;
1691 my $coff = $off - 1;
1705 @stack = (['', 0]) if ($#stack == -1);
1713 next if ($lines[$line] =~ /^-/);
1714 $remain--;
1726 if ($level == 0 && substr($blk, $off) =~ /^.\s*#\s*define/) {
1738 if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
1740 } elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
1741 ($type, $level) = @{$stack[$#stack - 1]};
1742 } elsif ($remainder =~ /^#\s*endif\b/) {
1754 (!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
1755 $remainder =~ /^(else)(?:\s|{)/ &&
1756 $remainder !~ /^else\s+if\b/) {
1757 $coff = $off + length($1) - 1;
1760 #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
1768 $level--;
1782 $level--;
1794 $level--;
1805 $remain--;
1808 my $statement = substr($blk, $soff, $off - $soff + 1);
1809 my $condition = substr($blk, $soff, $coff - $soff + 1);
1817 $line, $remain + 1, $off - $loff + 1, $level);
1824 $stmt =~ s/(^|\n)./$1/g;
1825 $stmt =~ s/^\s*//;
1826 $stmt =~ s/\s*$//;
1844 $stmt =~ s/(^|\n)./$1/g;
1845 $stmt =~ s/^\s*{//;
1846 $stmt =~ s/}\s*$//;
1847 $stmt =~ s/^\s*//;
1848 $stmt =~ s/\s*$//;
1872 #print "F: c<$condition> s<$statement> remain<$remain>\n";
1874 if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
1883 #print "C: c<$condition> s<$statement> remain<$remain>\n";
1884 last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
1895 my $start = $linenr - 1;
1904 next if ($rawlines[$line] =~ /^-/);
1905 $remain--;
1910 if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
1912 } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
1913 $level = $stack[$#stack - 1];
1914 } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
1921 $off--;
1926 $level--;
1975 my ($current_comment) = ($rawlines[$end_line - 1] =~ m@^\+.*(//.*$)@);
1977 ($current_comment) = ($rawlines[$end_line - 2] =~ m@^[\+ ].*(//.*$)@);
1983 ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
1991 my $line = $rawlines[$linenr - 1];
1993 if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
2015 ##print "LINE: $rawlines[$end_line - 1 ]\n";
2024 my $offset = $linenr - 1;
2030 next if (defined($line) && $line =~ /^-/);
2031 $cnt--;
2071 $res =~ s/$/\$/;
2101 if ($cur =~ /^(\s+)/o) {
2108 } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
2113 } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
2117 } elsif ($cur =~ /^($Modifier)\s*/) {
2121 } elsif ($cur =~ /^(\#\s*define\s*$Ident)(\(?)/o) {
2130 } elsif ($cur =~ /^(\#\s*(?:undef\s*$Ident|include\b))/o) {
2135 } elsif ($cur =~ /^(\#\s*(?:ifdef|ifndef|if))/o) {
2143 } elsif ($cur =~ /^(\#\s*(?:else|elif))/o) {
2151 } elsif ($cur =~ /^(\#\s*(?:endif))/o) {
2165 } elsif ($cur =~ /^(__attribute__)\s*\(?/o) {
2170 } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
2201 print "PAREN('$1') -> $type\n"
2207 } elsif ($cur =~ /^($Ident)\s*\(/o) {
2212 } elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) {
2257 } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
2272 if ($1 ne '++' && $1 ne '--') {
2295 DEFINE_\S+
2306 )(?:\s|$)|
2312 $possible =~ s/\s*$Storage\s*//g;
2313 $possible =~ s/\s*$Sparse\s*//g;
2314 if ($possible =~ /^\s*$/) {
2316 } elsif ($possible =~ /\s/) {
2317 $possible =~ s/\s*$Type\s*//g;
2340 $type =~ tr/[a-z]/[A-Z]/;
2373 my @lines = split("\n", $output, -1);
2400 if ($$lineRef =~ /^\@\@ -\d+,\d+ \+(\d+),(\d+) \@\@/) {
2405 $$lineRef =~ s/\+$o,$l \@\@/\+$no,$nl \@\@/;
2429 if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename
2431 } elsif ($line =~ /^\@\@ -\d+,\d+ \+\d+,\d+ \@\@/) { #new hunk
2439 fixup_current_range(\$lines[$range_last_linenr], $delta_offset--, -1);
2519 while ($file =~ s@^[^/]*/@@) {
2520 if (-f "$root/$file") {
2525 if (! -f _) {
2531 substr($prefix, -length($file)) = '';
2543 $string =~ s/^\s+|\s+$//g;
2551 $string =~ s/^\s+//;
2559 $string =~ s/\s+$//;
2567 $string =~ s/$find/$replace/g;
2576 my $max_spaces_before_tab = $source_indent - 1;
2580 1 while $leading =~ s@^([\t]*)$spaces_to_tab@$1\t@g;
2582 1 while $leading =~ s@^([\t]*)( {1,$max_spaces_before_tab})\t@$1\t@g;
2598 return -1;
2606 $pos += length($1) - 1;
2609 } elsif (index($string, '(') == -1) {
2621 for my $i (0 .. (length($line) - 1)) {
2662 my $is_binding_patch = -1;
2665 my $has_patch_separator = 0; #Found a --- line
2674 my $last_git_commit_id_linenr = -1;
2677 my $last_coalesced_string_linenr = -1;
2690 my $context_function; #undef'd unless there's a known function
2706 # Pre-scan the patch sanitizing the lines.
2707 # Pre-scan the patch looking for any __setup documentation.
2724 if ($rawline=~/^\+\+\+\s+(\S+)/) {
2726 if ($1 =~ m@Documentation/admin-guide/kernel-parameters.txt$@) {
2731 if ($rawline =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
2732 $realline=$1-1;
2747 next if (defined $rawlines[$ln - 1] &&
2748 $rawlines[$ln - 1] =~ /^-/);
2749 $cnt--;
2750 #print "RAW<$rawlines[$ln - 1]>\n";
2751 last if (!defined $rawlines[$ln - 1]);
2752 if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
2753 $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
2766 $rawlines[$linenr] =~ m@^.\s*(?:\*\*+| \*)(?:\s|$)@)
2776 # simplify matching -- only bother with positive lines.
2782 $realcnt-- if ($line =~ /^(?:\+| |$)/);
2788 #print "-->$line\n";
2799 $fixlinenr = -1;
2804 $sline =~ s/$;/ /g; #with comments as spaces
2806 my $rawline = $rawlines[$linenr - 1];
2809 # check if it's a mode change, rename or start of a patch
2811 ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ ||
2812 ($line =~ /^rename (?:from|to) \S+\s*$/ ||
2813 $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) {
2819 $line =~ /^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@(.*)/) {
2823 $realline=$1-1;
2836 if ($context =~ /\b(\w+)\s*\(/) {
2848 $realcnt-- if ($realcnt != 0);
2861 $realcnt--;
2871 if ($line =~ /^diff --git.*?(\S+)$/) {
2873 $realfile =~ s@^([^/]*)/@@ if (!$file);
2876 } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
2878 $realfile =~ s@^([^/]*)/@@ if (!$file);
2883 -e "$root/$p1_prefix") {
2885 "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
2921 $is_binding_patch = () = $realfile =~ m@^(?:Documentation/devicetree/|include/dt-bindings/)@;
2923 if (($last_binding_patch != -1) &&
2926 …udes should be a separate patch. See: Documentation/devicetree/bindings/submitting-patches.rst\n");
2944 if ($line !~ /^\s*$/) {
2949 "Missing commit description - Add an appropriate one\n");
2955 (($line =~ m@^\s+diff\b.*a/([\w/]+)@ &&
2956 $line =~ m@^\s+diff\b.*a/[\w/]+\s+b/$1\b@) ||
2957 $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
2958 $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
2960 "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
2975 if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) {
2978 while(defined($rawlines[$curline]) && ($rawlines[$curline++] =~ /^[ \t]\s*(.*)/)) {
2981 $author = encode("utf8", $author) if ($line =~ /=\?utf-8\?/i);
2982 $author =~ s/"//g;
2987 if ($line =~ /^\s*signed-off-by:\s*(.*)/i) {
3011 if ($address1 =~ /(\S+)\+\S+(\@.*)/) {
3014 if ($address2 =~ /(\S+)\+\S+(\@.*)/) {
3026 if ($line =~ /^---$/) {
3031 # Check if MAINTAINERS is being updated. If so, there's probably no need to
3033 if ($line =~ /^\s*MAINTAINERS\s*\|/) {
3039 $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
3050 "Non-standard signature: $sign_off\n" . $herecurr);
3053 "Non-standard signature: '$sign_off' - perhaps '$suggested_signature'?\n" . $herecurr) &&
3055 $fixed[$fixlinenr] =~ s/$sign_off/$suggested_signature/;
3067 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
3092 $dequoted =~ s/^"//;
3093 $dequoted =~ s/" </ </;
3100 $fixed[$fixlinenr] =~ s/\Q$email\E/$suggested_email/;
3106 $stripped_address =~ s/\([^\(\)]*\)//g;
3111 $fixed[$fixlinenr] =~ s/\Q$email_address\E/$stripped_address/;
3131 $cur_name =~ s/[a-zA-Z\s\-\"]+//g;
3135 $new_comment =~ s/^\((.*)\)$/$1/;
3136 $new_comment =~ s/^\[(.*)\]$/$1/;
3137 $new_comment =~ s/^[\s\#]+|\s+$//g;
3146 $fixed[$fixlinenr] =~ s/\Q$email\E/$new_email/;
3154 $new_comment =~ s/^\[(.*)\]$/$1/;
3155 $new_comment =~ s/^\/\*(.*)\*\/$/$1/;
3158 … $new_comment =~ s/^[^\w]$//; # Single lettered comment with non word character is usually a typo
3165 $fixed[$fixlinenr] =~ s/\Q$email\E/$new_email/;
3172 $sig_nospace =~ s/\s//g;
3181 # Check Co-developed-by: immediately followed by Signed-off-by: with same name and email
3182 if ($sign_off =~ /^co-developed-by:$/i) {
3185 … "Co-developed-by: should not be used to attribute nominal patch author '$author'\n" . $herecurr);
3189 "Co-developed-by: must be immediately followed by Signed-off-by:\n" . $herecurr);
3190 } elsif ($rawlines[$linenr] !~ /^signed-off-by:\s*(.*)/i) {
3192 …"Co-developed-by: must be immediately followed by Signed-off-by:\n" . $herecurr . $rawlines[$linen…
3195 …"Co-developed-by and Signed-off-by: name/email do not match\n" . $herecurr . $rawlines[$linenr] . …
3199 # check if Reported-by: is followed by a Closes: tag
3200 if ($sign_off =~ /^reported(?:|-and-tested)-by:$/i) {
3203 …"Reported-by: should be immediately followed by Closes: with a URL to the report\n" . $herecurr . …
3204 } elsif ($rawlines[$linenr] !~ /^closes:\s*/i) {
3206 …"Reported-by: should be immediately followed by Closes: with a URL to the report\n" . $herecurr . …
3224 $line =~ /^\s*(fixes:?)\s*(?:commit\s*)?([0-9a-f]{5,40})(?:\s*($balanced_parens))?/i) {
3232 $title = substr($3, 1, -1);
3234 $title = substr($title, 1, -1);
3243 my $tag_space = not ($line =~ /^fixes:? [0-9a-f]{5,40} ($balanced_parens)/i);
3245 my $id_length = not ($orig_commit =~ /^[0-9a-f]{12,40}$/i);
3246 my $id_case = not ($orig_commit !~ /[A-F]/);
3255 …"Please use correct Fixes: style 'Fixes: <12+ chars of sha1> (\"<title line>\")' - ie: '$fixed'\n"…
3269 # Check for Gerrit Change-Ids not in any patch context
3270 if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) {
3272 "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr) &&
3280 ($line =~ /^\s*(?:WARNING:|BUG:)/ ||
3281 $line =~ /^\s*\[\s*\d+\.\d{6,6}\s*\]/ ||
3283 $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/) ||
3284 $line =~ /^(?:\s+\w+:\s+[0-9a-fA-F]+){3,3}/ ||
3285 $line =~ /^\s*\#\d+\s*\[[0-9a-fA-F]+\]\s*\w+ at [0-9a-fA-F]+/) {
3293 !($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ ||
3295 $line =~ /^\s*(?:[\w\.\-\+]*\/)++[\w\.\-\+]+:/ ||
3297 $line =~ /^\s*(?:Fixes:|$link_tags_search|$signature_tags)/i ||
3307 $line =~ /^\s*$/) {
3313 $line =~ /^\s*(\w+:)\s*http/ && $1 !~ /^$link_tags_search$/) {
3316 "Patch version information should be after the --- line\n" . $herecurr);
3325 $line =~ /^\s*(\w+:)\s*(\S+)/) {
3330 "'$tag' should be followed by a public http(s) link\n" . $herecurr);
3339 $fixed[$fixlinenr] =~ s/^/ /;
3345 # commit <SHA-1 hash length 12+ chars> ("Complete commit subject")
3348 # bare SHA-1 hash with minimum length of 5. It also avoids several types of
3349 # possible SHA-1 matches.
3354 $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
3355 $line !~ /^This reverts commit [0-9a-f]{7,40}/ &&
3356 (($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
3357 …($line =~ /\bcommit\s*$/i && defined($rawlines[$linenr]) && $rawlines[$linenr] =~ /^\s*[0-9a-f]{5,…
3358 ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
3359 $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i &&
3360 $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
3375 if ($line =~ /(?:\bcommit\s+[0-9a-f]{5,}|\bcommit\s*$)/i) {
3377 if ($input =~ /\bcommit\s+[0-9a-f]{5,}\s*($balanced_parens)/i) {
3381 $orig_desc = substr($orig_desc, 1, -1);
3383 $orig_desc = substr($orig_desc, 1, -1);
3395 if ($input =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
3398 $short = 0 if ($input =~ /\bcommit\s+[0-9a-f]{12,40}/i);
3399 $long = 1 if ($input =~ /\bcommit\s+[0-9a-f]{41,}/i);
3400 $space = 0 if ($input =~ /\bcommit [0-9a-f]/i);
3401 $case = 0 if ($input =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
3402 } elsif ($input =~ /\b([0-9a-f]{12,40})\b/i) {
3411 $last_git_commit_id_linenr != $linenr - 1) {
3413 …it commit description style 'commit <12+ chars of sha1> (\"<title line>\")' - ie: '${init_char}omm…
3416 $last_git_commit_id_linenr = $linenr if ($line =~ /\bcommit\s*$/i);
3422 …"Use lore.kernel.org archive links when possible - see https://lore.kernel.org/lists.html\n" . $he…
3427 ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ ||
3428 $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
3429 ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
3434 "added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
3439 ($line =~ /^new file mode\s*\d+\s*$/) &&
3442 …"DT bindings should be in DT schema format. See: Documentation/devicetree/bindings/writing-schema.…
3446 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
3452 # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
3462 "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
3465 # Check if it's the start of a commit log
3468 !($rawline =~ /^\s+(?:\S|$)/ ||
3469 $rawline =~ /^(?:commit\b|from\b|[\w-]+:)/i)) {
3475 # Check if there is UTF-8 in a commit log when a mail header has explicitly
3478 $rawline =~ /^Content-Type:.+charset="(.+)".*$/ &&
3479 $1 !~ /utf-8/i) {
3486 "8-bit UTF-8 used in possible commit log\n" . $herecurr);
3491 while ($line =~ m{(?:^|\s)(/\S*)}g) {
3507 while ($rawline_utf8 =~ /(?:^|[^\w\-'`])($misspellings)(?:[^\w\-'`]|$)/gi) {
3510 my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);
3513 $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
3514 $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
3518 "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $hereptr) &&
3520 $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
3526 if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) {
3537 # avoid false positive from list command eg, '-rw-r--r-- 1 root root'
3539 $rawline !~ /[bcCdDlMnpPs\?-][rwxsStT-]{9}/) {
3545 my $start_pos = $-[1];
3558 $start_char = substr($rawline, $start_pos - 1, 1) if ($start_pos > ($in_commit_log ? 0 : 1));
3561 next if ($start_char =~ /^\S$/);
3562 next if (index(" \t.,;?!", $end_char) == -1);
3565 if ($first =~ /\b[0-9a-f]{2,}\b/i) {
3572 $fixed[$fixlinenr] =~ s/\b$first $second\b/$first/;
3576 # if it's a repeated word on consecutive lines in a comment block
3577 if ($prevline =~ /$;+\s*$/ &&
3578 $prevrawline =~ /($word_pattern)\s*$/) {
3580 if ($rawline =~ /^\+\s*\*\s*$last_word /) {
3584 $fixed[$fixlinenr] =~ s/(\+\s*\*\s*)$last_word /$1/;
3590 # ignore non-hunk lines and lines being removed
3591 next if (!$hunk_line || $line =~ /^-/);
3599 $fixed[$fixlinenr] =~ s/[\s\015]+$//;
3601 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
3606 $fixed[$fixlinenr] =~ s/\s+$//;
3614 $rawline =~ /\b675\s+Mass\s+Ave/i ||
3615 $rawline =~ /\b59\s+Temple\s+Pl/i ||
3616 $rawline =~ /\b51\s+Franklin\s+St/i) {
3621 …"Do not include the paragraph about writing to the Free Software Foundation's mailing address from…
3630 # (\b) rather than a whitespace character (\s)
3631 $line =~ /^\+\s*(?:config|menuconfig|choice)\b/) {
3639 next if ($f =~ /^-/);
3642 if ($f =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
3646 if ($f =~ /^\+\s*help\s*$/) {
3651 $f =~ s/^.//; # strip patch context [+ ]
3652 $f =~ s/#.*//; # strip # directives
3653 $f =~ s/^\s+//; # strip leading blanks
3669 my $stat_real = get_stat_real($linenr, $ln - 1);
3678 if ($rawline =~ /^\+[A-Z]:/ &&
3679 $rawline !~ /^\+[A-Z]:\t\S/) {
3683 $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/;
3688 if ($rawline =~ /^\+[A-Z]:/ &&
3689 $prevrawline =~ /^[\+ ][A-Z]:/) {
3690 $rawline =~ /^\+([A-Z]):\s*(.*)/;
3693 $prevrawline =~ /^[\+ ]([A-Z]):\s*(.*)/;
3704 "Misordered MAINTAINERS entry - list '$cur:' before '$prev:'\n" . $hereprev);
3709 "Misordered MAINTAINERS entry - list file patterns in alphabetic order\n" . $hereprev);
3717 (($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) ||
3718 ($realfile =~ /\.[ch]$/ && $line =~ /^\+.*\.compatible\s*=\s*\"/))) {
3720 my @compats = $rawline =~ /\"([a-zA-Z0-9\-\,\.\+_]+)\"/g;
3723 my $vp_file = $dt_path . "vendor-prefixes.yaml";
3727 $compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
3729 $compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/;
3730 `grep -Erq "$compat|$compat2|$compat3" $dt_path`;
3733 "DT compatible string \"$compat\" appears un-documented -- check $dt_path\n" . $herecurr);
3736 next if $compat !~ /^([a-zA-Z0-9\-]+)\,/;
3738 `grep -Eq "\\"\\^\Q$vendor\E,\\.\\*\\":" $vp_file`;
3741 … "DT compatible string vendor \"$vendor\" appears un-documented -- check $vp_file\n" . $herecurr);
3746 # Check for RGMII phy-mode with delay on PCB
3748 $line =~ /^\+\s*(phy-mode|phy-connection-type)\s*=\s*"/ &&
3752 if ($mode =~ /^"rgmii(?:|-rxid|-txid)"$/) {
3754 …"$prop $mode without comment -- delays on the PCB should be described, otherwise use \"rgmii-id\"\…
3760 if ($rawline =~ /^[ \+]\s*\#\!\s*\//) {
3764 if ($realfile =~ /\.(h|s|S)$/) {
3776 $rawline =~ /SPDX-License-Identifier:/ &&
3777 $rawline !~ m@^\+\s*\Q$comment\E\s*@) {
3783 $rawline !~ m@^\+\Q$comment\E SPDX-License-Identifier: @) {
3785 … "Missing or malformed SPDX-License-Identifier tag in line $checklicenseline\n" . $herecurr);
3786 } elsif ($rawline =~ /(SPDX-License-Identifier: .*)/) {
3793 $spdx_license !~ /GPL-2\.0(?:-only)? OR BSD-2-Clause/) {
3798 "DT binding documents should be licensed (GPL-2.0-only OR BSD-2-Clause)\n" . $herecurr) &&
3800 …$fixed[$fixlinenr] =~ s/SPDX-License-Identifier: .*/SPDX-License-Identifier: (GPL-2.0-only OR BSD-
3803 if ($realfile =~ m@^include/dt-bindings/@ &&
3804 $spdx_license !~ /GPL-2\.0(?:-only)? OR \S+/) {
3806 "DT binding headers should be licensed (GPL-2.0-only OR .*)\n" . $herecurr);
3815 "It's generally not useful to have the filename in the file\n" . $herecurr);
3819 next if ($realfile !~ /\.(h|c|rs|s|S|sh|dtsi|dts)$/);
3821 # check for using SPDX-License-Identifier on the wrong line number
3823 $rawline =~ /\bSPDX-License-Identifier:/ &&
3824 substr($line, @-, @+ - @-) eq "$;" x (@+ - @-)) {
3826 "Misplaced SPDX-License-Identifier tag - use line $checklicenseline instead\n" . $herecurr);
3852 …if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ …
3853 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3858 } elsif ($line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ ||
3859 $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) {
3863 } elsif ($line =~ /^\+.*\bEFI_GUID\s*\(/ ||
3864 $line =~ /^\+\s*(?:\w+)?\s*DEFINE_PER_CPU/) {
3868 } elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) {
3874 } elsif ($line =~ /($;[\s$;]*)$/ &&
3875 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3879 } elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ &&
3880 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3902 # check for .L prefix local symbols in .S files
3903 if ($realfile =~ /\.S$/ &&
3904 $line =~ /^\+\s*(?:[A-Z]+_)?SYM_[A-Z]+_(?:START|END)(?:_[A-Z_]+)?\s*\(\s*\.L/) {
3906 … range of code via 'SYM_*_START/END' annotations; see Documentation/core-api/asm-annotations.rst\n…
3914 if ($rawline =~ /^\+\s* \t\s*\S/ ||
3915 $rawline =~ /^\+\s* \s*/) {
3921 $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
3932 s/(^\+.*) {$tabsize,$tabsize}\t/$1\t\t/) {}
3934 s/(^\+.*) +\t/$1\t/) {}
3939 if ($sline =~ /^\+\s+($Assignment)[^=]/) {
3945 $fixed[$fixlinenr - 1] .= " $operator";
3946 $fixed[$fixlinenr] =~ s/\Q$operator\E\s*//;
3951 if ($rawline =~ /^\+\s*(&&|\|\|)/) {
3956 # insert logical operator at last non-comment, non-whitepsace char on previous line
3957 $prevline =~ /[\s$;]*$/;
3958 my $line_end = substr($prevrawline, $-[0]);
3959 $fixed[$fixlinenr - 1] =~ s/\Q$line_end\E$/ $operator$line_end/;
3960 $fixed[$fixlinenr] =~ s/\Q$operator\E\s*//;
3966 …$sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;…
3972 $fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/$tabsize)@e;
3977 # check multi-line statement indentation matches previous line
3979 …(?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|(?:\*\s*)*$Lval\
4001 s/^\+[ \t]*/\+$goodtabindent/;
4014 if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ &&
4015 (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) {
4020 s/(\(\s*$Type\s*\))[ \t]+/$1/;
4069 if ($prevline =~ /^[\+ ]};?\s*$/ &&
4071 !($line =~ /^\+\s*$/ ||
4072 $line =~ /^\+\s*(?:EXPORT_SYMBOL|early_param|ALLOW_ERROR_INJECTION)/ ||
4073 $line =~ /^\+\s*MODULE_/i ||
4074 $line =~ /^\+\s*\#\s*(?:end|elif|else)/ ||
4075 $line =~ /^\+[a-z_]*init/ ||
4076 $line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ ||
4077 $line =~ /^\+\s*DECLARE/ ||
4078 $line =~ /^\+\s*builtin_[\w_]*driver/ ||
4079 $line =~ /^\+\s*__setup/)) {
4088 if ($prevline =~ /^[\+ ]\s*$/ &&
4089 $line =~ /^\+\s*$/ &&
4090 $last_blank_line != ($linenr - 1)) {
4102 if (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/) {
4107 $sl =~ s/\b(?:$Attribute|$Sparse)\b//g;
4108 $pl =~ s/\b(?:$Attribute|$Sparse)\b//g;
4109 if (($pl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
4111 $pl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
4113 $pl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
4115 $pl =~ /^\+\s+$declaration_macros/) &&
4117 !($pl =~ /^\+\s+$c90_Keywords\b/ ||
4119 $pl =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
4121 $pl =~ /(?:\{\s*|\\)$/) &&
4123 !($sl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
4125 $sl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident\s*\)\s*[=,;:\[\(]/ ||
4127 $sl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
4129 $sl =~ /^\+\s+$declaration_macros/ ||
4131 $sl =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ ||
4133 $sl =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
4135 $sl =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
4137 $sl =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/)) {
4156 $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
4164 if ($line =~ /^\+.*([\[\(])\s*$/) {
4170 if ($sline =~ /^\+\{\s*$/ &&
4171 $prevline =~ /^\+(?:(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*)?($Ident)\(/) {
4176 if ($sline =~ /^\+\}\s*$/) {
4183 if ($sline =~ /^\+([\t]+)(?:}[ \t]*)?else(?:[ \t]*{)?\s*$/) {
4197 if ($sline =~ /^\+([\t]+)break\s*;\s*$/) {
4225 $realcnt && $sline =~ /.\s*\S/) {
4228 $stat =~ s/\n./\n /g;
4229 $cond =~ s/\n./\n /g;
4235 my $frag = $stat; $frag =~ s/;+\s*$//;
4244 (!defined $lines[$realline_next - 1] ||
4245 substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
4249 my $s = $stat;
4250 $s =~ s/{.*$//s;
4253 if ($s =~ /$Ident:\*$/s) {
4256 } elsif ($s =~ /^.\s*$Ident\s*\(/s) {
4258 } elsif ($s =~ /^.\s*else\b/s) {
4261s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+?)\b(?:\s+$Sparse)?\s*\**\s*…
4263 $type =~ s/\s+/ /g;
4264 possible($type, "A:" . $s);
4267 } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {
4268 possible($1, "B:" . $s);
4272 while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
4273 possible($1, "C:" . $s);
4279 …f ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Id…
4282 my $ctx = $s;
4284 $ctx =~ s/\)[^\)]*$//;
4286 for my $arg (split(/\s*,\s*/, $ctx)) {
4287 …if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$…
4289 possible($1, "D:" . $s);
4302 if ($line=~/\bswitch\s*\(.*\)/) {
4309 if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
4325 …($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $line …
4332 "Too many leading tabs - consider code refactoring\n" . $herecurr);
4335 my $ctx_cnt = $realcnt - $#ctx - 1;
4342 defined $lines[$ctx_ln - 1] &&
4343 $lines[$ctx_ln - 1] =~ /^-/)) {
4345 $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
4350 #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
4352 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
4355 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
4357 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
4358 $ctx =~ /\)\s*\;\s*$/ &&
4359 defined $lines[$ctx_ln - 1])
4361 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
4365 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
4371 … =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /^.\s*#/ &…
4375 my ($s, $c) = ($stat, $cond);
4377 substr($s, 0, length($c), '');
4380 $s =~ s/$;/ /g;
4381 $c =~ s/$;/ /g;
4390 $s =~ s/\n./\n/gs;
4391 while ($s =~ /\n\s+\\\n/) {
4392 $cond_lines += $s =~ s/\n\s+\\\n/\n/g;
4402 $s =~ s/^.*\bdo\b//;
4403 $s =~ s/^\s*{//;
4404 if ($s =~ s/^\s*\\//) {
4407 if ($s =~ s/^\s*?\n//) {
4414 if (($prevline =~ /^.\s*#\s*define\s/ ||
4415 $prevline =~ /\\\s*$/) && $continuation == 0) {
4419 my $cond_ptr = -1;
4426 if ($s =~ /^\s*\#\s*(?:else|elif)/) {
4435 $s =~ /^\s*?\n/ ||
4436 $s =~ /^\s*#\s*?/ ||
4437 $s =~ /^\s*$Ident\s*:/) {
4438 $continuation = ($s =~ /^.*?\\\n/) ? 1 : 0;
4439 if ($s =~ s/^.*?\n//) {
4445 my (undef, $sindent) = line_stats("+" . $s);
4449 # this is not this patch's fault.
4458 …dent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_l…
4460 if ($check && $s ne '' &&
4464 ($s !~ /^\s*(?:\}|\{|else\b)/)) ||
4472 my $opline = $line; $opline =~ s/^./ /;
4477 my $outline = $opline; $outline =~ s/\t/ /g;
4482 $prev_values = substr($curr_values, -1);
4490 if ($line =~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=/) {
4492 …if ($line =~ /^\+\s*(?:$Declare)?$var\s*=\s*(?:$var|\*\s*\(?\s*&\s*\(?\s*$var\s*\)?\s*\)?)\s*[;,]/…
4494 "Do not use self-assignments to avoid compiler warnings\n" . $herecurr);
4499 if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
4500 $line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) {
4501 $prevline =~ /($Lval\s*(?:\.|->))\s*$/;
4503 $line =~ /^.\s*($Lval)/;
4505 $ref =~ s/\s//g;
4507 "Avoid multiple line dereference - prefer '$ref'\n" . $hereprev);
4511 while ($line =~ m{\b($Declare)\s*(?!char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) {
4515 if ($type =~ /^(?:(?:$Storage|$Inline|$Attribute)\s+)*((?:un)?signed)((?:\s*\*)*)\s*$/) {
4526 $comp_pointer =~ s/\s//g;
4529 $fixed[$fixlinenr] =~ s@\b$sign\s*\Q$pointer\E\s*$var\b@$decl$var@;
4536 if ($line =~ /^.\s*$Declare\s*$/) {
4547 if ($line =~ /^.\s*$Modifier\s*$/) {
4558 if ($line =~ /^.\s*{/ &&
4559 $prevline =~ /(?:^|[^=])=\s*$/) {
4563 fix_delete_line($fixlinenr - 1, $prevrawline);
4566 $fixedline =~ s/\s*=\s*$/ = {/;
4569 $fixedline =~ s/^(.\s*)\{\s*/$1/;
4579 if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
4599 $fixed[$fixlinenr] =~ s@\/\/(.*)$@/\* $comment \*/@;
4604 $line =~ s@//.*@@;
4605 $opline =~ s@//.*@@;
4609 #print "APW <$lines[$realline_next - 1]>\n";
4611 exists $lines[$realline_next - 1] &&
4613 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/)) {
4619 $name =~ s/^\s*($Ident).*/$1/;
4620 if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
4626 \n.}\s*$|
4630 ^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(|
4631 \b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\()
4633 #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
4640 $prevline =~ /^.\s*$/ &&
4642 #print "FOO B <$lines[$linenr - 1]>\n";
4652 if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/ &&
4657 $fixed[$fixlinenr] =~ s/(^.$Type\s*$Ident(?:\s+$Modifier)*)\s*=\s*$zero_initializer\s*;/$1;/;
4661 if ($line =~ /^\+.*\bstatic\s.*=\s*($zero_initializer)\s*;/) {
4666 $fixed[$fixlinenr] =~ s/(\bstatic\s.*?)\s*=\s*$zero_initializer\s*;/$1;/;
4678 while ($sline =~ m{\b($TypeMisordered(\s*\*)*|$C90_int_types)\b}g) {
4681 next if ($type !~ /\b(?:short|long\s+long|long)\b/);
4683 $new_type =~ s/\b\s*int\s*\b/ /;
4684 $new_type =~ s/\b\s*(?:un)?signed\b\s*/ /;
4685 $new_type =~ s/^const\s+//;
4688 $new_type =~ s/\s+/ /g;
4693 $fixed[$fixlinenr] =~ s/\b\Q$type\E\b/$new_type/;
4698 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
4705 …if ($line =~ /^\+\s*const\s+(char|unsigned\s+char|_*u8|(?:[us]_)?int8_t)\s+\w+\s*\[\s*(?:\w+\s*)?\…
4709 $fixed[$fixlinenr] =~ s/(^.\s*)const\b/${1}static const/;
4714 if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
4721 if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) {
4723 if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) {
4726 } elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) {
4734 if ($sline =~ /^\+\s*const\s+static\s+($Type)\b/ ||
4735 $sline =~ /^\+\s*static\s+($BasicType)\s+const\b/) {
4737 "Move const after static - use 'static const $1'\n" . $herecurr) &&
4739 $fixed[$fixlinenr] =~ s/\bconst\s+static\b/static const/;
4740 $fixed[$fixlinenr] =~ s/\bstatic\s+($BasicType)\s+const\b/static const $1/;
4744 # check for non-global char *foo[] = {"bar", ...} declarations.
4745 if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
4752 if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) {
4754 …if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))…
4759 $fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/;
4765 if ($line =~ /(\b$Type\s*$Ident)\s*\(\s*\)/) {
4767 "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
4769 $fixed[$fixlinenr] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/;
4775 if ($line =~ /\btypedef\s/ &&
4776 $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
4777 $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
4786 while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
4791 $to =~ s/^(\S)/ $1/;
4793 $to =~ s/\s+$//;
4794 # '*'s should not have spaces between.
4795 while ($to =~ s/\*\s+\*/\*\*/) {
4805 $sub_to =~ s/\Q$from\E/$to/;
4807 s@\Q$sub_from\E@$sub_to@;
4811 while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) {
4816 $to =~ s/^(\S)/ $1/;
4818 $to =~ s/\s+$//;
4819 # '*'s should not have spaces between.
4820 while ($to =~ s/\*\s+\*/\*\*/) {
4823 $to =~ s/(\b$Modifier$)/$1 /;
4833 $sub_to =~ s/\Q$from\E/$to/;
4835 s@\Q$sub_from\E@$sub_to@;
4841 …ine =~ /\b(?!AA_|BUILD_|IDA_|KVM_|RWLOCK_|snd_|SPIN_)(?:[a-zA-Z_]*_)?BUG(?:_ON)?(?:_[A-Z_]+)?\s*\(…
4845 …"Do not crash the kernel unless it is absolutely unavoidable--use WARN_ON_ONCE() plus recovery cod…
4855 if ($line =~ /\bprintk_ratelimit\s*\(/) {
4861 if ($line =~ /\bprintk\s*\(\s*(?!KERN_[A-Z]+\b)/) {
4867 if ($line =~ /\b(printk(_once|_ratelimited)?)\s*\(\s*KERN_([A-Z]+)/) {
4883 if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
4893 if ($line =~ /\b(trace_printk|trace_puts|ftrace_vprintk)\s*\(/) {
4913 $fixed[$fixlinenr] =~ s/\bENOTSUPP\b/EOPNOTSUPP/;
4920 $sline =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ &&
4921 $sline !~ /\#\s*define\b.*do\s*\{/ &&
4928 $fixed_line =~ /(^..*$Type\s*$Ident\(.*\)\s*)\{(.*)$/;
4933 if ($line2 !~ /^\s*$/) {
4940 if ($line =~ /^.\s*{/ &&
4941 $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
4945 fix_delete_line($fixlinenr - 1, $prevrawline);
4950 $fixedline =~ s/^(.\s*)\{\s*/$1\t/;
4951 if ($fixedline !~ /^\+\s*$/) {
4958 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident){1,2}[=\{]/) {
4963 s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/;
4970 if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)($Ident)(\s*)\)(\s*)\(/) {
4982 if ($declare =~ /(\s+)$/) {
4998 # elsif ($declare =~ /\s{2,}$/) {
5005 $pre_pointer_space =~ /^\s/) {
5012 $post_pointer_space =~ /^\s/) {
5019 $post_funcname_space =~ /^\s/) {
5026 $pre_args_space =~ /^\s/) {
5033s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcn…
5038 # 1. with a type on the left -- int [] a;
5039 # 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
5040 # 3. inside a curly brace -- = { [0...10] = 5 }
5041 while ($line =~ /(.*?\s)\[/g) {
5042 my ($where, $prefix) = ($-[1], $1);
5043 if ($prefix !~ /$Type\s+$/ &&
5044 ($where != 0 || $prefix !~ /^.\s+$/) &&
5045 $prefix !~ /[{,:]\s+$/) {
5050 s/^(\+.*?)\s+\[/$1\[/;
5056 while ($line =~ /($Ident)\s+\(/g) {
5058 my $ctx_before = substr($line, 0, $-[1]);
5068 # cpp #define statements have non-optional spaces, ie
5071 } elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) {
5074 } elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) {
5085 s/\b$name\s+\(/$name\(/;
5091 if (!($line=~/\#\s*include/)) {
5097 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
5098 =>|->|<<|>>|<|>|=|!|~|
5099 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
5120 my $last_after = -1;
5140 $a = 'W' if ($elements[$n] =~ /\s$/);
5144 $a = 'E' if ($ca =~ /^\s*$/);
5151 $c = 'W' if ($elements[$n + 2] =~ /^\s/);
5155 $c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/);
5175 $ca =~ /\s$/ && $cc =~ /^\s*[,\)]/) {
5199 # ->
5200 } elsif ($op eq '->') {
5206 $fix_elements[$n + 2] =~ s/^\s+//;
5242 # '*' as part of a type definition -- reported already.
5250 $opv eq '*U' || $opv eq '-U' ||
5252 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
5261 if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
5269 $fix_elements[$n + 2] =~ s/^\s+//;
5275 # unary ++ and unary -- are allowed no space on one side.
5276 } elsif ($op eq '++' or $op eq '--') {
5297 $fix_elements[$n + 2] =~ s/^\s+//;
5306 $op eq '+' or $op eq '-' or
5315 $fix_elements[$n + 2] =~ s/^\s+//;
5330 $fix_elements[$n + 2] =~ s/^\s+//;
5353 $cc =~ /^\S+\@\S+>/) ||
5355 $ca =~ /<\S+\@\S+$/))
5377 $fix_elements[$n + 2] =~ s/^\s+//;
5401 # check for whitespace before a non-naked semicolon
5402 if ($line =~ /^\+.*\S\s+;\s*$/) {
5407 s/^(\+.*\S)\s+;/$1;/;
5412 if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
5419 ## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
5420 ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
5425 ## while ($ln =~ s/\([^\(\)]*\)//g) {
5439 $fixed[$fixlinenr] =~ s/^(\+.*(?:do|else|\)))\{/$1 {/;
5444 ## if ($line =~ /^.\t+$Type\s+$Ident(?:\s*=.*)?;/ &&
5445 ## $prevrawline =~ /^.\s*$/) {
5453 if ($line =~ /}(?!(?:,|;|\)|\}))\S/) {
5458 s/}((?!(?:,|;|\)))\S)/} $1/;
5463 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
5468 s/\[\s+/\[/;
5471 if ($line =~ /\s\]/) {
5476 s/\s+\]/\]/;
5481 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
5482 $line !~ /for\s*\(\s+;/) {
5487 s/\(\s+/\(/;
5490 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
5491 $line !~ /for\s*\(.*;\s+\)/ &&
5492 $line !~ /:\s+\)/) {
5497 s/\s+\)/\)/;
5502 # ie: &(foo->bar) should be &foo->bar and *(foo->bar) should be *foo->bar
5504 while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) {
5509 $fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/;
5514 # ie: (foo->bar)(); should be foo->bar();
5515 # but not "if (foo->bar) (" to avoid some false positives
5516 if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) {
5522 $var2 =~ s/\s//g;
5523 $fixed[$fixlinenr] =~ s/\Q$var\E/$var2/;
5531 $stat =~ /(^.\s*if\s*($balanced_parens))/) {
5533 my $test = substr($2, 1, -1);
5535 …while ($test =~ /(?:^|[^\w\&\!\~])+\s*\(\s*([\&\!\~]?\s*$Lval\s*(?:$Compare\s*$FuncArg)?)\s*\)/g) {
5538 next if ($match =~ /^\s*\w+\s*$/);
5557 if ($sline =~ /^.\s+[A-Za-z_][A-Za-z\d_]*:(?!\s*\d+)/ &&
5558 $sline !~ /^. [A-Za-z\d_][A-Za-z\d_]*:/ &&
5559 $sline !~ /^.\s+default:/) {
5564 s/^(.)\s+/$1/;
5572 …$stat =~ /^\+\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*,\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*;\
5580 if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
5583 $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) {
5586 if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) {
5590 } elsif ($spacing !~ /\s+/) {
5597 # at end-of-function, with the previous line a single leading tab, then return;
5599 if ($sline =~ /^[ \+]}\s*$/ &&
5600 $prevline =~ /^\+\treturn\s*;\s*$/ &&
5602 $lines[$linenr - 3] =~ /^[ +]/ &&
5603 $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
5608 # if statements using unnecessary parentheses - ie: if ((foo == bar))
5610 $line =~ /\bif\s*((?:\(\s*){2,})/) {
5614 …if ($line =~ /\bif\s*(?:\(\s*){$count,$count}$LvalOrFunc\s*($Compare)\s*$LvalOrFunc(?:\s*\)){$coun…
5616 $msg = " - maybe == should be = ?" if ($comp eq "==");
5627 $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
5633 if ($lead !~ /(?:$Operators|\.)\s*$/ &&
5634 $to !~ /^(?:Constant|[A-Z_][A-Z0-9_]*)$/ &&
5647 $fixed[$fixlinenr] =~ s/\(\s*\Q$const\E\s*$Compare\s*\Q$to\E\s*\)/($to $newcomp $const)/;
5652 if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
5656 "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
5666 s/\b(if|while|for|switch)\(/$1 \(/;
5670 # Check for illegal assignment in if conditional -- and check for trailing
5672 if ($line =~ /do\s*(?!{)/) {
5678 $stat_next =~ s/\n./\n /g;
5681 if ($stat_next =~ /^\s*while\b/) {
5685 ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
5687 statement_rawlines($whitespace) - 1;
5695 $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
5696 my ($s, $c) = ($stat, $cond);
5699 if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
5703 …if ($rawline =~ /^\+(\s+)if\s*\(\s*(\!)?\s*\(\s*(($Lval)\s*=\s*$LvalOrFunc)\s*\)\s*(?:($Compare)\s
5729 substr($s, 0, length($c), '');
5730 $s =~ s/\n.*//g;
5731 $s =~ s/$;//g; # Remove any comments
5732 if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
5733 $c !~ /}\s*while\s*/)
5751 $fixed[$fixlinenr] =~ /^\+(\s*)((?:if|while|for)\s*$balanced_parens)\s*(.*)$/) {
5767 \s*0[xX][0-9]+\s*
5771 \s*0[xX][0-9]+\s*
5780 if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
5781 my $s = $1;
5782 $s =~ s/$;//g; # Remove any comments
5783 if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
5789 if ($line =~ /}\s*if\b/) {
5795 if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
5797 (?:\s*$;*)(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
5798 \s*return\s+
5807 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ &&
5812 fix_delete_line($fixlinenr - 1, $prevrawline);
5815 $fixedline =~ s/}\s*$//;
5816 if ($fixedline !~ /^\+\s*$/) {
5820 $fixedline =~ s/^(.\s*)else/$1} else/;
5825 if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ &&
5827 my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
5831 substr($s, 0, length($c), '');
5832 $s =~ s/\n.*//g;
5834 if ($s =~ /^\s*;/) {
5838 fix_delete_line($fixlinenr - 1, $prevrawline);
5842 $trailing =~ s/^\+//;
5844 $fixedline =~ s/}\s*$/} $trailing/;
5856 $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
5860 $var !~ /^(?:[A-Z]+_){1,5}[A-Z]{1,3}[a-z]/ &&
5862 $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
5867 $var !~ /^(?:[a-z0-9_]*|[A-Z0-9_]*)?_?[a-z][A-Z](?:_[a-z0-9_]+|_[A-Z0-9_]+)?$/ &&
5869 $var !~ /^(?:[a-z_]*?)_?(?:[KMGT]iB|[KMGT]?Hz)(?:_[a-z_]+)?$/) {
5872 next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
5890 if ($line =~ /\#\s*define.*\\\s+$/) {
5894 $fixed[$fixlinenr] =~ s/\s+$//;
5900 if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
5903 if (-f "$root/$checkfile" &&
5907 my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
5920 # Usually multi-statement macros should be enclosed in a do {} while
5924 $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) {
5935 #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
5938 $has_arg_concat = 1 if ($ctx =~ /\#\#/ && $ctx !~ /\#\#\s*(?:__VA_ARGS__|args)\b/);
5940 $dstat =~ s/^.\s*\#\s*define\s+$Ident(\([^\)]*\))?\s*//;
5946 $define_args = substr($define_args, 1, length($define_args) - 2);
5947 $define_args =~ s/\s*//g;
5948 $define_args =~ s/\\\+?//g;
5952 $dstat =~ s/$;//g;
5953 $dstat =~ s/\\\n.//g;
5954 $dstat =~ s/^\s*//s;
5955 $dstat =~ s/\s*$//s;
5958 while ($dstat =~ s/\([^\(\)]*\)/1u/ ||
5959 $dstat =~ s/\{[^\{\}]*\}/1u/ ||
5960 $dstat =~ s/.\[[^\[\]]*\]/1u/)
5965 while ($dstat =~ s/($String)\s*$Ident/$1/ ||
5966 $dstat =~ s/$Ident\s*($String)/$1/)
5971 $dstat =~ s/\b_*asm_*\s+_*volatile_*\b/asm_volatile/g;
5985 \.$Ident\s*=\s*|
5991 $ctx =~ s/\n*$//;
5996 $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
5997 $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
5998 …$dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // f…
6001 $dstat !~ /^\.$Ident\s*=/ && # .foo =
6002 $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ && # stringification #foo
6004 …$dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (.…
6005 $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ && # while (...) {...}
6006 $dstat !~ /^for\s*$Constant$/ && # for (...)
6007 $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
6008 $dstat !~ /^do\s*{/ && # do {...
6010 $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/)
6012 if ($dstat =~ /^\s*if\b/) {
6014 …"Macros starting with if should be enclosed by a do - while loop to avoid possible if/else logic d…
6017 …"Non-declarative macros with multiple statements should be enclosed in a do - while loop\n" . "$he…
6025 # Make $define_stmt single line, comment-free, etc
6030 $l =~ s/\\$//;
6038 $define_stmt =~ s/$;//g;
6039 $define_stmt =~ s/\s+/ /g;
6047 …tmt =~ s/\b(__must_be_array|offsetof|sizeof|sizeof_field|__stringify|typeof|__typeof__|__builtin\w…
6048 $tmp_stmt =~ s/\#+\s*$arg\b//g;
6049 $tmp_stmt =~ s/\b$arg\s*\#\#//g;
6053 "Macro argument reuse '$arg' - possible side-effects?\n" . "$herectx");
6056 if ($tmp_stmt =~ m/($Operators)?\s*\b$arg\b\s*($Operators)?/m &&
6066 "Argument '$arg' is not used in function-like macro\n" . "$herectx");
6083 $line =~ s/(\w+)/$maybe_linker_symbol{$1}++/ge;
6087 $line !~ /^\+\s*\#.*\\$/ && # preprocessor
6096 # single-statement macros do not need to be enclosed in do while (0) loop,
6100 $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) {
6109 $dstat =~ s/\\\n.//g;
6110 $dstat =~ s/$;/ /g;
6112 …if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*…
6116 $ctx =~ s/\n*$//;
6121 $stmts !~ /^\s*(if|while|for|switch)\b/) {
6129 } elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) {
6130 $ctx =~ s/\n*$//;
6140 if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
6150 my $ln = $linenr - 1;
6155 my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
6156 my $offset = statement_rawlines($whitespace) - 1;
6165 $ln += statement_rawlines($block) - 1;
6169 $seen++ if ($block =~ /^\s*{/);
6202 if (!defined $suppress_ifbraces{$linenr - 1} &&
6206 # Check the pre-context.
6207 if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
6213 ctx_statement_full($linenr, $realcnt, $-[0]);
6233 # Check the post-context.
6239 if ($block =~ /^\s*\{/) {
6240 #print "APW: ALLOWED: chunk-1 block<$block>\n";
6244 if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
6254 if ($sline =~ /^.\s*\}\s*else\s*$/ ||
6255 $sline =~ /^.\s*else\s*\{\s*$/) {
6260 if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
6264 fix_delete_line($fixlinenr - 1, $prevrawline);
6267 if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
6276 my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
6279 …"Use of volatile is usually wrong: see Documentation/process/volatile-considered-harmful.rst\n" . …
6282 # Check for user-visible strings broken across lines, which breaks the ability
6286 if ($line =~ /^\+\s*$String/ &&
6287 $prevline =~ /"\s*$/ &&
6288 $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) {
6292 $prevrawline =~ /^\+.*"\s*$/ &&
6293 $last_coalesced_string_linenr != $linenr - 1) {
6296 if ($rawline =~ /\Q$extracted_string\E(\s*\)\s*;\s*$|\s*,\s*)/) {
6300 fix_delete_line($fixlinenr - 1, $prevrawline);
6303 $fixedline =~ s/"\s*$//;
6305 fix_insert_line($fixlinenr - 1, $fixedline);
6307 $fixedline =~ s/\Q$extracted_string\E\Q$comma_close\E//;
6308 if ($fixedline !~ /\+\s*$/) {
6322 # This does not work very well for -f --file checking as it depends on patch
6323 # context providing the function name or a single line form for in-file
6330 …"Prefer using '\"%s...\", __func__' to using '$context_function', this function's name, in a strin…
6335 # 'dprintk(FOO, "%s()\n", __func__);' which do not match $logFunctions
6336 …+.*\([^"]*"$tracing_logging_tags{0,3}%s(?:\s*\(\s*\)\s*)?$tracing_logging_tags{0,3}(?:\\n)?"\s*,\s
6338 "Unnecessary ftrace-like logging - prefer using ftrace\n" . $herecurr) &&
6345 if ($rawline =~ /^.*\".*\s\\n/) {
6349 $fixed[$fixlinenr] =~ s/^(\+.*\".*)\s+\\n/$1\\n/;
6355 if ($line =~ /$String[A-Z_]/ ||
6356 ($line =~ /([A-Za-z0-9_]+)$String/ && $1 !~ /^[Lu]$/)) {
6361 my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
6362 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/;
6363 $fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/;
6369 if ($line =~ /$String\s*[Lu]?"/) {
6373 while ($line =~ /($String)(?=\s*")/g) {
6374 my $extracted_string = substr($rawline, $-[0], $+[0] - $-[0]);
6375 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e;
6380 # check for non-standard and hex prefixed decimal printf formats
6384 my $string = substr($rawline, $-[1], $+[1] - $-[1]);
6385 $string =~ s/%%/__/g;
6389 "\%L$1 is non-standard C, use %ll$1\n" . $herecurr);
6395 "%Z$1 is non-standard C, use %z$1\n" . $herecurr);
6412 if ($line =~ /^.\s*\#\s*if\s+0\b/) {
6418 if ($line =~ /^.\s*\#\s*if\s+1\b/) {
6424 if ($prevline =~ /\bif\s*\(\s*($Lval)\s*\)/) {
6426 my $expr = '\s*\(\s*' . $tested . '\s*\)\s*;';
6435 if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
6440 if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
6449 fix_delete_line($fixlinenr - 1, $prevrawline);
6450 $fixed[$fixlinenr] =~ s/^\+$new_leading_tabs/\+$leading_tabs/;
6457 if ($line =~ /^\+.*\b$logFunctions\s*\(/ &&
6458 $prevline =~ /^[ \+]\s*if\s*\(\s*(\!\s*|NULL\s*==\s*)?($Lval)(\s*==\s*NULL\s*)?\s*\)/ &&
6462 my $testline = $lines[$linenr - 3];
6464 my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0);
6465 # print("line: <$line>\nprevline: <$prevline>\ns: <$s>\nc: <$c>\n\n\n");
6467 …if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*$allocFunctions\s*…
6468 $s !~ /\b__GFP_NOWARN\b/ ) {
6475 if ($line !~ /printk(?:_ratelimited|_once)?\s*\(/ &&
6476 $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
6481 $fixed[$fixlinenr] =~ s/\s*$level\s*//;
6486 if ($line =~ /\bprintk\s*\(\s*KERN_CONT\b|\bpr_cont\s*\(/) {
6493 $line =~ /\b$logFunctions\s*\(/ &&
6499 while ($stat_real =~ /[^\"%]*(%[\#\d\.\*\-]*(h+)[idux])/g) {
6502 my $lineoff = substr($stat_real, 0, $-[1]) =~ tr@\n@@;
6507 $nspec =~ s/h//g;
6508 $fixed[$fixlinenr + $lineoff] =~ s/\Q$pspec\E/$nspec/;
6515 $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ &&
6518 … "Possible precedence defect with mask then right shift - may need parentheses\n" . $herecurr);
6523 while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) {
6530 $fixed[$fixlinenr] =~ s/\b\Q$val\E\s*(?:==|\!=)\s*NULL\b/$equal$val/;
6538 …if ($line =~ /^\+\s*static\s+(?:const\s+)?(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Iden…
6541 if ((($ptr =~ /\b(union|struct)\s+$attr\b/ &&
6544 ($ptr !~ /\b(union|struct)\s+$attr\b/ &&
6548s/(\bstatic\s+(?:const\s+)?)(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])…
6563 s/$InitAttributeData/${attr_prefix}initconst/;
6574 /(^\+\s*(?:static\s+))/;
6578 $fixed[$fixlinenr] =~ s/(^\+\s*(?:static\s+))/$lead/;
6582 # check for __read_mostly with const non-pointer (should just be const)
6584 $line =~ /($Type)\s*$Ident/ && $1 !~ /\*\s*$/ && $1 =~ /\bconst\b/) {
6588 $fixed[$fixlinenr] =~ s/\s+__read_mostly\b//;
6594 … $line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) {
6597 $func =~ s/^__constant_//;
6601 $fixed[$fixlinenr] =~ s/\b$constant_func\b/$func/g;
6606 if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
6608 # ignore udelay's < 10, however
6615 "long udelay - prefer mdelay; see function description of mdelay().\n" . $herecurr);
6619 # warn about unexpectedly long msleep's
6620 if ($line =~ /\bmsleep\s*\((\d+)\);/) {
6628 if ($line =~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) {
6634 if ($line =~ /\bget_jiffies_64\s*\(\s*\)\s*$Compare|$Compare\s*get_jiffies_64\s*\(\s*\)/) {
6640 # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
6647 if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
6652 s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /;
6658 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ ||
6659 $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
6687 if ($line =~ /\b(?:$all_barriers)\s*\(/) {
6696 if ($realfile !~ m@^include/asm-generic/@ &&
6698 $line =~ m/\b(?:$underscore_smp_barriers)\s*\(/ &&
6699 $line !~ m/^.\s*\#\s*define\s+(?:$underscore_smp_barriers)\s*\(/) {
6701 "__smp memory barriers shouldn't be used outside barrier.h and asm-generic\n" . $herecurr);
6705 if ($line =~ /\bwaitqueue_active\s*\(/) {
6713 if ($line =~ /\bdata_race\s*\(/) {
6721 …if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@inc…
6727 if ($line =~ /\b($Type)\s+($Storage)\b/) {
6733 $line !~ /^.\s*$Storage/ &&
6734 $line =~ /^.\s*(.+?)\$Storage\s/ &&
6735 $1 !~ /[\,\)]\s*$/) {
6742 if ($line =~ /\b$Type\s+$Inline\b/ ||
6743 $line =~ /\b$Inline\s+$Storage\b/) {
6754 $fixed[$fixlinenr] =~ s/\b(__inline__|__inline)\b/inline/;
6761 $rawline =~ /\b__attribute__\s*\(\s*($balanced_parens)\s*\)/) {
6763 $attr =~ s/\s*\(\s*(.*)\)\s*/$1/;
6791 while ($attr =~ /\s*(\w+)\s*(${balanced_parens})?/g) {
6796 $curr_attr =~ s/^[\s_]+|[\s_]+$//g;
6800 $params =~ /^\s*\(\s*(\w+)\s*,\s*(.*)/;
6808 my $remove = "\Q$orig_attr\E" . '\s*' . "\Q$params\E" . '(?:\s*,\s*)?';
6809 $fixed[$fixlinenr] =~ s/$remove//;
6810 $fixed[$fixlinenr] =~ s/\b__attribute__/$new __attribute__/;
6811 $fixed[$fixlinenr] =~ s/\}\Q$new\E/} $new/;
6812 $fixed[$fixlinenr] =~ s/ __attribute__\s*\(\s*\(\s*\)\s*\)//;
6826 … $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ &&
6827 ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ ||
6836 $line =~ /\b($Declare)\s*$Ident\s*[=;,\[]/) {
6841 $kernel_type = 's' if ($type =~ /^_*[si]/);
6847 $fixed[$fixlinenr] =~ s/\b$type\b/$kernel_type/;
6853 if ($line =~ /(\(\s*$C90_int_types\s*\)\s*)($Constant)\b/) {
6858 $newconst =~ s/${Int_type}$//;
6860 if ($cast =~ /\blong\s+long\b/) {
6866 …"Unnecessary typecast of c90 int constant - '$cast$const' could be '$const$suffix'\n" . $herecurr)…
6868 $fixed[$fixlinenr] =~ s/\Q$cast\E$const\b/$newconst$suffix/;
6873 if ($line =~ /\bsizeof\s*\(\s*\&/) {
6879 if ($line =~ /\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/) {
6883 …$fixed[$fixlinenr] =~ s/\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/"sizeof(" . trim($1) . ")"…
6888 if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) {
6894 if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
6896 $fmt =~ s/%%//g;
6901 $fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/;
6909 $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s &&
6920 my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
6921 $fmt =~ s/%%//g;
6949 $use = " - use %pS instead";
6950 $use =~ s/pS/ps/ if ($bad_specifier =~ /pf/);
6952 $use = " - '%pA' is only intended to be used from Rust code";
6965 $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/) {
6973 "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
6983 # $stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
6987 # $fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_add…
6994 # $stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
7003 # $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
7011 # $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_…
7017 # $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broad…
7023 if ($line =~ /\bstrcpy\s*\(/) {
7025 "Prefer strscpy over strcpy - see: https://github.com/KSPP/linux/issues/88\n" . $herecurr);
7029 if ($line =~ /\bstrlcpy\s*\(/) {
7031 "Prefer strscpy over strlcpy - see: https://github.com/KSPP/linux/issues/89\n" . $herecurr);
7035 if ($line =~ /\bstrncpy\s*\(/) {
7037 …"Prefer strscpy, strscpy_pad, or __nonstring over strncpy - see: https://github.com/KSPP/linux/iss…
7041 if ($line =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
7045 …$fixed[$fixlinenr] =~ s/\bethtool_sprintf\s*\(\s*($FuncArg)\s*,\s*($FuncArg)/ethtool_puts($1, $7)/;
7049 # use $rawline because $line loses %s via sanitization and thus we can't match against it.
7050 if ($rawline =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*\"\%s\"\s*,\s*$FuncArg\s*\)/) {
7052 "Prefer ethtool_puts over ethtool_sprintf with standalone \"%s\" specifier\n" . $herecurr) &&
7054 …$fixed[$fixlinenr] =~ s/\bethtool_sprintf\s*\(\s*($FuncArg)\s*,\s*"\%s"\s*,\s*($FuncArg)/ethtool_p…
7062 $stat =~ /^\+(?:.*?)\b(min|max)\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
7086 $stat =~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) {
7103 ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ &&
7104 $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ &&
7105 $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) {
7120 if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) {
7133 $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
7137 $fixed[$fixlinenr] =~ s/(.*)\bextern\b\s*(.*)/$1$2/;
7143 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
7148 my $s = $stat;
7150 substr($s, 0, length($cond), '');
7152 if ($s =~ /^\s*;/)
7164 $stat =~ /^\+extern struct\s+(\w+)\s+(\w+)\[\];/)
7168 for my $s (keys %maybe_linker_symbol) {
7169 #print "Linker symbol? $st_name : $s\n";
7171 if $st_name =~ /$s/;
7174 "found a file-scoped extern type:$st_type name:$st_name in .c file\n"
7179 $stat =~ /^.\s*extern\s+/)
7187 … $stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s &&
7190 while ($args =~ m/\s*($Type\s*(?:$Ident|\(\s*\*\s*$Ident?\s*\)\s*$balanced_parens)?)/g) {
7192 if ($arg =~ /^$Type$/ && $arg !~ /enum\s+$Ident$/) {
7202 $stat =~ /^.\s*(?:$Storage\s+)?$Type\s*($Ident)\s*$balanced_parens\s*{/s) {
7222 # checks for new __setup's
7228 …"__setup appears un-documented -- check Documentation/admin-guide/kernel-parameters.txt\n" . $here…
7233 if ($line =~ /\*\s*\)\s*$allocFunctions\b/) {
7235 … "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
7241 …$line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k|v)[mz]alloc(?:_node)?)\s*\(\s*(sizeof\
7249 …$stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\
7259 if ($a1 =~ /^sizeof\s*\S/) {
7263 if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ &&
7264 !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) {
7272 …$fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($Func…
7279 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*($Lval)\s*,/ &&
7286 if ($line =~ /\b((?:devm_)?((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
7292 if ($line =~ /;\s*;\s*$/) {
7296 $fixed[$fixlinenr] =~ s/(\s*;\s*){2,}$/;/g;
7302 $line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) {
7308 $fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/BIT${ull}($1)/;
7313 if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^${CONFIG_}/) {
7319 …if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(${CONFIG_}[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:…
7332 'lint -fallthrough[ \t]*',
7333 'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)',
7334 '(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?',
7335 'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
7336 'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
7353 $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) {
7366 $fixed[$fixlinenr] =~ s/\b__FUNCTION__\b/__func__/g;
7373 "Use of the '$1' macro makes the build non-deterministic\n" . $herecurr);
7377 if ($line =~ /\byield\s*\(\s*\)/) {
7379 "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr);
7383 if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(.*)$/i) {
7410 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
7416 if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) {
7422 if ($line =~ /^.\s*__initcall\s*\(/) {
7434 if ($line =~ /\b($deprecated_apis_search)\b\s*\(/) {
7445 $line =~ /\bstruct\s+($const_structs)\b(?!\s*\{)/) {
7454 $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
7455 $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
7456 $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
7459 $line !~ /^.\s*\.\w+\s*=\s*.*\bNR_CPUS\b/)
7462 …"usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_po…
7466 if ($line =~ /\+\s*#\s*define\s+((?:__)?ARCH_(?:HAS|HAVE)\w*)\b/) {
7468 … "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
7473 $line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) {
7479 if ($line =~ /\breturn\s+sysfs_emit\s*\(\s*$FuncArg\s*,\s*($String)/ &&
7480 substr($rawline, $-[6], $+[6] - $-[6]) !~ /\\n"$/) {
7481 my $offset = $+[6] - 1;
7490 if ($sline =~ /^[\+ ]\s*\}(?:\s*__packed)?\s*;\s*$/ &&
7491 $prevline =~ /^\+\s*(?:\}(?:\s*__packed\s*)?|$Type)\s*$Ident\s*\[\s*(0|1)\s*\]\s*;\s*$/) {
7493 …"Use C99 flexible arrays - see https://docs.kernel.org/process/deprecated.html#zero-length-and-one
7495 $fixed[$fixlinenr - 1] =~ s/\[\s*0\s*\]/[]/;
7500 if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) {
7506 if ($line =~ /\bin_atomic\s*\(/) {
7533 if ($line =~ /\b($rcu_trace_funcs)\s*\(/) {
7541 if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
7542 $line =~ /__lockdep_no_validate__\s*\)/ ) {
7547 "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
7562 … =~ /\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?\s*(\s*(?:${multi_mode_perms_string_search}|0[0-7]{3,3})\
7574 …$fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*$store\s*\)/D…
7582 …$fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*NULL\s*\)/DEV…
7590 …$fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*NULL\s*,\s*$store\s*\)/DE…
7607 "Consider renaming function(s)$rename\n" . $herecurr);
7624 my $func = $entry->[0];
7625 my $arg_pos = $entry->[1];
7633 $arg_pos--;
7634 $skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}";
7636 my $test = "\\b$func\\s*\\(${skip_args}($FuncArg(?:\\|\\s*$FuncArg)*)\\s*[,\\)]";
7661 $fixed[$fixlinenr] =~ s/\Q$oval\E/$octal/;
7666 if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) {
7683 …"Prefer \"GPL\" over \"GPL v2\" - see commit bf7fbeeae6db (\"module: Cure the MODULE_LICENSE \"GPL…
7685 $fixed[$fixlinenr] =~ s/\bMODULE_LICENSE\s*\(\s*"GPL v2"\s*\)/MODULE_LICENSE("GPL")/;
7691 if ($line =~ /\.extra[12]\s*=\s*&(zero|one|int_max)\b/) {
7697 if (defined $stat && $line =~ /struct\s+$dev_id_types\s+\w+\s*\[\s*\]\s*=\s*\{/) {
7701 $stripped =~ s/(^|\n)./$1/g;
7703 $stripped =~ s/\\\n/\n/g;
7705 $stripped =~ s/""//g;
7706 $stripped =~ s/0x0//g;
7707 $stripped =~ s/[\s$;,0]//g;
7709 $stripped =~ s/\.$Ident=//g;
7711 if (!(substr($stripped, -4) eq "{}};" ||
7712 substr($stripped, -6) eq "{{}}};" ||
7724 if ($#rawlines == -1) {
7734 # This is not a patch, and we are in 'no-patch' mode so
7740 if (!$is_patch && $filename !~ /cover-letter\.patch$/) {
7742 "Does not appear to be a unified-diff format patch\n");
7753 "Missing Signed-off-by: line(s)\n");
7756 # 0 -> missing sign off
7757 # 1 -> sign off identical
7758 # 2 -> names and addresses match, comments mismatch
7759 # 3 -> addresses match, names different
7760 # 4 -> names match, addresses different
7761 # 5 -> names match, addresses excluding subaddress details (refer RFC 5233) match
7763 my $sob_msg = "'From: $author' != 'Signed-off-by: $author_sob'";
7767 "Missing Signed-off-by: line by nominal patch author '$author'\n");
7770 "From:/Signed-off-by: email comments mismatch: $sob_msg\n");
7773 "From:/Signed-off-by: email name mismatch: $sob_msg\n");
7776 "From:/Signed-off-by: email address mismatch: $sob_msg\n");
7779 "From:/Signed-off-by: email subaddress mismatch: $sob_msg\n");
7798 mechanically convert to the typical style using --fix or --fix-inplace.
7817 $newfile .= ".EXPERIMENTAL-checkpatch-fixes" if (!$fix_inplace);
7829 $fixed_line =~ s/^\+//;
7841 Wrote EXPERIMENTAL --fix correction(s) to '$newfile'