Lines Matching +full:1 +full:s

29 my $tree = 1;
30 my $chk_signoff = 1;
31 my $chk_fixes_tag = 1;
32 my $chk_patch = 1;
42 my $summary = 1;
61 (my $def_configuration_dirs = $def_configuration_dirs_help) =~ s/\$(\w+)/$ENV{$1}/g;
76 my $allow_c99_comments = 1; # Can be overridden by --ignore C99_COMMENT_TOLERANCE
127 --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
139 file. It's your fault if there's no backup or git
205 while ($text =~ /(?:(\bCHK|\bWARN|\bERROR|&\{\$msg_level})\s*\(|\$msg_type\s*=)\s*"([^"]+)"/g) {
206 if (defined($1)) {
208 $types{$2} .= ",$1" if ($types{$2} ne $1);
210 $types{$2} = $1;
245 $message =~ s/\n/\n\t/g;
262 $line =~ s/\s*\n?$//g;
263 $line =~ s/^\s*//g;
264 $line =~ s/\s+/ /g;
266 next if ($line =~ m/^\s*#/);
267 next if ($line =~ m/^\s*$/);
290 $line =~ s/\s+$//;
292 if ($line =~ /^\s*\*\*(.+)\*\*$/) {
296 $type = $1;
298 $in_desc = 1;
300 if ($line =~ /^(?:\s{4,}|$)/) {
301 $line =~ s/^\s{4}//;
319 # Perl's Getopt::Long allows options to take optional arguments after a space.
341 'ignore=s' => \@ignore,
342 'types=s' => \@use,
348 'root=s' => \$root,
356 'debug=s' => \%debug,
357 'test-only=s' => \$tst_only,
359 'codespellfile=s' => \$user_codespellfile,
360 'typedefsfile=s' => \$typedefsfile,
361 'color=s' => \$color,
364 'kconfig-prefix=s' => \${CONFIG_},
374 # under codespell's install directory: <codespell_root>/data/dictionary.txt
390 # $help is 1 if either -h, --help or --version is passed as option - exitcode: 0
391 # $help is 2 if invalid option is passed - exitcode: 1
392 help($help - 1) if ($help);
400 $color = 1;
412 $fix = 1 if ($fix_inplace);
417 my $perl_version_ok = 1;
421 exit(1) if (!$ignore_perl_version);
429 # skip TAB size 1 to avoid additional checks on $tabsize - 1
437 $word =~ s/\s*\n?$//g;
438 $word =~ s/^\s*//g;
439 $word =~ s/\s+/ /g;
442 next if ($word =~ m/^\s*#/);
443 next if ($word =~ m/^\s*$/);
477 $emacs = 1;
490 top_of_kernel_tree($1)) {
491 $root = $1;
505 (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
551 __aligned\s*\(.*\)|
556 __alloc_size\s*\(\s*\d+\s*(?:,\s*\d+\s*)?\)
599 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
615 (?:__)?(?:u|s|be|le)(?:8|16|32|64)|
632 (?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
700 [\.\!:\s]*
709 if ((scalar @arr) < 1) {
714 for my $i (0 .. ($len-1)) {
726 $str1 =~ s/-//g;
727 $str2 =~ s/-//g;
738 } elsif (substr($str1, $i-1, 1) eq substr($str2, $j-1, 1)) {
739 $distance[$i][$j] = $distance[$i - 1][$j - 1];
741 my $dist1 = $distance[$i][$j - 1]; #insert distance
742 my $dist2 = $distance[$i - 1][$j]; # remove
743 my $dist3 = $distance[$i - 1][$j - 1]; #replace
744 $distance[$i][$j] = 1 + edit_distance_min($dist1, $dist2, $dist3);
776 qr{char\s+(?:un)?signed},
777 qr{int\s+(?:(?:un)?signed\s+)?short\s},
778 qr{int\s+short(?:\s+(?:un)?signed)},
779 qr{short\s+int(?:\s+(?:un)?signed)},
780 qr{(?:un)?signed\s+int\s+short},
781 qr{short\s+(?:un)?signed},
782 qr{long\s+int\s+(?:un)?signed},
783 qr{int\s+long\s+(?:un)?signed},
784 qr{long\s+(?:un)?signed\s+int},
785 qr{int\s+(?:un)?signed\s+long},
786 qr{int\s+(?:un)?signed},
787 qr{int\s+long\s+long\s+(?:un)?signed},
788 qr{long\s+long\s+int\s+(?:un)?signed},
789 qr{long\s+long\s+(?:un)?signed\s+int},
790 qr{long\s+long\s+(?:un)?signed},
791 qr{long\s+(?:un)?signed},
796 qr{(?:(?:un)?signed\s+)?char},
797 qr{(?:(?:un)?signed\s+)?short\s+int},
798 qr{(?:(?:un)?signed\s+)?short},
799 qr{(?:(?:un)?signed\s+)?int},
800 qr{(?:(?:un)?signed\s+)?long\s+int},
801 qr{(?:(?:un)?signed\s+)?long\s+long\s+int},
802 qr{(?:(?:un)?signed\s+)?long\s+long},
803 qr{(?:(?:un)?signed\s+)?long},
808 qr{struct\s+$Ident},
809 qr{union\s+$Ident},
810 qr{enum\s+$Ident},
818 long\s+long\s+int\s+(?:un)?signed|
819 long\s+long\s+(?:un)?signed\s+int|
820 long\s+long\s+(?:un)?signed|
821 (?:(?:un)?signed\s+)?long\s+long\s+int|
822 (?:(?:un)?signed\s+)?long\s+long|
823 int\s+long\s+long\s+(?:un)?signed|
824 int\s+(?:(?:un)?signed\s+)?long\s+long|
826 long\s+int\s+(?:un)?signed|
827 long\s+(?:un)?signed\s+int|
828 long\s+(?:un)?signed|
829 (?:(?:un)?signed\s+)?long\s+int|
830 (?:(?:un)?signed\s+)?long|
831 int\s+long\s+(?:un)?signed|
832 int\s+(?:(?:un)?signed\s+)?long|
834 int\s+(?:un)?signed|
835 (?:(?:un)?signed\s+)?int
841 qr{struct\s+$InitAttribute\s+$Ident},
842 qr{union\s+$InitAttribute\s+$Ident},
857 ["IIO_DEV_ATTR_[A-Z_]+", 1],
928 (?:\s*\|\s*${single_mode_perms_string_search})*
934 return trim($string) if ($string =~ /^\s*0[0-7]{3,3}\s*$/);
941 while ($string =~ /\b(($single_mode_perms_string_search)\b(?:\s*\|\s*)?\s*)/g) {
944 my $omatch = $1;
948 $val .= '\s*\|\s*' if ($val ne "");
952 $oval =~ s/^\s*\|\s*//;
953 $oval =~ s/\s*\|\s*$//;
973 $line =~ s/\s*\n?$//g;
974 $line =~ s/^\s*//g;
976 next if ($line =~ m/^\s*#/);
977 next if ($line =~ m/^\s*$/);
993 $line =~ s/\s*\n?$//g;
994 $line =~ s/^\s*//g;
996 next if ($line =~ m/^\s*#/);
997 next if ($line =~ m/^\s*$/);
1000 $line =~ s/,.*$//;
1021 $line =~ s/\s*\n?$//g;
1022 $line =~ s/^\s*//g;
1024 next if ($line =~ m/^\s*#/);
1025 next if ($line =~ m/^\s*$/);
1026 if ($line =~ /\s/) {
1035 return 1;
1065 (?:$Modifier\s+|const\s+)*
1067 (?:typeof|__typeof__)\s*\([^\)]*\)|
1071 (?:\s+$Modifier|\s+const)*
1074 (?:$Modifier\s+|const\s+)*
1078 (?:\s+$Modifier|\s+const)*
1081 (?:$Modifier\s+|const\s+)*
1083 (?:typeof|__typeof__)\s*\([^\)]*\)|
1087 (?:\s+$Modifier|\s+const)*
1091 (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4}
1092 (?:\s+$Inline|\s+$Modifier)*
1096 (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*\s*(?:const\s*)?|\[\])+|(?:\s*\[\s*\])+){0,4}
1097 (?:\s+$Inline|\s+$Modifier)*
1099 $Declare = qr{(?:$Storage\s+(?:$Inline\s+)?)?$Type};
1100 $DeclareMisordered = qr{(?:$Storage\s+(?:$Inline\s+)?)?$TypeMisordered};
1104 our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
1110 our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
1111 our $LvalOrFunc = qr{((?:[\&\*]\s*)?$Lval)\s*($balanced_parens{0,1})\s*};
1112 our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant|$String)};
1115 (?:$Storage\s+)?(?:[A-Z_][A-Z0-9]*_){0,2}(?:DEFINE|DECLARE)(?:_[A-Z0-9]+){1,6}\s*\(|
1116 (?:$Storage\s+)?[HLP]?LIST_HEAD\s*\(|
1117 (?:SKCIPHER_REQUEST|SHASH_DESC|AHASH_REQUEST)_ON_STACK\s*\(|
1118 (?:$Storage\s+)?(?:XA_STATE|XA_STATE_ORDER)\s*\(|
1119 __cacheline_group_(?:begin|end)(?:_aligned)?\s*\(|
1120 __dma_from_device_group_(?:begin|end)\s*\(
1134 while ($string =~ /^\s*\(.*\)\s*$/) {
1135 $string =~ s@^\s*\(\s*@@;
1136 $string =~ s@\s*\)\s*$@@;
1139 $string =~ s@\s+@ @g;
1160 if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
1161 $camelcase{$1} = 1;
1162 } elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
1163 $camelcase{$1} = 1;
1164 } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
1165 $camelcase{$1} = 1;
1178 $maintained_status{$filename} = `perl $root/scripts/get_maintainer.pl --status --nom --nol --nogit --nogit-fallback -f $filename 2>&1`;
1187 return 1 if (!$tree || which("python3") eq "" || !(-x "$root/scripts/spdxcheck.py") || !(-e "$gitroot"));
1192 return 1;
1203 $camelcase_seeded = 1;
1206 my $git_last_include_commit = `${git_command} log --no-merges --pretty=format:"%h%n" -1 -- include`;
1226 $camelcase{$_} = 1;
1260 return $count eq 1 && $output =~ m{^${filename}$};
1268 my $output = `${git_command} log --no-color --format='%H %s' -1 $commit 2>&1`;
1269 $output =~ s/^\s*//gm;
1276 # all matching commit ids, but it's very slow...
1278 # echo "checking commits $1..."
1279 # git rev-list --remotes | grep -i "^$1" |
1281 # git log --format='%H %s' -1 $line |
1282 # echo "commit $(cut -c 1-12,41-)"
1303 my $fixlinenr = -1;
1306 # For example, HEAD-3 means we need check 'HEAD, HEAD~1, HEAD~2'.
1314 $git_range = "-$2 $1";
1318 $git_range = "-1 $commit_expr";
1320 my $lines = `${git_command} log --no-color --no-merges --pretty=format:'%H %s' $git_range`;
1323 next if (!defined($1) || !defined($2));
1324 my $sha1 = $1;
1340 $file = 1 if ($is_git_file);
1342 open($FILE, '-|', "git format-patch -M --stdout -1 $filename") ||
1363 $vname = qq("$1") if ($filename eq '-' && $_ =~ m/^Subject:\s+(.+)/i);
1374 $exit = 1;
1381 $fixlinenr = -1;
1424 return 1;
1436 if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) {
1437 $name = $1;
1440 } elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) {
1441 $address = $1;
1443 } elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) {
1444 $address = $1;
1446 $formatted_email =~ s/\Q$address\E.*$//;
1449 $name =~ s/^\"|\"$//g;
1450 # If there's a name left after stripping spaces and
1465 if ($name =~ s/\"(.+)\"//) {
1466 $quoted = $1;
1468 while ($name =~ s/\s*($balanced_parens)\s*/ /) {
1469 $name_comment .= trim($1);
1471 $name =~ s/^[ \"]+|[ \"]+$//g;
1475 $address =~ s/^\<|\>$//g;
1479 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
1491 $name =~ s/^[ \"]+|[ \"]+$//g;
1493 $address =~ s/(?:\.|\,|\")+$//; ##trailing commas, dots or quotes
1496 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
1592 $line =~ s/^.//;
1596 my ($white) = ($line =~ /^(\s*)/);
1623 $res = substr($line, 0, 1);
1625 for ($off = 1; $off < length($line); $off++) {
1626 $c = substr($line, $off, 1);
1663 substr($res, $off, 1, $c);
1672 substr($res, $off, 1, $;);
1674 substr($res, $off, 1, $;);
1676 substr($res, $off, 1, 'X');
1678 substr($res, $off, 1, $c);
1687 if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {
1688 my $clean = 'X' x length($1);
1689 $res =~ s@\<.*\>@<$clean>@;
1692 } elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {
1693 my $clean = 'X' x length($1);
1694 $res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@;
1698 my $match = $1;
1699 $res =~ s/\Q$match\E/"$;" x length($match)/e;
1715 my $line = $linenr - 1;
1718 my $coff = $off - 1;
1731 while (1) {
1732 @stack = (['', 0]) if ($#stack == -1);
1753 if ($level == 0 && substr($blk, $off) =~ /^.\s*#\s*define/) {
1759 $c = substr($blk, $off, 1);
1765 if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
1767 } elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
1768 ($type, $level) = @{$stack[$#stack - 1]};
1769 } elsif ($remainder =~ /^#\s*endif\b/) {
1781 (!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
1782 $remainder =~ /^(else)(?:\s|{)/ &&
1783 $remainder !~ /^else\s+if\b/) {
1784 $coff = $off + length($1) - 1;
1785 $coff_set = 1;
1786 #warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";
1787 #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
1800 $coff_set = 1;
1813 if (substr($blk, $off + 1, 1) eq ';') {
1830 $loff = $len + 1;
1835 my $statement = substr($blk, $soff, $off - $soff + 1);
1836 my $condition = substr($blk, $soff, $coff - $soff + 1);
1844 $line, $remain + 1, $off - $loff + 1, $level);
1851 $stmt =~ s/(^|\n)./$1/g;
1852 $stmt =~ s/^\s*//;
1853 $stmt =~ s/\s*$//;
1871 $stmt =~ s/(^|\n)./$1/g;
1872 $stmt =~ s/^\s*{//;
1873 $stmt =~ s/}\s*$//;
1874 $stmt =~ s/^\s*//;
1875 $stmt =~ s/\s*$//;
1881 my $stmt_statements = $#stmt_statements + 1;
1899 #print "F: c<$condition> s<$statement> remain<$remain>\n";
1901 if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
1910 #print "C: c<$condition> s<$statement> remain<$remain>\n";
1911 last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
1922 my $start = $linenr - 1;
1937 if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
1939 } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
1940 $level = $stack[$#stack - 1];
1941 } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
1960 if (!$outer || $level <= 1) {
1972 my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0);
2002 my ($current_comment) = ($rawlines[$end_line - 1] =~ m@^\+.*(//.*$)@);
2010 ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
2018 my $line = $rawlines[$linenr - 1];
2020 if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
2021 $in_comment = 1;
2024 $in_comment = 1;
2042 ##print "LINE: $rawlines[$end_line - 1 ]\n";
2051 my $offset = $linenr - 1;
2068 for (my $count = $linenr + 1; $count <= $lc; $count++) {
2092 $res .= $1;
2098 $res =~ s/$/\$/;
2122 print "$stream\n" if ($dbg_values > 1);
2127 "> <$type> <$av_pending>" if ($dbg_values > 1);
2128 if ($cur =~ /^(\s+)/o) {
2129 print "WS($1)\n" if ($dbg_values > 1);
2130 if ($1 =~ /\n/ && $av_preprocessor) {
2135 } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
2136 print "CAST($1)\n" if ($dbg_values > 1);
2140 } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
2141 print "DECLARE($1)\n" if ($dbg_values > 1);
2144 } elsif ($cur =~ /^($Modifier)\s*/) {
2145 print "MODIFIER($1)\n" if ($dbg_values > 1);
2148 } elsif ($cur =~ /^(\#\s*define\s*$Ident)(\(?)/o) {
2149 print "DEFINE($1,$2)\n" if ($dbg_values > 1);
2150 $av_preprocessor = 1;
2157 } elsif ($cur =~ /^(\#\s*(?:undef\s*$Ident|include\b))/o) {
2158 print "UNDEF($1)\n" if ($dbg_values > 1);
2159 $av_preprocessor = 1;
2162 } elsif ($cur =~ /^(\#\s*(?:ifdef|ifndef|if))/o) {
2163 print "PRE_START($1)\n" if ($dbg_values > 1);
2164 $av_preprocessor = 1;
2170 } elsif ($cur =~ /^(\#\s*(?:else|elif))/o) {
2171 print "PRE_RESTART($1)\n" if ($dbg_values > 1);
2172 $av_preprocessor = 1;
2178 } elsif ($cur =~ /^(\#\s*(?:endif))/o) {
2179 print "PRE_END($1)\n" if ($dbg_values > 1);
2181 $av_preprocessor = 1;
2190 print "PRECONT($1)\n" if ($dbg_values > 1);
2192 } elsif ($cur =~ /^(__attribute__)\s*\(?/o) {
2193 print "ATTR($1)\n" if ($dbg_values > 1);
2197 } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
2198 print "SIZEOF($1)\n" if ($dbg_values > 1);
2205 print "COND($1)\n" if ($dbg_values > 1);
2210 print "CASE($1)\n" if ($dbg_values > 1);
2215 print "KEYWORD($1)\n" if ($dbg_values > 1);
2219 print "PAREN('$1')\n" if ($dbg_values > 1);
2228 print "PAREN('$1') -> $type\n"
2229 if ($dbg_values > 1);
2231 print "PAREN('$1')\n" if ($dbg_values > 1);
2234 } elsif ($cur =~ /^($Ident)\s*\(/o) {
2235 print "FUNC($1)\n" if ($dbg_values > 1);
2239 } elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) {
2245 print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1);
2249 print "IDENT($1)\n" if ($dbg_values > 1);
2253 print "ASSIGN($1)\n" if ($dbg_values > 1);
2257 print "END($1)\n" if ($dbg_values > 1);
2262 print "COMMA($1)\n" if ($dbg_values > 1);
2266 print "QUESTION($1)\n" if ($dbg_values > 1);
2270 print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1);
2272 substr($var, length($res), 1, $av_pend_colon);
2281 print "CLOSE($1)\n" if ($dbg_values > 1);
2287 print "OPV($1)\n" if ($dbg_values > 1);
2294 substr($var, length($res), 1, $variant);
2298 print "OP($1)\n" if ($dbg_values > 1);
2299 if ($1 ne '++' && $1 ne '--') {
2304 print "C($1)\n" if ($dbg_values > 1);
2306 if (defined $1) {
2307 $cur = substr($cur, length($1));
2308 $res .= $type x length($1);
2322 DEFINE_\S+
2333 )(?:\s|$)|
2339 $possible =~ s/\s*$Storage\s*//g;
2340 $possible =~ s/\s*$Sparse\s*//g;
2341 if ($possible =~ /^\s*$/) {
2343 } elsif ($possible =~ /\s/) {
2344 $possible =~ s/\s*$Type\s*//g;
2358 warn "NOTPOSS: $possible ($line)\n" if ($dbg_possible > 1);
2400 my @lines = split("\n", $output, -1);
2401 splice(@lines, 1, 1);
2412 $verbose_emitted{$type} = 1;
2417 return 1;
2428 my $o = $1;
2432 $$lineRef =~ s/\+$o,$l \@\@/\+$no,$nl \@\@/;
2454 my $save_line = 1;
2456 if ($line =~ /^(?:\+\+\+|\-\-\-)\s+\S+/) { #new filename
2466 fixup_current_range(\$lines[$range_last_linenr], $delta_offset--, -1);
2473 fixup_current_range(\$lines[$range_last_linenr], $delta_offset++, 1);
2514 return 1;
2524 return 1;
2534 return 1;
2546 while ($file =~ s@^[^/]*/@@) {
2570 $string =~ s/^\s+|\s+$//g;
2578 $string =~ s/^\s+//;
2586 $string =~ s/\s+$//;
2594 $string =~ s/$find/$replace/g;
2603 my $max_spaces_before_tab = $source_indent - 1;
2607 1 while $leading =~ s@^([\t]*)$spaces_to_tab@$1\t@g;
2609 1 while $leading =~ s@^([\t]*)( {1,$max_spaces_before_tab})\t@$1\t@g;
2625 return -1;
2633 $pos += length($1) - 1;
2634 } elsif (substr($line, $pos, 1) eq '(') {
2636 } elsif (index($string, '(') == -1) {
2641 return length(expand_tabs(substr($line, 0, $last_openparen))) + 1;
2648 for my $i (0 .. (length($line) - 1)) {
2649 if (substr($line, $i, 1) eq "$;") {
2650 $comment .= substr($rawline, $i, 1);
2685 our $clean = 1;
2694 my $is_binding_patch = -1;
2695 my $in_header_lines = $file ? 0 : 1;
2706 my $last_git_commit_id_linenr = -1;
2709 my $last_coalesced_string_linenr = -1;
2722 my $context_function; #undef'd unless there's a known function
2746 my $checklicenseline = 1;
2756 if ($rawline=~/^\+\+\+\s+(\S+)/) {
2758 if ($1 =~ m@Documentation/admin-guide/kernel-parameters.txt$@) {
2759 $setup_docs = 1;
2764 $realline=$1-1;
2766 $realcnt=$3+1;
2768 $realcnt=1+1;
2778 for (my $ln = $linenr + 1; $cnt > 0; $ln++) {
2779 next if (defined $rawlines[$ln - 1] &&
2780 $rawlines[$ln - 1] =~ /^-/);
2782 #print "RAW<$rawlines[$ln - 1]>\n";
2783 last if (!defined $rawlines[$ln - 1]);
2784 if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
2785 $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
2786 ($edge) = $1;
2791 $in_comment = 1;
2798 $rawlines[$linenr] =~ m@^.\s*(?:\*\*+| \*)(?:\s|$)@)
2800 $in_comment = 1;
2813 if ($realcnt > 1) {
2831 $fixlinenr = -1;
2836 $sline =~ s/$;/ /g; #with comments as spaces
2838 my $rawline = $rawlines[$linenr - 1];
2841 # check if it's a mode change, rename or start of a patch
2843 ($line =~ /^ mode change [0-7]+ => [0-7]+ \S+\s*$/ ||
2844 ($line =~ /^rename (?:from|to) \S+\s*$/ ||
2845 $line =~ /^diff --git a\/[\w\/\.\_\-]+ b\/\S+\s*$/))) {
2846 $is_patch = 1;
2853 $is_patch = 1;
2854 $first_line = $linenr + 1;
2855 $realline=$1-1;
2857 $realcnt=$3+1;
2859 $realcnt=1+1;
2868 if ($context =~ /\b(\w+)\s*\(/) {
2869 $context_function = $1;
2892 } elsif ($realcnt == 1) {
2903 if ($line =~ /^diff --git.*?(\S+)$/) {
2904 $realfile = $1;
2905 $realfile =~ s@^([^/]*)/@@ if (!$file);
2907 $found_file = 1;
2908 } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
2909 $realfile = $1;
2910 $realfile =~ s@^([^/]*)/@@ if (!$file);
2913 $p1_prefix = $1;
2924 $found_file = 1;
2944 $check = 1;
2948 $checklicenseline = 1;
2955 if (($last_binding_patch != -1) &&
2976 if ($line !~ /^\s*$/) {
2987 (($line =~ m@^\s+diff\b.*a/([\w/]+)@ &&
2988 $line =~ m@^\s+diff\b.*a/[\w/]+\s+b/$1\b@) ||
2989 $line =~ m@^\s*(?:\-\-\-\s+a/|\+\+\+\s+b/)@ ||
2990 $line =~ m/^\s*\@\@ \-\d+,\d+ \+\d+,\d+ \@\@/)) {
2992 "Avoid using diff content in the commit message - patch(1) might not work\n" . $herecurr);
2993 $commit_log_has_diff = 1;
3007 if (decode("MIME-Header", $line) =~ /^From:\s*(.*)/) {
3008 $author = $1;
3010 while(defined($rawlines[$curline]) && ($rawlines[$curline++] =~ /^[ \t]\s*(.*)/)) {
3011 $author .= $1;
3014 $author =~ s/"//g;
3019 if ($line =~ /^\s*signed-off-by:\s*(.*)/i) {
3022 if ($author ne '' && $authorsignoff != 1) {
3023 if (same_email_addresses($1, $author)) {
3024 $authorsignoff = 1;
3026 my $ctx = $1;
3043 if ($address1 =~ /(\S+)\+\S+(\@.*)/) {
3044 $address1 = "$1$2";
3046 if ($address2 =~ /(\S+)\+\S+(\@.*)/) {
3047 $address2 = "$1$2";
3063 $fixed[$fixlinenr] =~ s/-/=/g;
3069 $has_patch_separator = 1;
3073 # Check if MAINTAINERS is being updated. If so, there's probably no need to
3075 if ($line =~ /^\s*MAINTAINERS\s*\|/) {
3076 $reported_maintainer_file = 1;
3081 $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
3082 my $space_before = $1;
3097 $fixed[$fixlinenr] =~ s/$sign_off/$suggested_signature/;
3130 if ($email =~ /^\s*$/) {
3144 $dequoted =~ s/^"//;
3145 $dequoted =~ s/" </ </;
3152 $fixed[$fixlinenr] =~ s/\Q$email\E/$suggested_email/;
3158 $stripped_address =~ s/\([^\(\)]*\)//g;
3163 $fixed[$fixlinenr] =~ s/\Q$email_address\E/$stripped_address/;
3169 if ($comment_count > 1) {
3183 $cur_name =~ s/[a-zA-Z\s\-\"]+//g;
3187 $new_comment =~ s/^\((.*)\)$/$1/;
3188 $new_comment =~ s/^\[(.*)\]$/$1/;
3189 $new_comment =~ s/^[\s\#]+|\s+$//g;
3198 $fixed[$fixlinenr] =~ s/\Q$email\E/$new_email/;
3206 $new_comment =~ s/^\[(.*)\]$/$1/;
3207 $new_comment =~ s/^\/\*(.*)\*\/$/$1/;
3210 $new_comment =~ s/^[^\w]$//; # Single lettered comment with non word character is usually a typo
3217 $fixed[$fixlinenr] =~ s/\Q$email\E/$new_email/;
3224 $sig_nospace =~ s/\s//g;
3230 $signatures{$sig_nospace} = 1;
3242 } elsif ($rawlines[$linenr] !~ /^signed-off-by:\s*(.*)/i) {
3245 } elsif ($1 ne $email) {
3256 } elsif ($rawlines[$linenr] !~ /^(closes|link):\s*/i) {
3266 $is_revert = 1;
3271 $needs_fixes_tag = $1;
3276 $line =~ /^\s*(fixes:?)\s*(?:commit\s*)?([0-9a-f]{5,40})(?:\s*($balanced_parens))?/i) {
3277 my $tag = $1;
3281 $fixes_tag = 1;
3284 $title = substr($3, 1, -1);
3286 $title = substr($title, 1, -1);
3287 $title_has_quotes = 1;
3322 if ($realfile eq '' && !$has_patch_separator && $line =~ /^\s*change-id:/i) {
3324 "Remove Gerrit Change-Id's before submitting upstream\n" . $herecurr) &&
3332 ($line =~ /^\s*(?:WARNING:|BUG:)/ ||
3333 $line =~ /^\s*\[\s*\d+\.\d{6,6}\s*\]/ ||
3335 $line =~ /^\s*\[\<[0-9a-fA-F]{8,}\>\]/) ||
3336 $line =~ /^(?:\s+\w+:\s+[0-9a-fA-F]+){3,3}/ ||
3337 $line =~ /^\s*\#\d+\s*\[[0-9a-fA-F]+\]\s*\w+ at [0-9a-fA-F]+/) {
3339 $commit_log_possible_stack_dump = 1;
3345 !($line =~ /^\s*[a-zA-Z0-9_\/\.]+\s+\|\s+\d+/ ||
3347 $line =~ /^\s*(?:[\w\.\-\+]*\/)++[\w\.\-\+]+:/ ||
3349 $line =~ /^\s*(?:Fixes:|https?:|$link_tags_search|$signature_tags)/i ||
3354 $commit_log_long_line = 1;
3359 $line =~ /^\s*$/) {
3365 $line =~ /^\s*(\w+:)\s*http/ && $1 !~ /^$link_tags_search$/) {
3366 if ($1 =~ /^v(?:ersion)?\d+/i) {
3371 "Unknown link reference '$1', use $link_tags_print instead\n" . $herecurr);
3377 $line =~ /^\s*(\w+:)\s*(\S+)/) {
3378 my $tag = $1;
3382 "'$tag' should be followed by a public http(s) link\n" . $herecurr);
3391 $fixed[$fixlinenr] =~ s/^/ /;
3404 # commit <SHA-1 hash length 12+ chars> ("Complete commit subject")
3407 # bare SHA-1 hash with minimum length of 5. It also avoids several types of
3408 # possible SHA-1 matches.
3413 $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink|base-commit):/i &&
3415 (($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i ||
3416 ($line =~ /\bcommit\s*$/i && defined($rawlines[$linenr]) && $rawlines[$linenr] =~ /^\s*[0-9a-f]{5,}\b/i)) ||
3417 ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i &&
3419 $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) {
3422 my $short = 1;
3424 my $case = 1;
3425 my $space = 1;
3434 if ($line =~ /(?:\bcommit\s+[0-9a-f]{5,}|\bcommit\s*$)/i) {
3436 if ($input =~ /\bcommit\s+[0-9a-f]{5,}\s*($balanced_parens)/i) {
3437 $orig_desc = $1;
3438 $has_parens = 1;
3440 $orig_desc = substr($orig_desc, 1, -1);
3442 $orig_desc = substr($orig_desc, 1, -1);
3443 $has_quotes = 1;
3454 if ($input =~ /\b(c)ommit\s+([0-9a-f]{5,})\b/i) {
3455 $init_char = $1;
3457 $short = 0 if ($input =~ /\bcommit\s+[0-9a-f]{12,40}/i);
3458 $long = 1 if ($input =~ /\bcommit\s+[0-9a-f]{41,}/i);
3460 $case = 0 if ($input =~ /\b[Cc]ommit\s+[0-9a-f]{5,40}[^A-F]/);
3462 $orig_commit = lc($1);
3470 $last_git_commit_id_linenr != $linenr - 1) {
3475 $last_git_commit_id_linenr = $linenr if ($line =~ /\bcommit\s*$/i);
3486 ($line =~ /^(?:new|deleted) file mode\s*\d+\s*$/ ||
3487 $line =~ /^rename (?:from|to) [\w\/\.\-]+\s*$/ ||
3488 ($line =~ /\{\s*([\w\/\.\-]*)\s*\=\>\s*([\w\/\.\-]*)\s*\}/ &&
3489 (defined($1) || defined($2))))) {
3490 $is_patch = 1;
3491 $reported_maintainer_file = 1;
3493 "added, moved or deleted file(s), does MAINTAINERS need updating?\n" . $herecurr);
3498 ($line =~ /^new file mode\s*\d+\s*$/) &&
3524 # Check if it's the start of a commit log
3527 !($rawline =~ /^\s+(?:\S|$)/ ||
3530 $in_commit_log = 1;
3531 $has_commit_log = 1;
3538 $1 !~ /utf-8/i) {
3539 $non_utf8_charset = 1;
3550 while ($line =~ m{(?:^|\s)(/\S*)}g) {
3551 my $file = $1;
3554 check_absolute_file($1, $herecurr)) {
3567 my $typo = $1;
3569 my $ptr = substr($blank, 0, $-[1]) . "^" x length($typo);
3579 $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
3585 if ($in_commit_log && $line =~ /(^fixes:|\bcommit)\s+([0-9a-f]{6,40})\b/i) {
3596 # avoid false positive from list command eg, '-rw-r--r-- 1 root root'
3599 pos($rawline) = 1 if (!$in_commit_log);
3602 my $first = $1;
3604 my $start_pos = $-[1];
3607 pos($rawline) += length($first) + length($second) + 1;
3617 $start_char = substr($rawline, $start_pos - 1, 1) if ($start_pos > ($in_commit_log ? 0 : 1));
3618 $end_char = substr($rawline, $end_pos, 1) if ($end_pos < length($rawline));
3620 next if ($start_char =~ /^\S$/);
3621 next if (index(" \t.,;?!", $end_char) == -1);
3631 $fixed[$fixlinenr] =~ s/\b$first $second\b/$first/;
3635 # if it's a repeated word on consecutive lines in a comment block
3636 if ($prevline =~ /$;+\s*$/ &&
3637 $prevrawline =~ /($word_pattern)\s*$/) {
3638 my $last_word = $1;
3639 if ($rawline =~ /^\+\s*\*\s*$last_word /) {
3643 $fixed[$fixlinenr] =~ s/(\+\s*\*\s*)$last_word /$1/;
3658 $fixed[$fixlinenr] =~ s/[\s\015]+$//;
3660 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
3665 $fixed[$fixlinenr] =~ s/\s+$//;
3668 $rpt_cleaners = 1;
3673 $rawline =~ /\b675\s+Mass\s+Ave/i ||
3674 $rawline =~ /\b59\s+Temple\s+Pl/i ||
3675 $rawline =~ /\b51\s+Franklin\s+St/i) {
3680 "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet)
3689 # (\b) rather than a whitespace character (\s)
3690 $line =~ /^\+\s*(?:config|menuconfig|choice)\b/) {
3701 if ($f =~ /^\+\s*(?:bool|tristate|prompt)\s*["']/) {
3702 $needs_help = 1;
3705 if ($f =~ /^\+\s*help\s*$/) {
3706 $has_help = 1;
3710 $f =~ s/^.//; # strip patch context [+ ]
3711 $f =~ s/#.*//; # strip # directives
3712 $f =~ s/^\s+//; # strip leading blanks
3728 my $stat_real = get_stat_real($linenr, $ln - 1);
3738 $rawline !~ /^\+[A-Z]:\t\S/) {
3742 $fixed[$fixlinenr] =~ s/^(\+[A-Z]):\s*/$1:\t/;
3749 $rawline =~ /^\+([A-Z]):\s*(.*)/;
3750 my $cur = $1;
3752 $prevrawline =~ /^[\+ ]([A-Z]):\s*(.*)/;
3753 my $prev = $1;
3776 (($realfile =~ /\.dtsi?$/ && $line =~ /^\+\s*compatible\s*=\s*\"/) ||
3777 ($realfile =~ /\.[ch]$/ && $line =~ /^\+.*\.compatible\s*=\s*\"/))) {
3789 next if $compat =~ /^usb(if)?[a-f0-9]{1,4},/;
3792 $compat2 =~ s/\,[a-zA-Z0-9]*\-/\,<\.\*>\-/;
3794 $compat3 =~ s/\,([a-z]*)[0-9]*\-/\,$1<\.\*>\-/;
3802 my $vendor = $1;
3813 $line =~ /^\+\s*(phy-mode|phy-connection-type)\s*=\s*"/ &&
3815 my $prop = $1;
3825 if ($rawline =~ /^[ \+]\s*\#\!\s*\//) {
3837 if ($realfile =~ /\.(h|s|S)$/) {
3849 $rawline !~ m@^\+\s*$pattern\s*@) {
3859 my $spdx_license = $1;
3872 $fixed[$fixlinenr] =~ s/SPDX-License-Identifier: .*/SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)/;
3876 $spdx_license !~ /GPL-2\.0(?:-only)? OR \S+/) {
3887 "It's generally not useful to have the filename in the file\n" . $herecurr);
3891 next if ($realfile !~ /\.(h|c|rs|s|S|sh|dtsi|dts)$/);
3932 if ($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(?:KERN_\S+\s*|[^"]*))?($String\s*(?:|,|\)\s*;)\s*)$/ &&
3933 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3938 } elsif ($line =~ /^\+\s*$String\s*(?:\s*|,|\)\s*;)\s*$/ ||
3939 $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) {
3943 } elsif ($line =~ /^\+.*\bEFI_GUID\s*\(/ ||
3944 $line =~ /^\+\s*(?:\w+)?\s*DEFINE_PER_CPU/) {
3948 } elsif ($rawline =~ /^\+.*\b[a-z][\w\.\+\-]*:\/\/\S+/i) {
3954 } elsif ($line =~ /($;[\s$;]*)$/ &&
3955 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3959 } elsif ($sline =~ /\s*($String(?:\s*(?:\\|,\s*|\)\s*;\s*))?)$/ &&
3960 length(expand_tabs(substr($line, 1, length($line) - length($1) - 1))) <= $max_line_length) {
3978 fix_delete_line($fixlinenr+1, "No newline at end of file");
3982 # check for .L prefix local symbols in .S files
3983 if ($realfile =~ /\.S$/ &&
3984 $line =~ /^\+\s*(?:[A-Z]+_)?SYM_[A-Z]+_(?:START|END)(?:_[A-Z_]+)?\s*\(\s*\.L/) {
3994 if ($rawline =~ /^\+\s* \t\s*\S/ ||
3995 $rawline =~ /^\+\s* \s*/) {
3997 $rpt_cleaners = 1;
4001 $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
4012 s/(^\+.*) {$tabsize,$tabsize}\t/$1\t\t/) {}
4014 s/(^\+.*) +\t/$1\t/) {}
4019 if ($sline =~ /^\+\s+($Assignment)[^=]/) {
4020 my $operator = $1;
4022 "Assignment operator '$1' should be on the previous line\n" . $hereprev) &&
4025 $fixed[$fixlinenr - 1] .= " $operator";
4026 $fixed[$fixlinenr] =~ s/\Q$operator\E\s*//;
4031 if ($rawline =~ /^\+\s*(&&|\|\|)/) {
4032 my $operator = $1;
4037 $prevline =~ /[\s$;]*$/;
4039 $fixed[$fixlinenr - 1] =~ s/\Q$line_end\E$/ $operator$line_end/;
4040 $fixed[$fixlinenr] =~ s/\Q$operator\E\s*//;
4046 $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;=])/) {
4047 my $indent = length($1);
4052 $fixed[$fixlinenr] =~ s@(^\+\t+) +@$1 . "\t" x ($indent/$tabsize)@e;
4059 $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|(?:\*\s*)*$Lval\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) {
4061 my $oldindent = $1;
4081 s/^\+[ \t]*/\+$goodtabindent/;
4094 if ($line =~ /^\+(.*)\(\s*$Type\s*\)([ \t]++)((?![={]|\\$|$Attribute|__attribute__))/ &&
4095 (!defined($1) || $1 !~ /\b(?:sizeof|__alignof__)\s*$/)) {
4100 s/(\(\s*$Type\s*\))[ \t]+/$1/;
4132 if (defined($1)) {
4133 $oldindent = expand_tabs($1);
4136 $oldindent = expand_tabs($1);
4139 my $newindent = $1;
4149 if ($prevline =~ /^[\+ ]};?\s*$/ &&
4151 !($line =~ /^\+\s*$/ ||
4152 $line =~ /^\+\s*(?:EXPORT_SYMBOL|early_param|ALLOW_ERROR_INJECTION)/ ||
4153 $line =~ /^\+\s*MODULE_/i ||
4154 $line =~ /^\+\s*\#\s*(?:end|elif|else)/ ||
4156 $line =~ /^\+\s*(?:static\s+)?[A-Z_]*ATTR/ ||
4157 $line =~ /^\+\s*DECLARE/ ||
4158 $line =~ /^\+\s*NOKPROBE_SYMBOL/ ||
4159 $line =~ /^\+\s*builtin_[\w_]*driver/ ||
4160 $line =~ /^\+\s*__setup/)) {
4169 if ($prevline =~ /^[\+ ]\s*$/ &&
4170 $line =~ /^\+\s*$/ &&
4171 $last_blank_line != ($linenr - 1)) {
4183 if (($prevline =~ /\+(\s+)\S/) && $sline =~ /^\+$1\S/) {
4188 $sl =~ s/\b(?:$Attribute|$Sparse)\b//g;
4189 $pl =~ s/\b(?:$Attribute|$Sparse)\b//g;
4190 if (($pl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
4192 $pl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident(?:\s*\[\s*(?:$Ident|$Constant)?\s*\])?\s*\)\s*[=,;:\[\(]/ ||
4194 $pl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
4196 $pl =~ /^\+\s+$declaration_macros/) &&
4198 !($pl =~ /^\+\s+$c90_Keywords\b/ ||
4200 $pl =~ /(?:$Compare|$Assignment|$Operators)\s*$/ ||
4202 $pl =~ /(?:\{\s*|\\)$/) &&
4204 !($sl =~ /^\+\s+$Declare\s*$Ident\s*[=,;:\[]/ ||
4206 $sl =~ /^\+\s+$Declare\s*\(\s*\*\s*$Ident(?:\s*\[\s*(?:$Ident|$Constant)?\s*\])?\s*\)\s*[=,;:\[\(]/ ||
4208 $sl =~ /^\+\s+$Ident(?:\s+|\s*\*\s*)$Ident\s*[=,;\[]/ ||
4210 $sl =~ /^\+\s+$declaration_macros/ ||
4212 $sl =~ /^\+\s+(?:static\s+)?(?:const\s+)?(?:union|struct|enum|typedef)\b/ ||
4214 $sl =~ /^\+\s+(?:$|[\{\}\.\#\"\?\:\(\[])/ ||
4216 $sl =~ /^\+\s+$Ident\s*:\s*\d+\s*[,;]/ ||
4218 $sl =~ /^\+\s+\(?\s*(?:$Compare|$Assignment|$Operators)/)) {
4229 # 1) within comments
4237 $fixed[$fixlinenr] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
4245 if ($line =~ /^\+.*([\[\(])\s*$/) {
4247 "Lines should not end with a '$1'\n" . $herecurr);
4251 if ($sline =~ /^\+\{\s*$/ &&
4252 $prevline =~ /^\+(?:(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*)?($Ident)\(/) {
4253 $context_function = $1;
4257 if ($sline =~ /^\+\}\s*$/) {
4263 # if the previous line is a break or return and is indented 1 tab more...
4264 if ($sline =~ /^\+([\t]+)(?:}[ \t]*)?else(?:[ \t]*{)?\s*$/) {
4265 my $tabs = length($1) + 1;
4278 if ($sline =~ /^\+([\t]+)break\s*;\s*$/) {
4279 my $tabs = $1;
4282 "break is not useful after a $1\n" . $hereprev) &&
4298 "Using $1 is unnecessary\n" . $herecurr);
4306 $realcnt && $sline =~ /.\s*\S/) {
4309 $stat =~ s/\n./\n /g;
4310 $cond =~ s/\n./\n /g;
4316 my $frag = $stat; $frag =~ s/;+\s*$//;
4325 (!defined $lines[$realline_next - 1] ||
4326 substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
4330 my $s = $stat;
4331 $s =~ s/{.*$//s;
4334 if ($s =~ /$Ident:\*$/s) {
4337 } elsif ($s =~ /^.\s*$Ident\s*\(/s) {
4339 } elsif ($s =~ /^.\s*else\b/s) {
4342 } elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+?)\b(?:\s+$Sparse)?\s*\**\s*(?:$Ident|\(\*[^\)]*\))(?:\s*$Modifier)?\s*(?:;|=|,|\()/s) {
4343 my $type = $1;
4344 $type =~ s/\s+/ /g;
4345 possible($type, "A:" . $s);
4348 } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {
4349 possible($1, "B:" . $s);
4353 while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
4354 possible($1, "C:" . $s);
4360 if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) {
4361 my ($name_len) = length($1);
4363 my $ctx = $s;
4364 substr($ctx, 0, $name_len + 1, '');
4365 $ctx =~ s/\)[^\)]*$//;
4367 for my $arg (split(/\s*,\s*/, $ctx)) {
4368 if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) {
4370 possible($1, "D:" . $s);
4383 if ($line=~/\bswitch\s*\(.*\)/) {
4390 if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
4406 if ($line =~ /(.*)\b((?:if|while|for|switch|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
4407 my $pre_ctx = "$1$2";
4416 my $ctx_cnt = $realcnt - $#ctx - 1;
4423 defined $lines[$ctx_ln - 1] &&
4424 $lines[$ctx_ln - 1] =~ /^-/)) {
4426 $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
4431 #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
4433 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
4436 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
4438 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
4439 $ctx =~ /\)\s*\;\s*$/ &&
4440 defined $lines[$ctx_ln - 1])
4442 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
4446 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
4452 if ($line =~ /\b(?:(?:if|while|for|(?:[a-z_]+|)for_each[a-z_]+)\s*\(|(?:do|else)\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
4456 my ($s, $c) = ($stat, $cond);
4458 substr($s, 0, length($c), '');
4461 $s =~ s/$;/ /g;
4462 $c =~ s/$;/ /g;
4466 my $cond_lines = 1 + $#newlines;
4471 $s =~ s/\n./\n/gs;
4472 while ($s =~ /\n\s+\\\n/) {
4473 $cond_lines += $s =~ s/\n\s+\\\n/\n/g;
4478 # 1) any blank line termination
4483 $s =~ s/^.*\bdo\b//;
4484 $s =~ s/^\s*{//;
4485 if ($s =~ s/^\s*\\//) {
4486 $continuation = 1;
4488 if ($s =~ s/^\s*?\n//) {
4489 $check = 1;
4495 if (($prevline =~ /^.\s*#\s*define\s/ ||
4496 $prevline =~ /\\\s*$/) && $continuation == 0) {
4500 my $cond_ptr = -1;
4507 if ($s =~ /^\s*\#\s*(?:else|elif)/) {
4512 # 1) blank lines, they should be at 0,
4516 $s =~ /^\s*?\n/ ||
4517 $s =~ /^\s*#\s*?/ ||
4518 $s =~ /^\s*$Ident\s*:/) {
4519 $continuation = ($s =~ /^.*?\\\n/) ? 1 : 0;
4520 if ($s =~ s/^.*?\n//) {
4526 my (undef, $sindent) = line_stats("+" . $s);
4530 # this is not this patch's fault.
4535 if (defined($stat_real) && $cond_lines > 1) {
4539 #print "line<$line> prevline<$prevline> indent<$indent> sindent<$sindent> check<$check> continuation<$continuation> s<$s> cond_lines<$cond_lines> stat_real<$stat_real> stat<$stat>\n";
4541 if ($check && $s ne '' &&
4545 ($s !~ /^\s*(?:\}|\{|else\b)/)) ||
4553 my $opline = $line; $opline =~ s/^./ /;
4558 my $outline = $opline; $outline =~ s/\t/ /g;
4563 $prev_values = substr($curr_values, -1);
4571 if ($line =~ /^\+\s*(?:$Declare)?([A-Za-z_][A-Za-z\d_]*)\s*=/) {
4572 my $var = $1;
4573 if ($line =~ /^\+\s*(?:$Declare)?$var\s*=\s*(?:$var|\*\s*\(?\s*&\s*\(?\s*$var\s*\)?\s*\)?)\s*[;,]/) {
4580 if ($prevline =~ /^\+.*$Lval\s*(?:\.|->)\s*$/ &&
4581 $line =~ /^\+\s*(?!\#\s*(?!define\s+|if))\s*$Lval/) {
4582 $prevline =~ /($Lval\s*(?:\.|->))\s*$/;
4583 my $ref = $1;
4584 $line =~ /^.\s*($Lval)/;
4585 $ref .= $1;
4586 $ref =~ s/\s//g;
4592 while ($line =~ m{\b($Declare)\s*(?!char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) {
4593 my $type = $1;
4596 if ($type =~ /^(?:(?:$Storage|$Inline|$Attribute)\s+)*((?:un)?signed)((?:\s*\*)*)\s*$/) {
4597 my $sign = $1;
4607 $comp_pointer =~ s/\s//g;
4610 $fixed[$fixlinenr] =~ s@\b$sign\s*\Q$pointer\E\s*$var\b@$decl$var@;
4617 if ($line =~ /^.\s*$Declare\s*$/) {
4620 } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) {
4622 "TEST: is not type ($1 is)\n". $herecurr);
4628 if ($line =~ /^.\s*$Modifier\s*$/) {
4631 } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) {
4633 "TEST: is not attr ($1 is)\n". $herecurr);
4639 if ($line =~ /^.\s*{/ &&
4640 $prevline =~ /(?:^|[^=])=\s*$/) {
4644 fix_delete_line($fixlinenr - 1, $prevrawline);
4647 $fixedline =~ s/\s*=\s*$/ = {/;
4650 $fixedline =~ s/^(.\s*)\{\s*/$1/;
4660 if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
4661 my $path = $1;
4679 my $comment = trim($1);
4680 $fixed[$fixlinenr] =~ s@\/\/(.*)$@/\* $comment \*/@;
4685 $line =~ s@//.*@@;
4686 $opline =~ s@//.*@@;
4690 #print "APW <$lines[$realline_next - 1]>\n";
4692 exists $lines[$realline_next - 1] &&
4694 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/)) {
4699 my $name = $1;
4700 $name =~ s/^\s*($Ident).*/$1/;
4701 if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
4704 $suppress_export{$realline_next} = 1;
4707 \n.}\s*$|
4711 ^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(|
4712 \b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\()
4714 #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
4717 $suppress_export{$realline_next} = 1;
4721 $prevline =~ /^.\s*$/ &&
4723 #print "FOO B <$lines[$linenr - 1]>\n";
4733 if ($line =~ /^\+$Type\s*$Ident(?:\s+$Modifier)*\s*=\s*($zero_initializer)\s*;/ &&
4736 "do not initialise globals to $1\n" . $herecurr) &&
4738 $fixed[$fixlinenr] =~ s/(^.$Type\s*$Ident(?:\s+$Modifier)*)\s*=\s*$zero_initializer\s*;/$1;/;
4742 if ($line =~ /^\+.*\bstatic\s.*=\s*($zero_initializer)\s*;/) {
4744 "do not initialise statics to $1\n" .
4747 $fixed[$fixlinenr] =~ s/(\bstatic\s.*?)\s*=\s*$zero_initializer\s*;/$1;/;
4753 my $tmp = trim($1);
4759 while ($sline =~ m{\b($TypeMisordered(\s*\*)*|$C90_int_types)\b}g) {
4760 my $type = trim($1);
4762 next if ($type !~ /\b(?:short|long\s+long|long)\b/);
4764 $new_type =~ s/\b\s*int\s*\b/ /;
4765 $new_type =~ s/\b\s*(?:un)?signed\b\s*/ /;
4766 $new_type =~ s/^const\s+//;
4769 $new_type =~ s/\s+/ /g;
4774 $fixed[$fixlinenr] =~ s/\b\Q$type\E\b/$new_type/;
4779 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
4786 if ($line =~ /^\+\s*const\s+(char|unsigned\s+char|_*u8|(?:[us]_)?int8_t)\s+\w+\s*\[\s*(?:\w+\s*)?\]\s*=\s*"/) {
4790 $fixed[$fixlinenr] =~ s/(^.\s*)const\b/${1}static const/;
4795 if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
4802 if ($sline =~ /\bconst\s+($BasicType)\s+const\b/) {
4803 my $found = $1;
4804 if ($sline =~ /\bconst\s+\Q$found\E\s+const\b\s*\*/) {
4807 } elsif ($sline !~ /\bconst\s+\Q$found\E\s+const\s+\w+\s*\[/) {
4815 if ($sline =~ /^\+\s*const\s+static\s+($Type)\b/ ||
4816 $sline =~ /^\+\s*static\s+($BasicType)\s+const\b/) {
4818 "Move const after static - use 'static const $1'\n" . $herecurr) &&
4820 $fixed[$fixlinenr] =~ s/\bconst\s+static\b/static const/;
4821 $fixed[$fixlinenr] =~ s/\bstatic\s+($BasicType)\s+const\b/static const $1/;
4826 if ($line =~ /^.\s+(?:static\s+|const\s+)?char\s+\*\s*\w+\s*\[\s*\]\s*=\s*\{/) {
4833 if ($line =~ m@\bsizeof\s*\(\s*($Lval)\s*\)@) {
4834 my $array = $1;
4835 if ($line =~ m@\b(sizeof\s*\(\s*\Q$array\E\s*\)\s*/\s*sizeof\s*\(\s*\Q$array\E\s*\[\s*0\s*\]\s*\))@) {
4836 my $array_div = $1;
4840 $fixed[$fixlinenr] =~ s/\Q$array_div\E/ARRAY_SIZE($array)/;
4846 if ($line =~ /(\b$Type\s*$Ident)\s*\(\s*\)/) {
4848 "Bad function definition - $1() should probably be $1(void)\n" . $herecurr) &&
4850 $fixed[$fixlinenr] =~ s/(\b($Type)\s+($Ident))\s*\(\s*\)/$2 $3(void)/;
4856 if ($line =~ /\btypedef\s/ &&
4857 $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
4858 $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
4867 while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
4868 #print "AA<$1>\n";
4869 my ($ident, $from, $to) = ($1, $2, $2);
4872 $to =~ s/^(\S)/ $1/;
4874 $to =~ s/\s+$//;
4875 # '*'s should not have spaces between.
4876 while ($to =~ s/\*\s+\*/\*\*/) {
4879 ## print "1: from<$from> to<$to> ident<$ident>\n";
4886 $sub_to =~ s/\Q$from\E/$to/;
4888 s@\Q$sub_from\E@$sub_to@;
4892 while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) {
4893 #print "BB<$1>\n";
4894 my ($match, $from, $to, $ident) = ($1, $2, $2, $3);
4897 $to =~ s/^(\S)/ $1/;
4899 $to =~ s/\s+$//;
4900 # '*'s should not have spaces between.
4901 while ($to =~ s/\*\s+\*/\*\*/) {
4904 $to =~ s/(\b$Modifier$)/$1 /;
4914 $sub_to =~ s/\Q$from\E/$to/;
4916 s@\Q$sub_from\E@$sub_to@;
4922 if ($line =~ /\b(?!AA_|BUILD_|IDA_|KVM_|RWLOCK_|snd_|SPIN_)(?:[a-zA-Z_]*_)?BUG(?:_ON)?(?:_[A-Z_]+)?\s*\(/) {
4936 if ($line =~ /\bprintk_ratelimit\s*\(/) {
4942 if ($line =~ /\bprintk\s*\(\s*(?!KERN_[A-Z]+\b)/) {
4948 if ($line =~ /\b(printk(_once|_ratelimited)?)\s*\(\s*KERN_([A-Z]+)/) {
4949 my $printk = $1;
4964 if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
4965 my $orig = $1;
4974 if ($line =~ /\b(trace_printk|trace_puts|ftrace_vprintk)\s*\(/) {
4976 "Do not use $1() in production code (this can be ignored if built only with a debug config option)\n" . $herecurr);
4994 $fixed[$fixlinenr] =~ s/\bENOTSUPP\b/EOPNOTSUPP/;
5001 $sline =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ &&
5002 $sline !~ /\#\s*define\b.*do\s*\{/ &&
5009 $fixed_line =~ /(^..*$Type\s*$Ident\(.*\)\s*)\{(.*)$/;
5010 my $line1 = $1;
5014 if ($line2 !~ /^\s*$/) {
5021 if ($line =~ /^.\s*{/ &&
5022 $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
5024 "open brace '{' following $1 go on the same line\n" . $hereprev) &&
5026 fix_delete_line($fixlinenr - 1, $prevrawline);
5031 $fixedline =~ s/^(.\s*)\{\s*/$1\t/;
5032 if ($fixedline !~ /^\+\s*$/) {
5039 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident){1,2}[=\{]/) {
5041 "missing space after $1 definition\n" . $herecurr) &&
5044 s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/;
5051 if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)($Ident)(\s*)\)(\s*)\(/) {
5052 my $declare = $1;
5063 if ($declare =~ /(\s+)$/) {
5064 $post_declare_space = $1;
5079 # elsif ($declare =~ /\s{2,}$/) {
5086 $pre_pointer_space =~ /^\s/) {
5093 $post_pointer_space =~ /^\s/) {
5100 $post_funcname_space =~ /^\s/) {
5107 $pre_args_space =~ /^\s/) {
5114 s/^(.\s*)$Declare\s*\(\s*\*\s*$Ident\s*\)\s*\(/$1 . $declare . $post_declare_space . '(*' . $funcname . ')('/ex;
5119 # 1. with a type on the left -- int [] a;
5122 while ($line =~ /(.*?\s)\[/g) {
5123 my ($where, $prefix) = ($-[1], $1);
5124 if ($prefix !~ /$Type\s+$/ &&
5125 ($where != 0 || $prefix !~ /^.\s+$/) &&
5126 $prefix !~ /[{,:]\s+$/) {
5131 s/^(\+.*?)\s+\[/$1\[/;
5137 while ($line =~ /($Ident)\s+\(/g) {
5138 my $name = $1;
5139 my $ctx_before = substr($line, 0, $-[1]);
5152 } elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) {
5155 } elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) {
5166 s/\b$name\s+\(/$name\(/;
5172 if (!($line=~/\#\s*include/)) {
5201 my $last_after = -1;
5205 my $good = $fix_elements[$n] . $fix_elements[$n + 1];
5214 if (length($opline) >= ($off + length($elements[$n + 1]))) {
5215 $cc = substr($opline, $off + length($elements[$n + 1]));
5221 $a = 'W' if ($elements[$n] =~ /\s$/);
5225 $a = 'E' if ($ca =~ /^\s*$/);
5227 my $op = $elements[$n + 1];
5232 $c = 'W' if ($elements[$n + 2] =~ /^\s/);
5236 $c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/);
5249 my $op_type = substr($curr_values, $off + 1, 1);
5252 my $opv = $op . substr($curr_vars, $off, 1);
5256 $ca =~ /\s$/ && $cc =~ /^\s*[,\)]/) {
5267 $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
5268 $line_fixed = 1;
5285 $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
5287 $fix_elements[$n + 2] =~ s/^\s+//;
5289 $line_fixed = 1;
5300 $line_fixed = 1;
5301 $rtrim_before = 1;
5307 $line_fixed = 1;
5309 $space_after = 1;
5314 $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
5316 $good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
5337 $good = $fix_elements[$n] . " " . ltrim($fix_elements[$n + 1]);
5338 $line_fixed = 1;
5342 if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
5348 $good = $fix_elements[$n] . rtrim($fix_elements[$n + 1]);
5350 $fix_elements[$n + 2] =~ s/^\s+//;
5352 $line_fixed = 1;
5361 $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
5362 $line_fixed = 1;
5369 $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
5370 $line_fixed = 1;
5376 $good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
5378 $fix_elements[$n + 2] =~ s/^\s+//;
5380 $line_fixed = 1;
5395 $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
5396 $fix_elements[$n + 2] =~ s/^\s+//;
5397 $line_fixed = 1;
5402 $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]);
5403 $line_fixed = 1;
5409 $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
5411 $fix_elements[$n + 2] =~ s/^\s+//;
5413 $line_fixed = 1;
5423 $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
5424 $line_fixed = 1;
5434 $cc =~ /^\S+\@\S+>/) ||
5436 $ca =~ /<\S+\@\S+$/))
5438 $ok = 1;
5446 $ok = 1;
5456 $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
5458 $fix_elements[$n + 2] =~ s/^\s+//;
5460 $line_fixed = 1;
5464 $off += length($elements[$n + 1]);
5483 if ($line =~ /^\+.*\S\s+;\s*$/) {
5487 1 while $fixed[$fixlinenr] =~
5488 s/^(\+.*\S)\s+;/$1;/;
5493 if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
5500 ## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
5501 ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
5506 ## while ($ln =~ s/\([^\(\)]*\)//g) {
5520 $fixed[$fixlinenr] =~ s/^(\+.*(?:do|else|\)))\{/$1 {/;
5525 ## if ($line =~ /^.\t+$Type\s+$Ident(?:\s*=.*)?;/ &&
5526 ## $prevrawline =~ /^.\s*$/) {
5534 if ($line =~ /}(?!(?:,|;|\)|\}))\S/) {
5539 s/}((?!(?:,|;|\)))\S)/} $1/;
5544 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
5549 s/\[\s+/\[/;
5552 if ($line =~ /\s\]/) {
5557 s/\s+\]/\]/;
5562 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
5563 $line !~ /for\s*\(\s+;/) {
5568 s/\(\s+/\(/;
5571 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
5572 $line !~ /for\s*\(.*;\s+\)/ &&
5573 $line !~ /:\s+\)/) {
5578 s/\s+\)/\)/;
5585 while ($line =~ /(?:[^&]&\s*|\*)\(\s*($Ident\s*(?:$Member\s*)+)\s*\)/g) {
5586 my $var = $1;
5590 $fixed[$fixlinenr] =~ s/\(\s*\Q$var\E\s*\)/$var/;
5597 if ($line =~ /(\bif\s*|)(\(\s*$Ident\s*(?:$Member\s*)+\))[ \t]*\(/ && $1 !~ /^if/) {
5603 $var2 =~ s/\s//g;
5604 $fixed[$fixlinenr] =~ s/\Q$var\E/$var2/;
5612 $stat =~ /(^.\s*if\s*($balanced_parens))/) {
5613 my $if_stat = $1;
5614 my $test = substr($2, 1, -1);
5616 while ($test =~ /(?:^|[^\w\&\!\~])+\s*\(\s*([\&\!\~]?\s*$Lval\s*(?:$Compare\s*$FuncArg)?)\s*\)/g) {
5617 my $match = $1;
5619 next if ($match =~ /^\s*\w+\s*$/);
5635 # and ignore bitfield definitions like foo:1
5638 if ($sline =~ /^.\s+[A-Za-z_][A-Za-z\d_]*:(?!\s*\d+)/ &&
5640 $sline !~ /^.\s+default:/) {
5645 s/^(.)\s+/$1/;
5653 $stat =~ /^\+\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*,\s*(?:$Lval\s*$Assignment\s*)?$FuncArg\s*;\s*$/) {
5661 if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
5662 my $spacing = $1;
5664 $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) {
5665 my $value = $1;
5667 if ($value =~ m/^\s*$FuncArg\s*(?:\?|$)/) {
5671 } elsif ($spacing !~ /\s+/) {
5680 if ($sline =~ /^[ \+]}\s*$/ &&
5681 $prevline =~ /^\+\treturn\s*;\s*$/ &&
5684 $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
5691 $line =~ /\bif\s*((?:\(\s*){2,})/) {
5692 my $openparens = $1;
5695 if ($line =~ /\bif\s*(?:\(\s*){$count,$count}$LvalOrFunc\s*($Compare)\s*$LvalOrFunc(?:\s*\)){$count,$count}/) {
5696 my $comp = $4; #Not $1 because of $LvalOrFunc
5708 $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
5709 my $lead = $1;
5714 if ($lead !~ /(?:$Operators|\.)\s*$/ &&
5728 $fixed[$fixlinenr] =~ s/\(\s*\Q$const\E\s*$Compare\s*\Q$to\E\s*\)/($to $newcomp $const)/;
5733 if ($sline =~ /\breturn(?:\s*\(+\s*|\s+)(E[A-Z]+)(?:\s*\)+\s*|\s*)[;:,]/) {
5734 my $name = $1;
5737 "return of an errno should typically be negative (ie: return -$1)\n" . $herecurr);
5747 s/\b(if|while|for|switch)\(/$1 \(/;
5753 if ($line =~ /do\s*(?!{)/) {
5759 $stat_next =~ s/\n./\n /g;
5762 if ($stat_next =~ /^\s*while\b/) {
5766 ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
5768 statement_rawlines($whitespace) - 1;
5771 $offset} = 1;
5776 $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
5777 my ($s, $c) = ($stat, $cond);
5780 if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
5784 if ($rawline =~ /^\+(\s+)if\s*\(\s*(\!)?\s*\(\s*(($Lval)\s*=\s*$LvalOrFunc)\s*\)\s*(?:($Compare)\s*($FuncArg))?\s*\)\s*(\{)?\s*$/) {
5785 my $space = $1;
5802 fix_insert_line($fixlinenr + 1, $newline);
5803 $fixed_assign_in_if = 1;
5810 substr($s, 0, length($c), '');
5811 $s =~ s/\n.*//g;
5812 $s =~ s/$;//g; # Remove any comments
5813 if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
5814 $c !~ /}\s*while\s*/)
5818 my $cond_lines = 1 + $#newlines;
5823 if (defined($stat_real) && $cond_lines > 1) {
5832 $fixed[$fixlinenr] =~ /^\+(\s*)((?:if|while|for)\s*$balanced_parens)\s*(.*)$/) {
5833 my $indent = $1;
5838 fix_insert_line($fixlinenr + 1, "$indent\t$rest");
5848 \s*0[xX][0-9]+\s*
5852 \s*0[xX][0-9]+\s*
5857 "boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
5861 if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
5862 my $s = $1;
5863 $s =~ s/$;//g; # Remove any comments
5864 if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
5870 if ($line =~ /}\s*if\b/) {
5876 if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
5878 (?:\s*$;*)(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
5879 \s*return\s+
5888 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ &&
5893 fix_delete_line($fixlinenr - 1, $prevrawline);
5896 $fixedline =~ s/}\s*$//;
5897 if ($fixedline !~ /^\+\s*$/) {
5901 $fixedline =~ s/^(.\s*)else/$1} else/;
5906 if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ &&
5908 my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
5912 substr($s, 0, length($c), '');
5913 $s =~ s/\n.*//g;
5915 if ($s =~ /^\s*;/) {
5919 fix_delete_line($fixlinenr - 1, $prevrawline);
5923 $trailing =~ s/^\+//;
5925 $fixedline =~ s/}\s*$/} $trailing/;
5933 my $var = $1;
5941 $var !~ /^(?:[A-Z]+_){1,5}[A-Z]{1,3}[a-z]/ &&
5952 my $word = $1;
5958 $camelcase_file_seeded = 1;
5962 $camelcase{$word} = 1;
5971 if ($line =~ /\#\s*define.*\\\s+$/) {
5975 $fixed[$fixlinenr] =~ s/\s+$//;
5981 if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
5982 my $file = "$1.h";
5986 $1 !~ /$allowed_asm_includes/)
5988 my $asminclude = `grep -Ec "#include\\s+<asm/$file>" $root/$checkfile`;
6005 $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) {
6016 #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
6018 $has_flow_statement = 1 if ($ctx =~ /\b(goto|return)\b/);
6019 $has_arg_concat = 1 if ($ctx =~ /\#\#/ && $ctx !~ /\#\#\s*(?:__VA_ARGS__|args)\b/);
6021 $dstat =~ s/^.\s*\#\s*define\s+$Ident(\([^\)]*\))?\s*//;
6022 my $define_args = $1;
6027 $define_args = substr($define_args, 1, length($define_args) - 2);
6028 $define_args =~ s/\s*//g;
6029 $define_args =~ s/\\\+?//g;
6033 $dstat =~ s/$;//g;
6034 $dstat =~ s/\\\n.//g;
6035 $dstat =~ s/^\s*//s;
6036 $dstat =~ s/\s*$//s;
6039 while ($dstat =~ s/\([^\(\)]*\)/1u/ ||
6040 $dstat =~ s/\{[^\{\}]*\}/1u/ ||
6041 $dstat =~ s/.\[[^\[\]]*\]/1u/)
6046 while ($dstat =~ s/($String)\s*$Ident/$1/ ||
6047 $dstat =~ s/$Ident\s*($String)/$1/)
6052 $dstat =~ s/\b_*asm_*\s+_*volatile_*\b/asm_volatile/g;
6066 \.$Ident\s*=\s*|
6072 $ctx =~ s/\n*$//;
6082 $dstat !~ /^\.$Ident\s*=/ && # .foo =
6083 $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ && # stringification #foo
6085 $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...)
6086 $dstat !~ /^while\s*$Constant\s*$Constant\s*$/ && # while (...) {...}
6087 $dstat !~ /^for\s*$Constant$/ && # for (...)
6088 $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
6089 $dstat !~ /^do\s*{/ && # do {...
6091 $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/)
6093 if ($dstat =~ /^\s*if\b/) {
6108 my $first = 1;
6111 $l =~ s/\\$//;
6116 $define_stmt .= substr($l, 1);
6119 $define_stmt =~ s/$;//g;
6120 $define_stmt =~ s/\s+/ /g;
6128 $tmp_stmt =~ s/\b(__must_be_array|offsetof|sizeof|sizeof_field|__stringify|typeof|__typeof__|__builtin\w+|typecheck\s*\(\s*$Type\s*,|\#+)\s*\(*\s*$arg\s*\)*\b//g;
6129 $tmp_stmt =~ s/\#+\s*$arg\b//g;
6130 $tmp_stmt =~ s/\b$arg\s*\#\#//g;
6132 if ($use_cnt > 1) {
6137 if ($tmp_stmt =~ m/($Operators)?\s*\b$arg\b\s*($Operators)?/m &&
6138 ((defined($1) && $1 ne ',') ||
6164 $line =~ s/(\w+)/$maybe_linker_symbol{$1}++/ge;
6168 $line !~ /^\+\s*\#.*\\$/ && # preprocessor
6181 $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) {
6190 $dstat =~ s/\\\n.//g;
6191 $dstat =~ s/$;/ /g;
6193 if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*\)\s*([;\s]*)\s*$/) {
6197 $ctx =~ s/\n*$//;
6201 if (($stmts =~ tr/;/;/) == 1 &&
6202 $stmts !~ /^\s*(if|while|for|switch)\b/) {
6210 } elsif ($dstat =~ /^\+\s*#\s*define\s+$Ident.*;\s*$/) {
6211 $ctx =~ s/\n*$//;
6221 if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
6223 ctx_statement_full($linenr, $realcnt, 1);
6225 #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
6231 my $ln = $linenr - 1;
6236 my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
6237 my $offset = statement_rawlines($whitespace) - 1;
6243 $suppress_ifbraces{$ln + $offset} = 1;
6246 $ln += statement_rawlines($block) - 1;
6250 $seen++ if ($block =~ /^\s*{/);
6253 if (statement_lines($cond) > 1) {
6255 $allowed[$allow] = 1;
6259 $allowed[$allow] = 1;
6261 if (statement_block_size($block) > 1) {
6263 $allowed[$allow] = 1;
6283 if (!defined $suppress_ifbraces{$linenr - 1} &&
6288 if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
6289 #print "APW: ALLOWED: pre<$1>\n";
6290 $allowed = 1;
6302 if (statement_lines($cond) > 1) {
6304 $allowed = 1;
6308 $allowed = 1;
6310 if (statement_block_size($block) > 1) {
6312 $allowed = 1;
6315 if (defined $chunks[1]) {
6316 my ($cond, $block) = @{$chunks[1]};
6320 if ($block =~ /^\s*\{/) {
6321 #print "APW: ALLOWED: chunk-1 block<$block>\n";
6322 $allowed = 1;
6325 if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
6335 if ($sline =~ /^.\s*\}\s*else\s*$/ ||
6336 $sline =~ /^.\s*else\s*\{\s*$/) {
6341 if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
6345 fix_delete_line($fixlinenr - 1, $prevrawline);
6348 if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
6357 my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
6367 if ($line =~ /^\+\s*$String/ &&
6368 $prevline =~ /"\s*$/ &&
6369 $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) {
6373 $prevrawline =~ /^\+.*"\s*$/ &&
6374 $last_coalesced_string_linenr != $linenr - 1) {
6377 if ($rawline =~ /\Q$extracted_string\E(\s*\)\s*;\s*$|\s*,\s*)/) {
6378 $comma_close = $1;
6381 fix_delete_line($fixlinenr - 1, $prevrawline);
6384 $fixedline =~ s/"\s*$//;
6385 $fixedline .= substr($extracted_string, 1) . trim($comma_close);
6386 fix_insert_line($fixlinenr - 1, $fixedline);
6388 $fixedline =~ s/\Q$extracted_string\E\Q$comma_close\E//;
6389 if ($fixedline !~ /\+\s*$/) {
6411 "Prefer using '\"%s...\", __func__' to using '$context_function', this function's name, in a string\n" . $herecurr);
6416 # 'dprintk(FOO, "%s()\n", __func__);' which do not match $logFunctions
6417 if ($rawline =~ /^\+.*\([^"]*"$tracing_logging_tags{0,3}%s(?:\s*\(\s*\)\s*)?$tracing_logging_tags{0,3}(?:\\n)?"\s*,\s*__func__\s*\)\s*;/) {
6426 if ($rawline =~ /^.*\".*\s\\n/) {
6430 $fixed[$fixlinenr] =~ s/^(\+.*\".*)\s+\\n/$1\\n/;
6437 ($line =~ /([A-Za-z0-9_]+)$String/ && $1 !~ /^[Lu]$/)) {
6443 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E([A-Za-z0-9_])/$extracted_string $1/;
6444 $fixed[$fixlinenr] =~ s/([A-Za-z0-9_])\Q$extracted_string\E/$1 $extracted_string/;
6450 if ($line =~ /$String\s*[Lu]?"/) {
6454 while ($line =~ /($String)(?=\s*")/g) {
6456 $fixed[$fixlinenr] =~ s/\Q$extracted_string\E\s*"/substr($extracted_string, 0, -1)/e;
6462 my $show_L = 1; #don't show the same defect twice
6463 my $show_Z = 1;
6465 my $string = substr($rawline, $-[1], $+[1] - $-[1]);
6466 $string =~ s/%%/__/g;
6470 "\%L$1 is non-standard C, use %ll$1\n" . $herecurr);
6476 "%Z$1 is non-standard C, use %z$1\n" . $herecurr);
6493 if ($line =~ /^.\s*\#\s*if\s+0\b/) {
6498 # warn about #if 1
6499 if ($line =~ /^.\s*\#\s*if\s+1\b/) {
6501 "Consider removing the #if 1 and its #endif\n" . $herecurr);
6505 if ($prevline =~ /\bif\s*\(\s*($Lval)\s*\)/) {
6506 my $tested = quotemeta($1);
6507 my $expr = '\s*\(\s*' . $tested . '\s*\)\s*;';
6509 my $func = $1;
6513 my $do_fix = 1;
6516 if ($lines[$linenr - 2] =~ /^\+(\t*)if\s*\(\s*$tested\s*\)\s*$/) {
6517 $leading_tabs = $1;
6521 if ($lines[$linenr - 1] =~ /^\+(\t+)$func\s*\(\s*$tested\s*\)\s*;\s*$/) {
6522 $new_leading_tabs = $1;
6523 if (length($leading_tabs) + 1 ne length($new_leading_tabs)) {
6530 fix_delete_line($fixlinenr - 1, $prevrawline);
6531 $fixed[$fixlinenr] =~ s/^\+$new_leading_tabs/\+$leading_tabs/;
6538 if ($line =~ /^\+.*\b$logFunctions\s*\(/ &&
6539 $prevline =~ /^[ \+]\s*if\s*\(\s*(\!\s*|NULL\s*==\s*)?($Lval)(\s*==\s*NULL\s*)?\s*\)/ &&
6540 (defined $1 || defined $3) &&
6545 my ($s, $c) = ctx_statement_block($linenr - 3, $realcnt, 0);
6546 # print("line: <$line>\nprevline: <$prevline>\ns: <$s>\nc: <$c>\n\n\n");
6548 if ($s =~ /(?:^|\n)[ \+]\s*(?:$Type\s*)?\Q$testval\E\s*=\s*(?:\([^\)]*\)\s*)?\s*$allocFunctions\s*\(/ &&
6549 $s !~ /\b__GFP_NOWARN\b/ ) {
6556 if ($line !~ /printk(?:_ratelimited|_once)?\s*\(/ &&
6557 $line =~ /\b$logFunctions\s*\(.*\b(KERN_[A-Z]+)\b/) {
6558 my $level = $1;
6562 $fixed[$fixlinenr] =~ s/\s*$level\s*//;
6567 if ($line =~ /\bprintk\s*\(\s*KERN_CONT\b|\bpr_cont\s*\(/) {
6574 $line =~ /\b$logFunctions\s*\(/ &&
6581 my $pspec = $1;
6583 my $lineoff = substr($stat_real, 0, $-[1]) =~ tr@\n@@;
6588 $nspec =~ s/h//g;
6589 $fixed[$fixlinenr + $lineoff] =~ s/\Q$pspec\E/$nspec/;
6596 $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ &&
6604 while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) {
6605 my $val = $1;
6611 $fixed[$fixlinenr] =~ s/\b\Q$val\E\s*(?:==|\!=)\s*NULL\b/$equal$val/;
6618 my $attr = $1;
6619 if ($line =~ /^\+\s*static\s+(?:const\s+)?(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*[=;]/) {
6620 my $ptr = $1;
6622 if ((($ptr =~ /\b(union|struct)\s+$attr\b/ &&
6625 ($ptr !~ /\b(union|struct)\s+$attr\b/ &&
6629 $fixed[$fixlinenr] =~ s/(\bstatic\s+(?:const\s+)?)(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*([=;])\s*/"$1" . trim(string_find_replace($2, "\\s*$attr\\s*", " ")) . " " . trim(string_find_replace($3, "\\s*$attr\\s*", "")) . " $attr" . ("$4" eq ";" ? ";" : " = ")/e;
6636 my $attr = $1;
6638 my $attr_prefix = $1;
6644 s/$InitAttributeData/${attr_prefix}initconst/;
6650 my $attr = $1;
6655 /(^\+\s*(?:static\s+))/;
6656 $lead = rtrim($1);
6659 $fixed[$fixlinenr] =~ s/(^\+\s*(?:static\s+))/$lead/;
6665 $line =~ /($Type)\s*$Ident/ && $1 !~ /\*\s*$/ && $1 =~ /\bconst\b/) {
6669 $fixed[$fixlinenr] =~ s/\s+__read_mostly\b//;
6675 $line =~ /(__constant_(?:htons|ntohs|[bl]e(?:16|32|64)_to_cpu|cpu_to_[bl]e(?:16|32|64)))\s*\(/) {
6676 my $constant_func = $1;
6678 $func =~ s/^__constant_//;
6682 $fixed[$fixlinenr] =~ s/\b$constant_func\b/$func/g;
6687 if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
6688 my $delay = $1;
6689 # ignore udelay's < 10, however
6700 # warn about unexpectedly long msleep's
6701 if ($line =~ /\bmsleep\s*\((\d+)\);/) {
6702 if ($1 < 20) {
6709 if ($line =~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) {
6715 if ($line =~ /\bget_jiffies_64\s*\(\s*\)\s*$Compare|$Compare\s*get_jiffies_64\s*\(\s*\)/) {
6721 # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
6728 if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
6730 "exactly one space required after that #$1\n" . $herecurr) &&
6733 s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /;
6739 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ ||
6740 $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
6741 my $which = $1;
6744 "$1 definition without comment\n" . $herecurr);
6768 if ($line =~ /\b(?:$all_barriers)\s*\(/) {
6779 $line =~ m/\b(?:$underscore_smp_barriers)\s*\(/ &&
6780 $line !~ m/^.\s*\#\s*define\s+(?:$underscore_smp_barriers)\s*\(/) {
6786 if ($line =~ /\bwaitqueue_active\s*\(/) {
6794 if ($line =~ /\bdata_race\s*\(/) {
6809 if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
6815 if ($line =~ /\b($Type)\s+($Storage)\b/) {
6817 "storage class '$2' should be located before type '$1'\n" . $herecurr);
6821 $line !~ /^.\s*$Storage/ &&
6822 $line =~ /^.\s*(.+?)\$Storage\s/ &&
6823 $1 !~ /[\,\)]\s*$/) {
6830 if ($line =~ /\b$Type\s+$Inline\b/ ||
6831 $line =~ /\b$Inline\s+$Storage\b/) {
6840 "plain inline is preferred over $1\n" . $herecurr) &&
6842 $fixed[$fixlinenr] =~ s/\b(__inline__|__inline)\b/inline/;
6849 $rawline =~ /\b__attribute__\s*\(\s*($balanced_parens)\s*\)/) {
6850 my $attr = $1;
6851 $attr =~ s/\s*\(\s*(.*)\)\s*/$1/;
6879 while ($attr =~ /\s*(\w+)\s*(${balanced_parens})?/g) {
6880 my $orig_attr = $1;
6884 $curr_attr =~ s/^[\s_]+|[\s_]+$//g;
6888 $params =~ /^\s*\(\s*(\w+)\s*,\s*(.*)/;
6889 $new = "__$1\($2";
6896 my $remove = "\Q$orig_attr\E" . '\s*' . "\Q$params\E" . '(?:\s*,\s*)?';
6897 $fixed[$fixlinenr] =~ s/$remove//;
6898 $fixed[$fixlinenr] =~ s/\b__attribute__/$new __attribute__/;
6899 $fixed[$fixlinenr] =~ s/\}\Q$new\E/} $new/;
6900 $fixed[$fixlinenr] =~ s/ __attribute__\s*\(\s*\(\s*\)\s*\)//;
6914 $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ &&
6915 ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ ||
6924 $line =~ /\b($Declare)\s*$Ident\s*[=;,\[]/) {
6925 my $type = $1;
6927 $type = $1;
6929 $kernel_type = 's' if ($type =~ /^_*[si]/);
6931 $kernel_type .= $1;
6935 $fixed[$fixlinenr] =~ s/\b$type\b/$kernel_type/;
6941 if ($line =~ /(\(\s*$C90_int_types\s*\)\s*)($Constant)\b/) {
6942 my $cast = $1;
6946 $newconst =~ s/${Int_type}$//;
6948 if ($cast =~ /\blong\s+long\b/) {
6956 $fixed[$fixlinenr] =~ s/\Q$cast\E$const\b/$newconst$suffix/;
6961 if ($line =~ /\bsizeof\s*\(\s*\&/) {
6967 if ($line =~ /\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/) {
6969 "sizeof $1 should be sizeof($1)\n" . $herecurr) &&
6971 $fixed[$fixlinenr] =~ s/\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/"sizeof(" . trim($1) . ")"/ex;
6976 if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) {
6982 if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
6984 $fmt =~ s/%%//g;
6989 $fixed[$fixlinenr] =~ s/\bseq_printf\b/seq_puts/;
6997 $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s &&
6998 $1 !~ /^_*volatile_*$/) {
7008 my $fmt = get_quoted_string($lines[$count - 1], raw_line($count, 0));
7009 $fmt =~ s/%%//g;
7012 $specifier = $1;
7038 $use =~ s/pS/ps/ if ($bad_specifier =~ /pf/);
7053 $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/) {
7061 "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
7062 } elsif ($ms_size =~ /^(0x|)1$/i) {
7071 # $stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
7075 # $fixed[$fixlinenr] =~ s/\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/ether_addr_copy($2, $7)/;
7082 # $stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
7091 # $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
7099 # $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_zero_addr($2)/;
7105 # $fixed[$fixlinenr] =~ s/\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*,\s*ETH_ALEN\s*\)/eth_broadcast_addr($2)/;
7110 if ($line =~ /\bstrcpy\s*\(/ && !is_userspace($realfile)) {
7116 if ($line =~ /\bstrlcpy\s*\(/ && !is_userspace($realfile)) {
7122 if ($line =~ /\bstrncpy\s*\(/ && !is_userspace($realfile)) {
7128 if ($line =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
7132 $fixed[$fixlinenr] =~ s/\bethtool_sprintf\s*\(\s*($FuncArg)\s*,\s*($FuncArg)/ethtool_puts($1, $7)/;
7136 # use $rawline because $line loses %s via sanitization and thus we can't match against it.
7137 if ($rawline =~ /\bethtool_sprintf\s*\(\s*$FuncArg\s*,\s*\"\%s\"\s*,\s*$FuncArg\s*\)/) {
7139 "Prefer ethtool_puts over ethtool_sprintf with standalone \"%s\" specifier\n" . $herecurr) &&
7141 $fixed[$fixlinenr] =~ s/\bethtool_sprintf\s*\(\s*($FuncArg)\s*,\s*"\%s"\s*,\s*($FuncArg)/ethtool_puts($1, $7)/;
7149 $stat =~ /^\+(?:.*?)\b(min|max)\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
7151 my $call = $1;
7173 $stat =~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) {
7174 my $min = $1;
7190 ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ &&
7191 $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ &&
7192 $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) {
7207 if ($stat_real =~ /\bsscanf\b\s*\(\s*$FuncArg\s*,\s*("[^"]+")/) {
7210 if ($count == 1 &&
7220 $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
7224 $fixed[$fixlinenr] =~ s/(.*)\bextern\b\s*(.*)/$1$2/;
7230 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
7232 my $function_name = $1;
7235 my $s = $stat;
7237 substr($s, 0, length($cond), '');
7239 if ($s =~ /^\s*;/)
7251 $stat =~ /^\+extern struct\s+(\w+)\s+(\w+)\[\];/)
7253 my ($st_type, $st_name) = ($1, $2);
7255 for my $s (keys %maybe_linker_symbol) {
7256 #print "Linker symbol? $st_name : $s\n";
7258 if $st_name =~ /$s/;
7266 $stat =~ /^.\s*extern\s+/)
7274 $stat =~ /^.\s*(?:extern\s+)?$Type\s*(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*\(\s*([^{]+)\s*\)\s*;/s &&
7275 $1 ne "void") {
7276 my $args = trim($1);
7277 while ($args =~ m/\s*($Type\s*(?:$Ident|\(\s*\*\s*$Ident?\s*\)\s*$balanced_parens)?)/g) {
7278 my $arg = trim($1);
7279 if ($arg =~ /^$Type$/ && $arg !~ /enum\s+$Ident$/) {
7289 $stat =~ /^.\s*(?:$Storage\s+)?$Type\s*($Ident)\s*$balanced_parens\s*{/s) {
7290 $context_function = $1;
7299 $ok = 1 if ($rl =~ /^[ \+]\{/);
7300 $ok = 1 if ($rl =~ /\{/ && $n == 0);
7309 # checks for new __setup's
7311 my $name = $1;
7320 if ($line =~ /\*\s*\)\s*$allocFunctions\b/) {
7328 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k|v)[mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) {
7330 "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
7336 $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*,/) {
7344 if ($a1 =~ s/^sizeof\s*\S\(?([^\)]*)\)?$/$1/) {
7350 $cnt == 1 &&
7352 $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*,/$1 = $newfunc($a1,/;
7361 $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
7371 if ($a1 =~ /^sizeof\s*\S/) {
7375 if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ &&
7382 $cnt == 1 &&
7385 $sized =~ s/^sizeof\s*\S\(?([^\)]*)\)?$/$1/;
7386 $fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . $sized . ', ' . trim($r1)/e;
7393 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*($Lval)\s*,/ &&
7394 $1 eq $3) {
7400 if ($line =~ /\b((?:devm_)?((?:k|kv)?(calloc|malloc_array)(?:_node)?))\s*\(\s*sizeof\b/) {
7402 "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
7406 if ($line =~ /;\s*;\s*$/) {
7408 "Statements terminations use 1 semicolon\n" . $herecurr) &&
7410 $fixed[$fixlinenr] =~ s/(\s*;\s*){2,}$/;/g;
7414 # check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi
7416 $line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) {
7418 $ull = "_ULL" if (defined($1) && $1 =~ /ll/i);
7422 $fixed[$fixlinenr] =~ s/\(?\s*1\s*[ulUL]*\s*<<\s*(\d+|$Ident)\s*\)?/BIT${ull}($1)/;
7427 if ($rawline =~ /\bIS_ENABLED\s*\(\s*(\w+)\s*\)/ && $1 !~ /^${CONFIG_}/) {
7429 "IS_ENABLED($1) is normally used as IS_ENABLED(${CONFIG_}$1)\n" . $herecurr);
7433 if ($line =~ /^\+\s*#\s*if\s+defined(?:\s*\(?\s*|\s+)(${CONFIG_}[A-Z_]+)\s*\)?\s*\|\|\s*defined(?:\s*\(?\s*|\s+)\1_MODULE\s*\)?\s*$/) {
7434 my $config = $1;
7447 'intentional(?:ly)?[ \t]*fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)',
7448 '(?:else,?\s*)?FALL(?:S | |-)?THR(?:OUGH|U|EW)[ \t.!]*(?:-[^\n\r]*)?',
7449 'Fall(?:(?:s | |-)[Tt]|t)hr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
7450 'fall(?:s | |-)?thr(?:ough|u|ew)[ \t.!]*(?:-[^\n\r]*)?',
7467 $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) {
7480 $fixed[$fixlinenr] =~ s/\b__FUNCTION__\b/__func__/g;
7487 "Use of the '$1' macro makes the build non-deterministic\n" . $herecurr);
7491 if ($line =~ /\byield\s*\(\s*\)/) {
7497 if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(.*)$/i) {
7498 my $lead = $1;
7524 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
7530 if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) {
7532 "$1 is obsolete, use k$3 instead\n" . $herecurr);
7536 if ($line =~ /^.\s*__initcall\s*\(/) {
7548 if ($line =~ /\b($deprecated_apis_search)\b\s*\(/) {
7549 my $deprecated_api = $1;
7559 $line =~ /\bstruct\s+($const_structs)\b(?!\s*[\{;])/) {
7561 "struct $1 should normally be const\n" . $herecurr);
7568 $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
7569 $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
7570 $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
7573 $line !~ /^.\s*\.\w+\s*=\s*.*\bNR_CPUS\b/)
7580 if ($line =~ /\+\s*#\s*define\s+((?:__)?ARCH_(?:HAS|HAVE)\w*)\b/) {
7582 "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
7587 $line =~ /\b((?:un)?likely)\s*\(\s*$FuncArg\s*\)\s*$Compare/) {
7589 "Using $1 should generally have parentheses around the comparison\n" . $herecurr);
7593 if ($line =~ /\breturn\s+sysfs_emit\s*\(\s*$FuncArg\s*,\s*($String)/ &&
7595 my $offset = $+[6] - 1;
7604 if ($sline =~ /^[\+ ]\s*\}(?:\s*__packed)?\s*;\s*$/ &&
7605 $prevline =~ /^\+\s*(?:\}(?:\s*__packed\s*)?|$Type)\s*$Ident\s*\[\s*(0|1)\s*\]\s*;\s*$/) {
7608 $1 == '0' && $fix) {
7609 $fixed[$fixlinenr - 1] =~ s/\[\s*0\s*\]/[]/;
7614 if ($line =~ /\b(?:(?:un)?likely)\s*\(\s*!?\s*(IS_ERR(?:_OR_NULL|_VALUE)?|WARN)/) {
7616 "nested (un)?likely() calls, $1 already uses unlikely() internally\n" . $herecurr);
7620 if ($line =~ /\bin_atomic\s*\(/) {
7650 if ($line =~ /\b($rcu_trace_funcs)\s*\(/) {
7658 if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
7659 $line =~ /__lockdep_no_validate__\s*\)/ ) {
7679 $stat =~ /\bDEVICE_ATTR\s*\(\s*(\w+)\s*,\s*\(?\s*(\s*(?:${multi_mode_perms_string_search}|0[0-7]{3,3})\s*)\s*\)?\s*,\s*(\w+)\s*,\s*(\w+)\s*\)/) {
7680 my $var = $1;
7691 $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*$store\s*\)/DEVICE_ATTR_RW(${var})/;
7699 $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*$show\s*,\s*NULL\s*\)/DEVICE_ATTR_RO(${var})/;
7707 $fixed[$fixlinenr] =~ s/\bDEVICE_ATTR\s*\(\s*$var\s*,\s*\Q$perms\E\s*,\s*NULL\s*,\s*$store\s*\)/DEVICE_ATTR_WO(${var})/;
7724 "Consider renaming function(s)$rename\n" . $herecurr);
7742 my $arg_pos = $entry->[1];
7749 if ($arg_pos > 1) {
7751 $skip_args = "(?:\\s*$FuncArg\\s*,\\s*){$arg_pos,$arg_pos}";
7753 my $test = "\\b$func\\s*\\(${skip_args}($FuncArg(?:\\|\\s*$FuncArg)*)\\s*[,\\)]";
7755 my $val = $1;
7773 my $oval = $1;
7778 $fixed[$fixlinenr] =~ s/\Q$oval\E/$octal/;
7783 if ($line =~ /\bMODULE_LICENSE\s*\(\s*($String)\s*\)/) {
7802 $fixed[$fixlinenr] =~ s/\bMODULE_LICENSE\s*\(\s*"GPL v2"\s*\)/MODULE_LICENSE("GPL")/;
7808 if ($line =~ /\.extra[12]\s*=\s*&(zero|one|int_max)\b/) {
7810 "duplicated sysctl range checking value '$1', consider using the shared one in include/linux/sysctl.h\n" . $herecurr);
7814 if (defined $stat && $line =~ /struct\s+$dev_id_types\s+\w+\s*\[\s*\]\s*=\s*\{/) {
7818 $stripped =~ s/(^|\n)./$1/g;
7820 $stripped =~ s/\\\n/\n/g;
7822 $stripped =~ s/""//g;
7823 $stripped =~ s/0x0//g;
7824 $stripped =~ s/[\s$;,0]//g;
7826 $stripped =~ s/\.$Ident=//g;
7839 while ($line =~ /\*\s*($Ident)\s+__free\s*\(\s*$Ident\s*\)\s*[,;]/g) {
7841 "pointer '$1' with __free attribute should be initialized\n" . $herecurr);
7847 if ($#rawlines == -1) {
7853 if ($mailback && ($clean == 1 || !$is_patch)) {
7876 "Missing Signed-off-by: line(s)\n");
7877 } elsif ($authorsignoff != 1) {
7880 # 1 -> sign off identical
7908 if ($summary && !($clean == 1 && $quiet == 1)) {
7952 $fixed_line =~ s/^\+//;
7964 Wrote EXPERIMENTAL --fix correction(s) to '$newfile'
7977 if ($clean == 1) {