2 # (c) 2001, Dave Jones. (the file handling bit)
3 # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
4 # (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
5 # (c) 2008-2010 Andy Whitcroft <apw@canonical.com>
6 # Licensed under the terms of the GNU GPL License version 2
16 use Getopt::Long qw(:config no_auto_abbrev);
41 my $configuration_file = ".checkpatch.conf";
42 my $max_line_length = 80;
43 my $ignore_perl_version = 0;
44 my $minimum_perl_version = 5.10.0;
50 Usage: $P [OPTION]... [FILE]...
55 --no-tree run without a kernel tree
56 --no-signoff do not check for 'Signed-off-by' line
57 --patch treat FILE as patchfile (default)
58 --emacs emacs compile window format
59 --terse one line per report
60 -f, --file treat FILE as regular source file
61 --subjective, --strict enable more subjective tests
62 --types TYPE(,TYPE2...) show only these comma separated message types
63 --ignore TYPE(,TYPE2...) ignore various comma separated message types
64 --max-line-length=n set the maximum line length, if exceeded, warn
65 --show-types show the message "types" in the output
66 --root=PATH PATH to the kernel tree root
67 --no-summary suppress the per-file summary
68 --mailback only produce a report in case of warnings/errors
69 --summary-file include the filename in summary
70 --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
71 'values', 'possible', 'type', and 'attr' (default
73 --test-only=WORD report only warnings/errors containing WORD
75 --fix EXPERIMENTAL - may create horrible results
76 If correctable single-line errors exist, create
77 "<inputfile>.EXPERIMENTAL-checkpatch-fixes"
78 with potential errors corrected to the preferred
80 --fix-inplace EXPERIMENTAL - may create horrible results
81 Is the same as --fix, but overwrites the input
82 file. It's your fault if there's no backup or git
83 --ignore-perl-version override checking of perl version. expect
85 -h, --help, --version display this help and exit
87 When FILE is - read standard input.
93 my $conf = which_conf($configuration_file);
96 open(my $conffile, '<', "$conf")
97 or warn "$P: Can't find a readable $configuration_file file $!\n";
102 $line =~ s/\s*\n?$//g;
106 next if ($line =~ m/^\s*#/);
107 next if ($line =~ m/^\s*$/);
109 my @words = split(" ", $line);
110 foreach my $word (@words) {
111 last if ($word =~ m/^#/);
112 push (@conf_args, $word);
116 unshift(@ARGV, @conf_args) if @conf_args;
120 'q|quiet+' => \$quiet,
122 'signoff!' => \$chk_signoff,
123 'patch!' => \$chk_patch,
127 'subjective!' => \$check,
128 'strict!' => \$check,
129 'ignore=s' => \@ignore,
131 'show-types!' => \$show_types,
132 'max-line-length=i' => \$max_line_length,
134 'summary!' => \$summary,
135 'mailback!' => \$mailback,
136 'summary-file!' => \$summary_file,
138 'fix-inplace!' => \$fix_inplace,
139 'ignore-perl-version!' => \$ignore_perl_version,
140 'debug=s' => \%debug,
141 'test-only=s' => \$tst_only,
148 $fix = 1 if ($fix_inplace);
152 if ($^V && $^V lt $minimum_perl_version) {
153 printf "$P: requires at least perl version %vd\n", $minimum_perl_version;
154 if (!$ignore_perl_version) {
160 print "$P: no input files\n";
164 sub hash_save_array_words {
165 my ($hashRef, $arrayRef) = @_;
167 my @array = split(/,/, join(',', @$arrayRef));
168 foreach my $word (@array) {
169 $word =~ s/\s*\n?$//g;
172 $word =~ tr/[a-z]/[A-Z]/;
174 next if ($word =~ m/^\s*#/);
175 next if ($word =~ m/^\s*$/);
181 sub hash_show_words {
182 my ($hashRef, $prefix) = @_;
184 if ($quiet == 0 && keys %$hashRef) {
185 print "NOTE: $prefix message types:";
186 foreach my $word (sort keys %$hashRef) {
193 hash_save_array_words(\%ignore_type, \@ignore);
194 hash_save_array_words(\%use_type, \@use);
197 my $dbg_possible = 0;
200 for my $key (keys %debug) {
202 eval "\${dbg_$key} = '$debug{$key}';";
206 my $rpt_cleaners = 0;
215 if (!top_of_kernel_tree($root)) {
216 die "$P: $root: --root does not point at a valid tree\n";
219 if (top_of_kernel_tree('.')) {
221 } elsif ($0 =~ m@(.*)/scripts/[^/]*$@ &&
222 top_of_kernel_tree($1)) {
227 if (!defined $root) {
228 print "Must be run from the top-level dir. of a kernel tree\n";
233 my $emitted_corrupt = 0;
236 [A-Za-z_][A-Za-z\d_]*
237 (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
239 our $Storage = qr{extern|static|asmlinkage};
251 our $InitAttributePrefix = qr{__(?:mem|cpu|dev|net_|)};
252 our $InitAttributeData = qr{$InitAttributePrefix(?:initdata\b)};
253 our $InitAttributeConst = qr{$InitAttributePrefix(?:initconst\b)};
254 our $InitAttributeInit = qr{$InitAttributePrefix(?:init\b)};
255 our $InitAttribute = qr{$InitAttributeData|$InitAttributeConst|$InitAttributeInit};
257 # Notes to $Attribute:
258 # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check
278 ____cacheline_aligned|
279 ____cacheline_aligned_in_smp|
280 ____cacheline_internodealigned_in_smp|
284 our $Inline = qr{inline|__always_inline|noinline};
285 our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
286 our $Lval = qr{$Ident(?:$Member)*};
288 our $Int_type = qr{(?i)llu|ull|ll|lu|ul|l|u};
289 our $Binary = qr{(?i)0b[01]+$Int_type?};
290 our $Hex = qr{(?i)0x[0-9a-f]+$Int_type?};
291 our $Int = qr{[0-9]+$Int_type?};
292 our $Float_hex = qr{(?i)0x[0-9a-f]+p-?[0-9]+[fl]?};
293 our $Float_dec = qr{(?i)(?:[0-9]+\.[0-9]*|[0-9]*\.[0-9]+)(?:e-?[0-9]+)?[fl]?};
294 our $Float_int = qr{(?i)[0-9]+e-?[0-9]+[fl]?};
295 our $Float = qr{$Float_hex|$Float_dec|$Float_int};
296 our $Constant = qr{$Float|$Binary|$Hex|$Int};
297 our $Assignment = qr{\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=};
298 our $Compare = qr{<=|>=|==|!=|<|>};
299 our $Arithmetic = qr{\+|-|\*|\/|%};
303 &&|\|\||,|\^|\+\+|--|&|\||$Arithmetic
307 our $NonptrTypeWithAttr;
311 our $NON_ASCII_UTF8 = qr{
312 [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
313 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
314 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
315 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
316 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
317 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
318 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
322 [\x09\x0A\x0D\x20-\x7E] # ASCII
326 our $typeTypedefs = qr{(?x:
327 (?:__)?(?:u|s|be|le)(?:8|16|32|64)|
331 our $logFunctions = qr{(?x:
332 printk(?:_ratelimited|_once|)|
333 (?:[a-z0-9]+_){1,2}(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)|
334 WARN(?:_RATELIMIT|_ONCE|)|
337 seq_vprintf|seq_printf|seq_puts
340 our $signature_tags = qr{(?xi:
353 qr{(?:unsigned\s+)?char},
354 qr{(?:unsigned\s+)?short},
355 qr{(?:unsigned\s+)?int},
356 qr{(?:unsigned\s+)?long},
357 qr{(?:unsigned\s+)?long\s+int},
358 qr{(?:unsigned\s+)?long\s+long},
359 qr{(?:unsigned\s+)?long\s+long\s+int},
368 qr{${Ident}_handler},
369 qr{${Ident}_handler_fn},
371 our @typeListWithAttr = (
373 qr{struct\s+$InitAttribute\s+$Ident},
374 qr{union\s+$InitAttribute\s+$Ident},
377 our @modifierList = (
381 our $allowed_asm_includes = qr{(?x:
385 # memory.h: ARM has a custom one
388 my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)";
389 my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)";
390 my $allWithAttr = "(?x: \n" . join("|\n ", @typeListWithAttr) . "\n)";
391 $Modifier = qr{(?:$Attribute|$Sparse|$mods)};
393 (?:$Modifier\s+|const\s+)*
395 (?:typeof|__typeof__)\s*\([^\)]*\)|
399 (?:\s+$Modifier|\s+const)*
401 $NonptrTypeWithAttr = qr{
402 (?:$Modifier\s+|const\s+)*
404 (?:typeof|__typeof__)\s*\([^\)]*\)|
408 (?:\s+$Modifier|\s+const)*
412 (?:(?:\s|\*|\[\])+\s*const|(?:\s|\*|\[\])+|(?:\s*\[\s*\])+)?
413 (?:\s+$Inline|\s+$Modifier)*
415 $Declare = qr{(?:$Storage\s+)?$Type};
419 our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*};
421 # Using $balanced_parens, $LvalOrFunc, or $FuncArg
422 # requires at least perl version v5.10.0
423 # Any use must be runtime checked with $^V
425 our $balanced_parens = qr/(\((?:[^\(\)]++|(?-1))*\))/;
426 our $LvalOrFunc = qr{($Lval)\s*($balanced_parens{0,1})\s*};
427 our $FuncArg = qr{$Typecast{0,1}($LvalOrFunc|$Constant)};
431 return "" if (!defined($string));
432 $string =~ s@^\s*\(\s*@@g;
433 $string =~ s@\s*\)\s*$@@g;
434 $string =~ s@\s+@ @g;
438 sub seed_camelcase_file {
441 return if (!(-f $file));
445 open(my $include_file, '<', "$file")
446 or warn "$P: Can't read '$file' $!\n";
447 my $text = <$include_file>;
448 close($include_file);
450 my @lines = split('\n', $text);
452 foreach my $line (@lines) {
453 next if ($line !~ /(?:[A-Z][a-z]|[a-z][A-Z])/);
454 if ($line =~ /^[ \t]*(?:#[ \t]*define|typedef\s+$Type)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)/) {
456 } elsif ($line =~ /^\s*$Declare\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[\(\[,;]/) {
458 } elsif ($line =~ /^\s*(?:union|struct|enum)\s+(\w*(?:[A-Z][a-z]|[a-z][A-Z])\w*)\s*[;\{]/) {
464 my $camelcase_seeded = 0;
465 sub seed_camelcase_includes {
466 return if ($camelcase_seeded);
469 my $camelcase_cache = "";
470 my @include_files = ();
472 $camelcase_seeded = 1;
475 my $git_last_include_commit = `git log --no-merges --pretty=format:"%h%n" -1 -- include`;
476 chomp $git_last_include_commit;
477 $camelcase_cache = ".checkpatch-camelcase.git.$git_last_include_commit";
479 my $last_mod_date = 0;
480 $files = `find $root/include -name "*.h"`;
481 @include_files = split('\n', $files);
482 foreach my $file (@include_files) {
483 my $date = POSIX::strftime("%Y%m%d%H%M",
484 localtime((stat $file)[9]));
485 $last_mod_date = $date if ($last_mod_date < $date);
487 $camelcase_cache = ".checkpatch-camelcase.date.$last_mod_date";
490 if ($camelcase_cache ne "" && -f $camelcase_cache) {
491 open(my $camelcase_file, '<', "$camelcase_cache")
492 or warn "$P: Can't read '$camelcase_cache' $!\n";
493 while (<$camelcase_file>) {
497 close($camelcase_file);
503 $files = `git ls-files "include/*.h"`;
504 @include_files = split('\n', $files);
507 foreach my $file (@include_files) {
508 seed_camelcase_file($file);
511 if ($camelcase_cache ne "") {
512 unlink glob ".checkpatch-camelcase.*";
513 open(my $camelcase_file, '>', "$camelcase_cache")
514 or warn "$P: Can't write '$camelcase_cache' $!\n";
515 foreach (sort { lc($a) cmp lc($b) } keys(%camelcase)) {
516 print $camelcase_file ("$_\n");
518 close($camelcase_file);
522 $chk_signoff = 0 if ($file);
528 for my $filename (@ARGV) {
531 open($FILE, '-|', "diff -u /dev/null $filename") ||
532 die "$P: $filename: diff failed - $!\n";
533 } elsif ($filename eq '-') {
534 open($FILE, '<&STDIN');
536 open($FILE, '<', "$filename") ||
537 die "$P: $filename: open failed - $!\n";
539 if ($filename eq '-') {
540 $vname = 'Your patch';
549 if (!process($filename)) {
559 sub top_of_kernel_tree {
563 "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",
564 "README", "Documentation", "arch", "include", "drivers",
565 "fs", "init", "ipc", "kernel", "lib", "scripts",
568 foreach my $check (@tree_check) {
569 if (! -e $root . '/' . $check) {
577 my ($formatted_email) = @_;
583 if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) {
586 $comment = $3 if defined $3;
587 } elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) {
589 $comment = $2 if defined $2;
590 } elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) {
592 $comment = $2 if defined $2;
593 $formatted_email =~ s/$address.*$//;
594 $name = $formatted_email;
596 $name =~ s/^\"|\"$//g;
597 # If there's a name left after stripping spaces and
598 # leading quotes, and the address doesn't have both
599 # leading and trailing angle brackets, the address
601 # "joe smith joe@smith.com" bad
602 # "joe smith <joe@smith.com" bad
603 if ($name ne "" && $address !~ /^<[^>]+>$/) {
611 $name =~ s/^\"|\"$//g;
612 $address = trim($address);
613 $address =~ s/^\<|\>$//g;
615 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
616 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
620 return ($name, $address, $comment);
624 my ($name, $address) = @_;
629 $name =~ s/^\"|\"$//g;
630 $address = trim($address);
632 if ($name =~ /[^\w \-]/i) { ##has "must quote" chars
633 $name =~ s/(?<!\\)"/\\"/g; ##escape quotes
638 $formatted_email = "$address";
640 $formatted_email = "$name <$address>";
643 return $formatted_email;
649 foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
650 if (-e "$path/$conf") {
651 return "$path/$conf";
663 for my $c (split(//, $str)) {
667 for (; ($n % 8) != 0; $n++) {
679 (my $res = shift) =~ tr/\t/ /c;
686 # Drop the diff line leader and expand tabs
688 $line = expand_tabs($line);
690 # Pick the indent from the front of the line.
691 my ($white) = ($line =~ /^(\s*)/);
693 return (length($line), length($white));
696 my $sanitise_quote = '';
698 sub sanitise_line_reset {
699 my ($in_comment) = @_;
702 $sanitise_quote = '*/';
704 $sanitise_quote = '';
717 # Always copy over the diff marker.
718 $res = substr($line, 0, 1);
720 for ($off = 1; $off < length($line); $off++) {
721 $c = substr($line, $off, 1);
723 # Comments we are wacking completly including the begin
724 # and end, all to $;.
725 if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
726 $sanitise_quote = '*/';
728 substr($res, $off, 2, "$;$;");
732 if ($sanitise_quote eq '*/' && substr($line, $off, 2) eq '*/') {
733 $sanitise_quote = '';
734 substr($res, $off, 2, "$;$;");
738 if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') {
739 $sanitise_quote = '//';
741 substr($res, $off, 2, $sanitise_quote);
746 # A \ in a string means ignore the next character.
747 if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&
749 substr($res, $off, 2, 'XX');
754 if ($c eq "'" || $c eq '"') {
755 if ($sanitise_quote eq '') {
756 $sanitise_quote = $c;
758 substr($res, $off, 1, $c);
760 } elsif ($sanitise_quote eq $c) {
761 $sanitise_quote = '';
765 #print "c<$c> SQ<$sanitise_quote>\n";
766 if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {
767 substr($res, $off, 1, $;);
768 } elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") {
769 substr($res, $off, 1, $;);
770 } elsif ($off != 0 && $sanitise_quote && $c ne "\t") {
771 substr($res, $off, 1, 'X');
773 substr($res, $off, 1, $c);
777 if ($sanitise_quote eq '//') {
778 $sanitise_quote = '';
781 # The pathname on a #include may be surrounded by '<' and '>'.
782 if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {
783 my $clean = 'X' x length($1);
784 $res =~ s@\<.*\>@<$clean>@;
786 # The whole of a #error is a string.
787 } elsif ($res =~ /^.\s*\#\s*(?:error|warning)\s+(.*)\b/) {
788 my $clean = 'X' x length($1);
789 $res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@;
795 sub get_quoted_string {
796 my ($line, $rawline) = @_;
798 return "" if ($line !~ m/(\"[X]+\")/g);
799 return substr($rawline, $-[0], $+[0] - $-[0]);
802 sub ctx_statement_block {
803 my ($linenr, $remain, $off) = @_;
804 my $line = $linenr - 1;
821 @stack = (['', 0]) if ($#stack == -1);
823 #warn "CSB: blk<$blk> remain<$remain>\n";
824 # If we are about to drop off the end, pull in more
827 for (; $remain > 0; $line++) {
828 last if (!defined $lines[$line]);
829 next if ($lines[$line] =~ /^-/);
832 $blk .= $lines[$line] . "\n";
837 # Bail if there is no further context.
838 #warn "CSB: blk<$blk> off<$off> len<$len>\n";
842 if ($level == 0 && substr($blk, $off) =~ /^.\s*#\s*define/) {
848 $c = substr($blk, $off, 1);
849 $remainder = substr($blk, $off);
851 #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n";
853 # Handle nested #if/#else.
854 if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) {
855 push(@stack, [ $type, $level ]);
856 } elsif ($remainder =~ /^#\s*(?:else|elif)\b/) {
857 ($type, $level) = @{$stack[$#stack - 1]};
858 } elsif ($remainder =~ /^#\s*endif\b/) {
859 ($type, $level) = @{pop(@stack)};
862 # Statement ends at the ';' or a close '}' at the
864 if ($level == 0 && $c eq ';') {
868 # An else is really a conditional as long as its not else if
869 if ($level == 0 && $coff_set == 0 &&
870 (!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
871 $remainder =~ /^(else)(?:\s|{)/ &&
872 $remainder !~ /^else\s+if\b/) {
873 $coff = $off + length($1) - 1;
875 #warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";
876 #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
879 if (($type eq '' || $type eq '(') && $c eq '(') {
883 if ($type eq '(' && $c eq ')') {
885 $type = ($level != 0)? '(' : '';
887 if ($level == 0 && $coff < $soff) {
890 #warn "CSB: mark coff<$coff>\n";
893 if (($type eq '' || $type eq '{') && $c eq '{') {
897 if ($type eq '{' && $c eq '}') {
899 $type = ($level != 0)? '{' : '';
902 if (substr($blk, $off + 1, 1) eq ';') {
908 # Preprocessor commands end at the newline unless escaped.
909 if ($type eq '#' && $c eq "\n" && $p ne "\\") {
917 # We are truly at the end, so shuffle to the next line.
924 my $statement = substr($blk, $soff, $off - $soff + 1);
925 my $condition = substr($blk, $soff, $coff - $soff + 1);
927 #warn "STATEMENT<$statement>\n";
928 #warn "CONDITION<$condition>\n";
930 #print "coff<$coff> soff<$off> loff<$loff>\n";
932 return ($statement, $condition,
933 $line, $remain + 1, $off - $loff + 1, $level);
936 sub statement_lines {
939 # Strip the diff line prefixes and rip blank lines at start and end.
940 $stmt =~ s/(^|\n)./$1/g;
944 my @stmt_lines = ($stmt =~ /\n/g);
946 return $#stmt_lines + 2;
949 sub statement_rawlines {
952 my @stmt_lines = ($stmt =~ /\n/g);
954 return $#stmt_lines + 2;
957 sub statement_block_size {
960 $stmt =~ s/(^|\n)./$1/g;
966 my @stmt_lines = ($stmt =~ /\n/g);
967 my @stmt_statements = ($stmt =~ /;/g);
969 my $stmt_lines = $#stmt_lines + 2;
970 my $stmt_statements = $#stmt_statements + 1;
972 if ($stmt_lines > $stmt_statements) {
975 return $stmt_statements;
979 sub ctx_statement_full {
980 my ($linenr, $remain, $off) = @_;
981 my ($statement, $condition, $level);
985 # Grab the first conditional/block pair.
986 ($statement, $condition, $linenr, $remain, $off, $level) =
987 ctx_statement_block($linenr, $remain, $off);
988 #print "F: c<$condition> s<$statement> remain<$remain>\n";
989 push(@chunks, [ $condition, $statement ]);
990 if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
991 return ($level, $linenr, @chunks);
994 # Pull in the following conditional/block pairs and see if they
995 # could continue the statement.
997 ($statement, $condition, $linenr, $remain, $off, $level) =
998 ctx_statement_block($linenr, $remain, $off);
999 #print "C: c<$condition> s<$statement> remain<$remain>\n";
1000 last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
1002 push(@chunks, [ $condition, $statement ]);
1005 return ($level, $linenr, @chunks);
1009 my ($linenr, $remain, $outer, $open, $close, $off) = @_;
1011 my $start = $linenr - 1;
1018 my @stack = ($level);
1019 for ($line = $start; $remain > 0; $line++) {
1020 next if ($rawlines[$line] =~ /^-/);
1023 $blk .= $rawlines[$line];
1025 # Handle nested #if/#else.
1026 if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
1027 push(@stack, $level);
1028 } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
1029 $level = $stack[$#stack - 1];
1030 } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
1031 $level = pop(@stack);
1034 foreach my $c (split(//, $lines[$line])) {
1035 ##print "C<$c>L<$level><$open$close>O<$off>\n";
1041 if ($c eq $close && $level > 0) {
1043 last if ($level == 0);
1044 } elsif ($c eq $open) {
1049 if (!$outer || $level <= 1) {
1050 push(@res, $rawlines[$line]);
1053 last if ($level == 0);
1056 return ($level, @res);
1058 sub ctx_block_outer {
1059 my ($linenr, $remain) = @_;
1061 my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0);
1065 my ($linenr, $remain) = @_;
1067 my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0);
1071 my ($linenr, $remain, $off) = @_;
1073 my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off);
1076 sub ctx_block_level {
1077 my ($linenr, $remain) = @_;
1079 return ctx_block_get($linenr, $remain, 0, '{', '}', 0);
1081 sub ctx_statement_level {
1082 my ($linenr, $remain, $off) = @_;
1084 return ctx_block_get($linenr, $remain, 0, '(', ')', $off);
1087 sub ctx_locate_comment {
1088 my ($first_line, $end_line) = @_;
1090 # Catch a comment on the end of the line itself.
1091 my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*(?:\\\s*)?$@);
1092 return $current_comment if (defined $current_comment);
1094 # Look through the context and try and figure out if there is a
1097 $current_comment = '';
1098 for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
1099 my $line = $rawlines[$linenr - 1];
1101 if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
1104 if ($line =~ m@/\*@) {
1107 if (!$in_comment && $current_comment ne '') {
1108 $current_comment = '';
1110 $current_comment .= $line . "\n" if ($in_comment);
1111 if ($line =~ m@\*/@) {
1116 chomp($current_comment);
1117 return($current_comment);
1119 sub ctx_has_comment {
1120 my ($first_line, $end_line) = @_;
1121 my $cmt = ctx_locate_comment($first_line, $end_line);
1123 ##print "LINE: $rawlines[$end_line - 1 ]\n";
1124 ##print "CMMT: $cmt\n";
1126 return ($cmt ne '');
1130 my ($linenr, $cnt) = @_;
1132 my $offset = $linenr - 1;
1137 $line = $rawlines[$offset++];
1138 next if (defined($line) && $line =~ /^-/);
1150 while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) {
1153 $coded = sprintf("^%c", unpack('C', $2) + 64);
1162 my $av_preprocessor = 0;
1167 sub annotate_reset {
1168 $av_preprocessor = 0;
1170 @av_paren_type = ('E');
1171 $av_pend_colon = 'O';
1174 sub annotate_values {
1175 my ($stream, $type) = @_;
1178 my $var = '_' x length($stream);
1181 print "$stream\n" if ($dbg_values > 1);
1183 while (length($cur)) {
1184 @av_paren_type = ('E') if ($#av_paren_type < 0);
1185 print " <" . join('', @av_paren_type) .
1186 "> <$type> <$av_pending>" if ($dbg_values > 1);
1187 if ($cur =~ /^(\s+)/o) {
1188 print "WS($1)\n" if ($dbg_values > 1);
1189 if ($1 =~ /\n/ && $av_preprocessor) {
1190 $type = pop(@av_paren_type);
1191 $av_preprocessor = 0;
1194 } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
1195 print "CAST($1)\n" if ($dbg_values > 1);
1196 push(@av_paren_type, $type);
1199 } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) {
1200 print "DECLARE($1)\n" if ($dbg_values > 1);
1203 } elsif ($cur =~ /^($Modifier)\s*/) {
1204 print "MODIFIER($1)\n" if ($dbg_values > 1);
1207 } elsif ($cur =~ /^(\#\s*define\s*$Ident)(\(?)/o) {
1208 print "DEFINE($1,$2)\n" if ($dbg_values > 1);
1209 $av_preprocessor = 1;
1210 push(@av_paren_type, $type);
1216 } elsif ($cur =~ /^(\#\s*(?:undef\s*$Ident|include\b))/o) {
1217 print "UNDEF($1)\n" if ($dbg_values > 1);
1218 $av_preprocessor = 1;
1219 push(@av_paren_type, $type);
1221 } elsif ($cur =~ /^(\#\s*(?:ifdef|ifndef|if))/o) {
1222 print "PRE_START($1)\n" if ($dbg_values > 1);
1223 $av_preprocessor = 1;
1225 push(@av_paren_type, $type);
1226 push(@av_paren_type, $type);
1229 } elsif ($cur =~ /^(\#\s*(?:else|elif))/o) {
1230 print "PRE_RESTART($1)\n" if ($dbg_values > 1);
1231 $av_preprocessor = 1;
1233 push(@av_paren_type, $av_paren_type[$#av_paren_type]);
1237 } elsif ($cur =~ /^(\#\s*(?:endif))/o) {
1238 print "PRE_END($1)\n" if ($dbg_values > 1);
1240 $av_preprocessor = 1;
1242 # Assume all arms of the conditional end as this
1243 # one does, and continue as if the #endif was not here.
1244 pop(@av_paren_type);
1245 push(@av_paren_type, $type);
1248 } elsif ($cur =~ /^(\\\n)/o) {
1249 print "PRECONT($1)\n" if ($dbg_values > 1);
1251 } elsif ($cur =~ /^(__attribute__)\s*\(?/o) {
1252 print "ATTR($1)\n" if ($dbg_values > 1);
1253 $av_pending = $type;
1256 } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
1257 print "SIZEOF($1)\n" if ($dbg_values > 1);
1263 } elsif ($cur =~ /^(if|while|for)\b/o) {
1264 print "COND($1)\n" if ($dbg_values > 1);
1268 } elsif ($cur =~/^(case)/o) {
1269 print "CASE($1)\n" if ($dbg_values > 1);
1270 $av_pend_colon = 'C';
1273 } elsif ($cur =~/^(return|else|goto|typeof|__typeof__)\b/o) {
1274 print "KEYWORD($1)\n" if ($dbg_values > 1);
1277 } elsif ($cur =~ /^(\()/o) {
1278 print "PAREN('$1')\n" if ($dbg_values > 1);
1279 push(@av_paren_type, $av_pending);
1283 } elsif ($cur =~ /^(\))/o) {
1284 my $new_type = pop(@av_paren_type);
1285 if ($new_type ne '_') {
1287 print "PAREN('$1') -> $type\n"
1288 if ($dbg_values > 1);
1290 print "PAREN('$1')\n" if ($dbg_values > 1);
1293 } elsif ($cur =~ /^($Ident)\s*\(/o) {
1294 print "FUNC($1)\n" if ($dbg_values > 1);
1298 } elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) {
1299 if (defined $2 && $type eq 'C' || $type eq 'T') {
1300 $av_pend_colon = 'B';
1301 } elsif ($type eq 'E') {
1302 $av_pend_colon = 'L';
1304 print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1);
1307 } elsif ($cur =~ /^($Ident|$Constant)/o) {
1308 print "IDENT($1)\n" if ($dbg_values > 1);
1311 } elsif ($cur =~ /^($Assignment)/o) {
1312 print "ASSIGN($1)\n" if ($dbg_values > 1);
1315 } elsif ($cur =~/^(;|{|})/) {
1316 print "END($1)\n" if ($dbg_values > 1);
1318 $av_pend_colon = 'O';
1320 } elsif ($cur =~/^(,)/) {
1321 print "COMMA($1)\n" if ($dbg_values > 1);
1324 } elsif ($cur =~ /^(\?)/o) {
1325 print "QUESTION($1)\n" if ($dbg_values > 1);
1328 } elsif ($cur =~ /^(:)/o) {
1329 print "COLON($1,$av_pend_colon)\n" if ($dbg_values > 1);
1331 substr($var, length($res), 1, $av_pend_colon);
1332 if ($av_pend_colon eq 'C' || $av_pend_colon eq 'L') {
1337 $av_pend_colon = 'O';
1339 } elsif ($cur =~ /^(\[)/o) {
1340 print "CLOSE($1)\n" if ($dbg_values > 1);
1343 } elsif ($cur =~ /^(-(?![->])|\+(?!\+)|\*|\&\&|\&)/o) {
1346 print "OPV($1)\n" if ($dbg_values > 1);
1353 substr($var, length($res), 1, $variant);
1356 } elsif ($cur =~ /^($Operators)/o) {
1357 print "OP($1)\n" if ($dbg_values > 1);
1358 if ($1 ne '++' && $1 ne '--') {
1362 } elsif ($cur =~ /(^.)/o) {
1363 print "C($1)\n" if ($dbg_values > 1);
1366 $cur = substr($cur, length($1));
1367 $res .= $type x length($1);
1371 return ($res, $var);
1375 my ($possible, $line) = @_;
1376 my $notPermitted = qr{(?:
1393 ^(?:typedef|struct|enum)\b
1395 warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
1396 if ($possible !~ $notPermitted) {
1397 # Check for modifiers.
1398 $possible =~ s/\s*$Storage\s*//g;
1399 $possible =~ s/\s*$Sparse\s*//g;
1400 if ($possible =~ /^\s*$/) {
1402 } elsif ($possible =~ /\s/) {
1403 $possible =~ s/\s*$Type\s*//g;
1404 for my $modifier (split(' ', $possible)) {
1405 if ($modifier !~ $notPermitted) {
1406 warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
1407 push(@modifierList, $modifier);
1412 warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
1413 push(@typeList, $possible);
1417 warn "NOTPOSS: $possible ($line)\n" if ($dbg_possible > 1);
1424 return defined $use_type{$_[0]} if (scalar keys %use_type > 0);
1426 return !defined $ignore_type{$_[0]};
1430 if (!show_type($_[1]) ||
1431 (defined $tst_only && $_[2] !~ /\Q$tst_only\E/)) {
1436 $line = "$prefix$_[0]:$_[1]: $_[2]\n";
1438 $line = "$prefix$_[0]: $_[2]\n";
1440 $line = (split('\n', $line))[0] . "\n" if ($terse);
1442 push(our @report, $line);
1451 if (report("ERROR", $_[0], $_[1])) {
1459 if (report("WARNING", $_[0], $_[1])) {
1467 if ($check && report("CHECK", $_[0], $_[1])) {
1475 sub check_absolute_file {
1476 my ($absolute, $herecurr) = @_;
1477 my $file = $absolute;
1479 ##print "absolute<$absolute>\n";
1481 # See if any suffix of this path is a path within the tree.
1482 while ($file =~ s@^[^/]*/@@) {
1483 if (-f "$root/$file") {
1484 ##print "file<$file>\n";
1492 # It is, so see if the prefix is acceptable.
1493 my $prefix = $absolute;
1494 substr($prefix, -length($file)) = '';
1496 ##print "prefix<$prefix>\n";
1497 if ($prefix ne ".../") {
1498 WARN("USE_RELATIVE_PATH",
1499 "use relative pathname instead of absolute in changelog text\n" . $herecurr);
1506 $string =~ s/^\s+|\s+$//g;
1514 $string =~ s/^\s+//;
1522 $string =~ s/\s+$//;
1527 sub string_find_replace {
1528 my ($string, $find, $replace) = @_;
1530 $string =~ s/$find/$replace/g;
1538 my $source_indent = 8;
1539 my $max_spaces_before_tab = $source_indent - 1;
1540 my $spaces_to_tab = " " x $source_indent;
1542 #convert leading spaces to tabs
1543 1 while $leading =~ s@^([\t]*)$spaces_to_tab@$1\t@g;
1544 #Remove spaces before a tab
1545 1 while $leading =~ s@^([\t]*)( {1,$max_spaces_before_tab})\t@$1\t@g;
1550 sub pos_last_openparen {
1555 my $opens = $line =~ tr/\(/\(/;
1556 my $closes = $line =~ tr/\)/\)/;
1558 my $last_openparen = 0;
1560 if (($opens == 0) || ($closes >= $opens)) {
1564 my $len = length($line);
1566 for ($pos = 0; $pos < $len; $pos++) {
1567 my $string = substr($line, $pos);
1568 if ($string =~ /^($FuncArg|$balanced_parens)/) {
1569 $pos += length($1) - 1;
1570 } elsif (substr($line, $pos, 1) eq '(') {
1571 $last_openparen = $pos;
1572 } elsif (index($string, '(') == -1) {
1577 return $last_openparen + 1;
1581 my $filename = shift;
1587 my $stashrawline="";
1598 my $in_header_lines = 1;
1599 my $in_commit_log = 0; #Scanning lines before patch
1601 my $non_utf8_charset = 0;
1609 # Trace the real file/line as we go.
1615 my $comment_edge = 0;
1619 my $prev_values = 'E';
1622 my %suppress_ifbraces;
1623 my %suppress_whiletrailers;
1624 my %suppress_export;
1625 my $suppress_statement = 0;
1627 my %signatures = ();
1629 # Pre-scan the patch sanitizing the lines.
1630 # Pre-scan the patch looking for any __setup documentation.
1632 my @setup_docs = ();
1635 my $camelcase_file_seeded = 0;
1637 sanitise_line_reset();
1639 foreach my $rawline (@rawlines) {
1643 push(@fixed, $rawline) if ($fix);
1645 if ($rawline=~/^\+\+\+\s+(\S+)/) {
1647 if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
1652 if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
1661 # Guestimate if this is a continuing comment. Run
1662 # the context looking for a comment "edge". If this
1663 # edge is a close comment then we must be in a comment
1667 for (my $ln = $linenr + 1; $cnt > 0; $ln++) {
1668 next if (defined $rawlines[$ln - 1] &&
1669 $rawlines[$ln - 1] =~ /^-/);
1671 #print "RAW<$rawlines[$ln - 1]>\n";
1672 last if (!defined $rawlines[$ln - 1]);
1673 if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ &&
1674 $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) {
1679 if (defined $edge && $edge eq '*/') {
1683 # Guestimate if this is a continuing comment. If this
1684 # is the start of a diff block and this line starts
1685 # ' *' then it is very likely a comment.
1686 if (!defined $edge &&
1687 $rawlines[$linenr] =~ m@^.\s*(?:\*\*+| \*)(?:\s|$)@)
1692 ##print "COMMENT:$in_comment edge<$edge> $rawline\n";
1693 sanitise_line_reset($in_comment);
1695 } elsif ($realcnt && $rawline =~ /^(?:\+| |$)/) {
1696 # Standardise the strings and chars within the input to
1697 # simplify matching -- only bother with positive lines.
1698 $line = sanitise_line($rawline);
1700 push(@lines, $line);
1703 $realcnt-- if ($line =~ /^(?:\+| |$)/);
1708 #print "==>$rawline\n";
1709 #print "-->$line\n";
1711 if ($setup_docs && $line =~ /^\+/) {
1712 push(@setup_docs, $line);
1720 foreach my $line (@lines) {
1722 my $sline = $line; #copy of $line
1723 $sline =~ s/$;/ /g; #with comments as spaces
1725 my $rawline = $rawlines[$linenr - 1];
1727 #extract the line range in the file after the patch is applied
1728 if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
1730 $first_line = $linenr + 1;
1740 %suppress_ifbraces = ();
1741 %suppress_whiletrailers = ();
1742 %suppress_export = ();
1743 $suppress_statement = 0;
1746 # track the line number as we move through the hunk, note that
1747 # new versions of GNU diff omit the leading space on completely
1748 # blank context lines so we need to count that too.
1749 } elsif ($line =~ /^( |\+|$)/) {
1751 $realcnt-- if ($realcnt != 0);
1753 # Measure the line length and indent.
1754 ($length, $indent) = line_stats($rawline);
1756 # Track the previous line.
1757 ($prevline, $stashline) = ($stashline, $line);
1758 ($previndent, $stashindent) = ($stashindent, $indent);
1759 ($prevrawline, $stashrawline) = ($stashrawline, $rawline);
1761 #warn "line<$line>\n";
1763 } elsif ($realcnt == 1) {
1767 my $hunk_line = ($realcnt != 0);
1769 #make up the handle for any error we report on this line
1770 $prefix = "$filename:$realline: " if ($emacs && $file);
1771 $prefix = "$filename:$linenr: " if ($emacs && !$file);
1773 $here = "#$linenr: " if (!$file);
1774 $here = "#$realline: " if ($file);
1776 # extract the filename as it passes
1777 if ($line =~ /^diff --git.*?(\S+)$/) {
1779 $realfile =~ s@^([^/]*)/@@ if (!$file);
1781 } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
1783 $realfile =~ s@^([^/]*)/@@ if (!$file);
1787 if (!$file && $tree && $p1_prefix ne '' &&
1788 -e "$root/$p1_prefix") {
1789 WARN("PATCH_PREFIX",
1790 "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
1793 if ($realfile =~ m@^include/asm/@) {
1794 ERROR("MODIFIED_INCLUDE_ASM",
1795 "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
1800 $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
1802 my $hereline = "$here\n$rawline\n";
1803 my $herecurr = "$here\n$rawline\n";
1804 my $hereprev = "$here\n$prevrawline\n$rawline\n";
1806 $cnt_lines++ if ($realcnt != 0);
1808 # Check for incorrect file permissions
1809 if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
1810 my $permhere = $here . "FILE: $realfile\n";
1811 if ($realfile !~ m@scripts/@ &&
1812 $realfile !~ /\.(py|pl|awk|sh)$/) {
1813 ERROR("EXECUTE_PERMISSIONS",
1814 "do not set execute permissions for source files\n" . $permhere);
1818 # Check the patch for a signoff:
1819 if ($line =~ /^\s*signed-off-by:/i) {
1824 # Check signature styles
1825 if (!$in_header_lines &&
1826 $line =~ /^(\s*)([a-z0-9_-]+by:|$signature_tags)(\s*)(.*)/i) {
1827 my $space_before = $1;
1829 my $space_after = $3;
1831 my $ucfirst_sign_off = ucfirst(lc($sign_off));
1833 if ($sign_off !~ /$signature_tags/) {
1834 WARN("BAD_SIGN_OFF",
1835 "Non-standard signature: $sign_off\n" . $herecurr);
1837 if (defined $space_before && $space_before ne "") {
1838 if (WARN("BAD_SIGN_OFF",
1839 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr) &&
1841 $fixed[$linenr - 1] =
1842 "$ucfirst_sign_off $email";
1845 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
1846 if (WARN("BAD_SIGN_OFF",
1847 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr) &&
1849 $fixed[$linenr - 1] =
1850 "$ucfirst_sign_off $email";
1854 if (!defined $space_after || $space_after ne " ") {
1855 if (WARN("BAD_SIGN_OFF",
1856 "Use a single space after $ucfirst_sign_off\n" . $herecurr) &&
1858 $fixed[$linenr - 1] =
1859 "$ucfirst_sign_off $email";
1863 my ($email_name, $email_address, $comment) = parse_email($email);
1864 my $suggested_email = format_email(($email_name, $email_address));
1865 if ($suggested_email eq "") {
1866 ERROR("BAD_SIGN_OFF",
1867 "Unrecognized email address: '$email'\n" . $herecurr);
1869 my $dequoted = $suggested_email;
1870 $dequoted =~ s/^"//;
1871 $dequoted =~ s/" </ </;
1872 # Don't force email to have quotes
1873 # Allow just an angle bracketed address
1874 if ("$dequoted$comment" ne $email &&
1875 "<$email_address>$comment" ne $email &&
1876 "$suggested_email$comment" ne $email) {
1877 WARN("BAD_SIGN_OFF",
1878 "email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr);
1882 # Check for duplicate signatures
1883 my $sig_nospace = $line;
1884 $sig_nospace =~ s/\s//g;
1885 $sig_nospace = lc($sig_nospace);
1886 if (defined $signatures{$sig_nospace}) {
1887 WARN("BAD_SIGN_OFF",
1888 "Duplicate signature\n" . $herecurr);
1890 $signatures{$sig_nospace} = 1;
1894 # Check for wrappage within a valid hunk of the file
1895 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
1896 ERROR("CORRUPTED_PATCH",
1897 "patch seems to be corrupt (line wrapped?)\n" .
1898 $herecurr) if (!$emitted_corrupt++);
1901 # Check for absolute kernel paths.
1903 while ($line =~ m{(?:^|\s)(/\S*)}g) {
1906 if ($file =~ m{^(.*?)(?::\d+)+:?$} &&
1907 check_absolute_file($1, $herecurr)) {
1910 check_absolute_file($file, $herecurr);
1915 # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
1916 if (($realfile =~ /^$/ || $line =~ /^\+/) &&
1917 $rawline !~ m/^$UTF8*$/) {
1918 my ($utf8_prefix) = ($rawline =~ /^($UTF8*)/);
1920 my $blank = copy_spacing($rawline);
1921 my $ptr = substr($blank, 0, length($utf8_prefix)) . "^";
1922 my $hereptr = "$hereline$ptr\n";
1925 "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
1928 # Check if it's the start of a commit log
1929 # (not a header line and we haven't seen the patch filename)
1930 if ($in_header_lines && $realfile =~ /^$/ &&
1931 $rawline !~ /^(commit\b|from\b|[\w-]+:).+$/i) {
1932 $in_header_lines = 0;
1936 # Check if there is UTF-8 in a commit log when a mail header has explicitly
1937 # declined it, i.e defined some charset where it is missing.
1938 if ($in_header_lines &&
1939 $rawline =~ /^Content-Type:.+charset="(.+)".*$/ &&
1941 $non_utf8_charset = 1;
1944 if ($in_commit_log && $non_utf8_charset && $realfile =~ /^$/ &&
1945 $rawline =~ /$NON_ASCII_UTF8/) {
1946 WARN("UTF8_BEFORE_PATCH",
1947 "8-bit UTF-8 used in possible commit log\n" . $herecurr);
1950 # ignore non-hunk lines and lines being removed
1951 next if (!$hunk_line || $line =~ /^-/);
1953 #trailing whitespace
1954 if ($line =~ /^\+.*\015/) {
1955 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1956 if (ERROR("DOS_LINE_ENDINGS",
1957 "DOS line endings\n" . $herevet) &&
1959 $fixed[$linenr - 1] =~ s/[\s\015]+$//;
1961 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
1962 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1963 if (ERROR("TRAILING_WHITESPACE",
1964 "trailing whitespace\n" . $herevet) &&
1966 $fixed[$linenr - 1] =~ s/\s+$//;
1972 # Check for FSF mailing addresses.
1973 if ($rawline =~ /\bwrite to the Free/i ||
1974 $rawline =~ /\b59\s+Temple\s+Pl/i ||
1975 $rawline =~ /\b51\s+Franklin\s+St/i) {
1976 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1977 my $msg_type = \&ERROR;
1978 $msg_type = \&CHK if ($file);
1979 &{$msg_type}("FSF_MAILING_ADDRESS",
1980 "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)
1983 # check for Kconfig help text having a real description
1984 # Only applies when adding the entry originally, after that we do not have
1985 # sufficient context to determine whether it is indeed long enough.
1986 if ($realfile =~ /Kconfig/ &&
1987 $line =~ /.\s*config\s+/) {
1990 my $ln = $linenr + 1;
1994 for (; $cnt > 0 && defined $lines[$ln - 1]; $ln++) {
1995 $f = $lines[$ln - 1];
1996 $cnt-- if ($lines[$ln - 1] !~ /^-/);
1997 $is_end = $lines[$ln - 1] =~ /^\+/;
1999 next if ($f =~ /^-/);
2001 if ($lines[$ln - 1] =~ /.\s*(?:bool|tristate)\s*\"/) {
2003 } elsif ($lines[$ln - 1] =~ /.\s*(?:---)?help(?:---)?$/) {
2010 next if ($f =~ /^$/);
2011 if ($f =~ /^\s*config\s/) {
2017 WARN("CONFIG_DESCRIPTION",
2018 "please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_start && $is_end && $length < 4);
2019 #print "is_start<$is_start> is_end<$is_end> length<$length>\n";
2022 # discourage the addition of CONFIG_EXPERIMENTAL in Kconfig.
2023 if ($realfile =~ /Kconfig/ &&
2024 $line =~ /.\s*depends on\s+.*\bEXPERIMENTAL\b/) {
2025 WARN("CONFIG_EXPERIMENTAL",
2026 "Use of CONFIG_EXPERIMENTAL is deprecated. For alternatives, see https://lkml.org/lkml/2012/10/23/580\n");
2029 if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) &&
2030 ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) {
2033 'EXTRA_AFLAGS' => 'asflags-y',
2034 'EXTRA_CFLAGS' => 'ccflags-y',
2035 'EXTRA_CPPFLAGS' => 'cppflags-y',
2036 'EXTRA_LDFLAGS' => 'ldflags-y',
2039 WARN("DEPRECATED_VARIABLE",
2040 "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag});
2043 # check we are in a valid source file if not then ignore this hunk
2044 next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);
2047 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
2048 $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
2049 !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:|,|\)\s*;)\s*$/ ||
2050 $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
2051 $length > $max_line_length)
2054 "line over $max_line_length characters\n" . $herecurr);
2057 # Check for user-visible strings broken across lines, which breaks the ability
2058 # to grep for the string. Make exceptions when the previous string ends in a
2059 # newline (multiple lines in one string constant) or '\t', '\r', ';', or '{'
2060 # (common in inline assembly) or is a octal \123 or hexadecimal \xaf value
2061 if ($line =~ /^\+\s*"/ &&
2062 $prevline =~ /"\s*$/ &&
2063 $prevrawline !~ /(?:\\(?:[ntr]|[0-7]{1,3}|x[0-9a-fA-F]{1,2})|;\s*|\{\s*)"\s*$/) {
2064 WARN("SPLIT_STRING",
2065 "quoted string split across lines\n" . $hereprev);
2068 # check for spaces before a quoted newline
2069 if ($rawline =~ /^.*\".*\s\\n/) {
2070 if (WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
2071 "unnecessary whitespace before a quoted newline\n" . $herecurr) &&
2073 $fixed[$linenr - 1] =~ s/^(\+.*\".*)\s+\\n/$1\\n/;
2078 # check for adding lines without a newline.
2079 if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
2080 WARN("MISSING_EOF_NEWLINE",
2081 "adding a line without newline at end of file\n" . $herecurr);
2084 # Blackfin: use hi/lo macros
2085 if ($realfile =~ m@arch/blackfin/.*\.S$@) {
2086 if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) {
2087 my $herevet = "$here\n" . cat_vet($line) . "\n";
2089 "use the LO() macro, not (... & 0xFFFF)\n" . $herevet);
2091 if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) {
2092 my $herevet = "$here\n" . cat_vet($line) . "\n";
2094 "use the HI() macro, not (... >> 16)\n" . $herevet);
2098 # check we are in a valid source file C or perl if not then ignore this hunk
2099 next if ($realfile !~ /\.(h|c|pl)$/);
2101 # at the beginning of a line any tabs must come first and anything
2102 # more than 8 must use tabs.
2103 if ($rawline =~ /^\+\s* \t\s*\S/ ||
2104 $rawline =~ /^\+\s* \s*/) {
2105 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
2107 if (ERROR("CODE_INDENT",
2108 "code indent should use tabs where possible\n" . $herevet) &&
2110 $fixed[$linenr - 1] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
2114 # check for space before tabs.
2115 if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
2116 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
2117 if (WARN("SPACE_BEFORE_TAB",
2118 "please, no space before tabs\n" . $herevet) &&
2120 while ($fixed[$linenr - 1] =~
2121 s/(^\+.*) {8,8}+\t/$1\t\t/) {}
2122 while ($fixed[$linenr - 1] =~
2123 s/(^\+.*) +\t/$1\t/) {}
2127 # check for && or || at the start of a line
2128 if ($rawline =~ /^\+\s*(&&|\|\|)/) {
2129 CHK("LOGICAL_CONTINUATIONS",
2130 "Logical continuations should be on the previous line\n" . $hereprev);
2133 # check multi-line statement indentation matches previous line
2134 if ($^V && $^V ge 5.10.0 &&
2135 $prevline =~ /^\+(\t*)(if \(|$Ident\().*(\&\&|\|\||,)\s*$/) {
2136 $prevline =~ /^\+(\t*)(.*)$/;
2140 my $pos = pos_last_openparen($rest);
2142 $line =~ /^(\+| )([ \t]*)/;
2145 my $goodtabindent = $oldindent .
2148 my $goodspaceindent = $oldindent . " " x $pos;
2150 if ($newindent ne $goodtabindent &&
2151 $newindent ne $goodspaceindent) {
2153 if (CHK("PARENTHESIS_ALIGNMENT",
2154 "Alignment should match open parenthesis\n" . $hereprev) &&
2155 $fix && $line =~ /^\+/) {
2156 $fixed[$linenr - 1] =~
2157 s/^\+[ \t]*/\+$goodtabindent/;
2163 if ($line =~ /^\+.*\*[ \t]*\)[ \t]+(?!$Assignment|$Arithmetic)/) {
2165 "No space is necessary after a cast\n" . $hereprev) &&
2167 $fixed[$linenr - 1] =~
2168 s/^(\+.*\*[ \t]*\))[ \t]+/$1/;
2172 if ($realfile =~ m@^(drivers/net/|net/)@ &&
2173 $prevrawline =~ /^\+[ \t]*\/\*[ \t]*$/ &&
2174 $rawline =~ /^\+[ \t]*\*/) {
2175 WARN("NETWORKING_BLOCK_COMMENT_STYLE",
2176 "networking block comments don't use an empty /* line, use /* Comment...\n" . $hereprev);
2179 if ($realfile =~ m@^(drivers/net/|net/)@ &&
2180 $prevrawline =~ /^\+[ \t]*\/\*/ && #starting /*
2181 $prevrawline !~ /\*\/[ \t]*$/ && #no trailing */
2182 $rawline =~ /^\+/ && #line is new
2183 $rawline !~ /^\+[ \t]*\*/) { #no leading *
2184 WARN("NETWORKING_BLOCK_COMMENT_STYLE",
2185 "networking block comments start with * on subsequent lines\n" . $hereprev);
2188 if ($realfile =~ m@^(drivers/net/|net/)@ &&
2189 $rawline !~ m@^\+[ \t]*\*/[ \t]*$@ && #trailing */
2190 $rawline !~ m@^\+.*/\*.*\*/[ \t]*$@ && #inline /*...*/
2191 $rawline !~ m@^\+.*\*{2,}/[ \t]*$@ && #trailing **/
2192 $rawline =~ m@^\+[ \t]*.+\*\/[ \t]*$@) { #non blank */
2193 WARN("NETWORKING_BLOCK_COMMENT_STYLE",
2194 "networking block comments put the trailing */ on a separate line\n" . $herecurr);
2197 # check for spaces at the beginning of a line.
2199 # 1) within comments
2200 # 2) indented preprocessor commands
2202 if ($rawline =~ /^\+ / && $line !~ /^\+ *(?:$;|#|$Ident:)/) {
2203 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
2204 if (WARN("LEADING_SPACE",
2205 "please, no spaces at the start of a line\n" . $herevet) &&
2207 $fixed[$linenr - 1] =~ s/^\+([ \t]+)/"\+" . tabify($1)/e;
2211 # check we are in a valid C source file if not then ignore this hunk
2212 next if ($realfile !~ /\.(h|c)$/);
2214 # discourage the addition of CONFIG_EXPERIMENTAL in #if(def).
2215 if ($line =~ /^\+\s*\#\s*if.*\bCONFIG_EXPERIMENTAL\b/) {
2216 WARN("CONFIG_EXPERIMENTAL",
2217 "Use of CONFIG_EXPERIMENTAL is deprecated. For alternatives, see https://lkml.org/lkml/2012/10/23/580\n");
2220 # check for RCS/CVS revision markers
2221 if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
2223 "CVS style keyword markers, these will _not_ be updated\n". $herecurr);
2226 # Blackfin: don't use __builtin_bfin_[cs]sync
2227 if ($line =~ /__builtin_bfin_csync/) {
2228 my $herevet = "$here\n" . cat_vet($line) . "\n";
2230 "use the CSYNC() macro in asm/blackfin.h\n" . $herevet);
2232 if ($line =~ /__builtin_bfin_ssync/) {
2233 my $herevet = "$here\n" . cat_vet($line) . "\n";
2235 "use the SSYNC() macro in asm/blackfin.h\n" . $herevet);
2238 # check for old HOTPLUG __dev<foo> section markings
2239 if ($line =~ /\b(__dev(init|exit)(data|const|))\b/) {
2240 WARN("HOTPLUG_SECTION",
2241 "Using $1 is unnecessary\n" . $herecurr);
2244 # Check for potential 'bare' types
2245 my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
2247 #print "LINE<$line>\n";
2248 if ($linenr >= $suppress_statement &&
2249 $realcnt && $sline =~ /.\s*\S/) {
2250 ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
2251 ctx_statement_block($linenr, $realcnt, 0);
2252 $stat =~ s/\n./\n /g;
2253 $cond =~ s/\n./\n /g;
2255 #print "linenr<$linenr> <$stat>\n";
2256 # If this statement has no statement boundaries within
2257 # it there is no point in retrying a statement scan
2258 # until we hit end of it.
2259 my $frag = $stat; $frag =~ s/;+\s*$//;
2260 if ($frag !~ /(?:{|;)/) {
2261 #print "skip<$line_nr_next>\n";
2262 $suppress_statement = $line_nr_next;
2265 # Find the real next line.
2266 $realline_next = $line_nr_next;
2267 if (defined $realline_next &&
2268 (!defined $lines[$realline_next - 1] ||
2269 substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
2276 # Ignore goto labels.
2277 if ($s =~ /$Ident:\*$/s) {
2279 # Ignore functions being called
2280 } elsif ($s =~ /^.\s*$Ident\s*\(/s) {
2282 } elsif ($s =~ /^.\s*else\b/s) {
2284 # declarations always start with types
2285 } 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) {
2288 possible($type, "A:" . $s);
2290 # definitions in global scope can only start with types
2291 } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b\s*(?!:)/s) {
2292 possible($1, "B:" . $s);
2295 # any (foo ... *) is a pointer cast, and foo is a type
2296 while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) {
2297 possible($1, "C:" . $s);
2300 # Check for any sort of function declaration.
2301 # int foo(something bar, other baz);
2302 # void (*store_gdt)(x86_descr_ptr *);
2303 if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/s) {
2304 my ($name_len) = length($1);
2307 substr($ctx, 0, $name_len + 1, '');
2308 $ctx =~ s/\)[^\)]*$//;
2310 for my $arg (split(/\s*,\s*/, $ctx)) {
2311 if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/s || $arg =~ /^($Ident)$/s) {
2313 possible($1, "D:" . $s);
2321 # Checks which may be anchored in the context.
2324 # Check for switch () and associated case and default
2325 # statements should be at the same indent.
2326 if ($line=~/\bswitch\s*\(.*\)/) {
2329 my @ctx = ctx_block_outer($linenr, $realcnt);
2331 for my $ctx (@ctx) {
2332 my ($clen, $cindent) = line_stats($ctx);
2333 if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
2334 $indent != $cindent) {
2335 $err .= "$sep$ctx\n";
2342 ERROR("SWITCH_CASE_INDENT_LEVEL",
2343 "switch and case should be at the same indent\n$hereline$err");
2347 # if/while/etc brace do not go on next line, unless defining a do while loop,
2348 # or if that brace on the next line is for something else
2349 if ($line =~ /(.*)\b((?:if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.\s*\#/) {
2350 my $pre_ctx = "$1$2";
2352 my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
2354 if ($line =~ /^\+\t{6,}/) {
2355 WARN("DEEP_INDENTATION",
2356 "Too many leading tabs - consider code refactoring\n" . $herecurr);
2359 my $ctx_cnt = $realcnt - $#ctx - 1;
2360 my $ctx = join("\n", @ctx);
2362 my $ctx_ln = $linenr;
2363 my $ctx_skip = $realcnt;
2365 while ($ctx_skip > $ctx_cnt || ($ctx_skip == $ctx_cnt &&
2366 defined $lines[$ctx_ln - 1] &&
2367 $lines[$ctx_ln - 1] =~ /^-/)) {
2368 ##print "SKIP<$ctx_skip> CNT<$ctx_cnt>\n";
2369 $ctx_skip-- if (!defined $lines[$ctx_ln - 1] || $lines[$ctx_ln - 1] !~ /^-/);
2373 #print "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
2374 #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
2376 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
2378 "that open brace { should be on the previous line\n" .
2379 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
2381 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
2382 $ctx =~ /\)\s*\;\s*$/ &&
2383 defined $lines[$ctx_ln - 1])
2385 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
2386 if ($nindent > $indent) {
2387 WARN("TRAILING_SEMICOLON",
2388 "trailing semicolon indicates no statements, indent implies otherwise\n" .
2389 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
2394 # Check relative indent for conditionals and blocks.
2395 if ($line =~ /\b(?:(?:if|while|for)\s*\(|do\b)/ && $line !~ /^.\s*#/ && $line !~ /\}\s*while\s*/) {
2396 ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
2397 ctx_statement_block($linenr, $realcnt, 0)
2398 if (!defined $stat);
2399 my ($s, $c) = ($stat, $cond);
2401 substr($s, 0, length($c), '');
2403 # Make sure we remove the line prefixes as we have
2404 # none on the first line, and are going to readd them
2408 # Find out how long the conditional actually is.
2409 my @newlines = ($c =~ /\n/gs);
2410 my $cond_lines = 1 + $#newlines;
2412 # We want to check the first line inside the block
2413 # starting at the end of the conditional, so remove:
2414 # 1) any blank line termination
2415 # 2) any opening brace { on end of the line
2417 my $continuation = 0;
2419 $s =~ s/^.*\bdo\b//;
2421 if ($s =~ s/^\s*\\//) {
2424 if ($s =~ s/^\s*?\n//) {
2429 # Also ignore a loop construct at the end of a
2430 # preprocessor statement.
2431 if (($prevline =~ /^.\s*#\s*define\s/ ||
2432 $prevline =~ /\\\s*$/) && $continuation == 0) {
2438 while ($cond_ptr != $cond_lines) {
2439 $cond_ptr = $cond_lines;
2441 # If we see an #else/#elif then the code
2443 if ($s =~ /^\s*\#\s*(?:else|elif)/) {
2448 # 1) blank lines, they should be at 0,
2449 # 2) preprocessor lines, and
2451 if ($continuation ||
2453 $s =~ /^\s*#\s*?/ ||
2454 $s =~ /^\s*$Ident\s*:/) {
2455 $continuation = ($s =~ /^.*?\\\n/) ? 1 : 0;
2456 if ($s =~ s/^.*?\n//) {
2462 my (undef, $sindent) = line_stats("+" . $s);
2463 my $stat_real = raw_line($linenr, $cond_lines);
2465 # Check if either of these lines are modified, else
2466 # this is not this patch's fault.
2467 if (!defined($stat_real) ||
2468 $stat !~ /^\+/ && $stat_real !~ /^\+/) {
2471 if (defined($stat_real) && $cond_lines > 1) {
2472 $stat_real = "[...]\n$stat_real";
2475 #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";
2477 if ($check && (($sindent % 8) != 0 ||
2478 ($sindent <= $indent && $s ne ''))) {
2479 WARN("SUSPECT_CODE_INDENT",
2480 "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
2484 # Track the 'values' across context and added lines.
2485 my $opline = $line; $opline =~ s/^./ /;
2486 my ($curr_values, $curr_vars) =
2487 annotate_values($opline . "\n", $prev_values);
2488 $curr_values = $prev_values . $curr_values;
2490 my $outline = $opline; $outline =~ s/\t/ /g;
2491 print "$linenr > .$outline\n";
2492 print "$linenr > $curr_values\n";
2493 print "$linenr > $curr_vars\n";
2495 $prev_values = substr($curr_values, -1);
2497 #ignore lines not being added
2498 next if ($line =~ /^[^\+]/);
2500 # TEST: allow direct testing of the type matcher.
2502 if ($line =~ /^.\s*$Declare\s*$/) {
2504 "TEST: is type\n" . $herecurr);
2505 } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) {
2506 ERROR("TEST_NOT_TYPE",
2507 "TEST: is not type ($1 is)\n". $herecurr);
2511 # TEST: allow direct testing of the attribute matcher.
2513 if ($line =~ /^.\s*$Modifier\s*$/) {
2515 "TEST: is attr\n" . $herecurr);
2516 } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) {
2517 ERROR("TEST_NOT_ATTR",
2518 "TEST: is not attr ($1 is)\n". $herecurr);
2523 # check for initialisation to aggregates open brace on the next line
2524 if ($line =~ /^.\s*{/ &&
2525 $prevline =~ /(?:^|[^=])=\s*$/) {
2527 "that open brace { should be on the previous line\n" . $hereprev);
2531 # Checks which are anchored on the added line.
2534 # check for malformed paths in #include statements (uses RAW line)
2535 if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
2537 if ($path =~ m{//}) {
2538 ERROR("MALFORMED_INCLUDE",
2539 "malformed #include filename\n" . $herecurr);
2541 if ($path =~ "^uapi/" && $realfile =~ m@\binclude/uapi/@) {
2542 ERROR("UAPI_INCLUDE",
2543 "No #include in ...include/uapi/... should use a uapi/ path prefix\n" . $herecurr);
2547 # no C99 // comments
2548 if ($line =~ m{//}) {
2549 if (ERROR("C99_COMMENTS",
2550 "do not use C99 // comments\n" . $herecurr) &&
2552 my $line = $fixed[$linenr - 1];
2553 if ($line =~ /\/\/(.*)$/) {
2554 my $comment = trim($1);
2555 $fixed[$linenr - 1] =~ s@\/\/(.*)$@/\* $comment \*/@;
2559 # Remove C99 comments.
2561 $opline =~ s@//.*@@;
2563 # EXPORT_SYMBOL should immediately follow the thing it is exporting, consider
2564 # the whole statement.
2565 #print "APW <$lines[$realline_next - 1]>\n";
2566 if (defined $realline_next &&
2567 exists $lines[$realline_next - 1] &&
2568 !defined $suppress_export{$realline_next} &&
2569 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
2570 $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
2571 # Handle definitions which produce identifiers with
2574 # EXPORT_SYMBOL(something_foo);
2576 if ($stat =~ /^(?:.\s*}\s*\n)?.([A-Z_]+)\s*\(\s*($Ident)/ &&
2577 $name =~ /^${Ident}_$2/) {
2578 #print "FOO C name<$name>\n";
2579 $suppress_export{$realline_next} = 1;
2581 } elsif ($stat !~ /(?:
2583 ^.DEFINE_$Ident\(\Q$name\E\)|
2584 ^.DECLARE_$Ident\(\Q$name\E\)|
2585 ^.LIST_HEAD\(\Q$name\E\)|
2586 ^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(|
2587 \b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\()
2589 #print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
2590 $suppress_export{$realline_next} = 2;
2592 $suppress_export{$realline_next} = 1;
2595 if (!defined $suppress_export{$linenr} &&
2596 $prevline =~ /^.\s*$/ &&
2597 ($line =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
2598 $line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
2599 #print "FOO B <$lines[$linenr - 1]>\n";
2600 $suppress_export{$linenr} = 2;
2602 if (defined $suppress_export{$linenr} &&
2603 $suppress_export{$linenr} == 2) {
2604 WARN("EXPORT_SYMBOL",
2605 "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
2608 # check for global initialisers.
2609 if ($line =~ /^\+(\s*$Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/) {
2610 if (ERROR("GLOBAL_INITIALISERS",
2611 "do not initialise globals to 0 or NULL\n" .
2614 $fixed[$linenr - 1] =~ s/($Type\s*$Ident\s*(?:\s+$Modifier))*\s*=\s*(0|NULL|false)\s*;/$1;/;
2617 # check for static initialisers.
2618 if ($line =~ /^\+.*\bstatic\s.*=\s*(0|NULL|false)\s*;/) {
2619 if (ERROR("INITIALISED_STATIC",
2620 "do not initialise statics to 0 or NULL\n" .
2623 $fixed[$linenr - 1] =~ s/(\bstatic\s.*?)\s*=\s*(0|NULL|false)\s*;/$1;/;
2627 # check for static const char * arrays.
2628 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
2629 WARN("STATIC_CONST_CHAR_ARRAY",
2630 "static const char * array should probably be static const char * const\n" .
2634 # check for static char foo[] = "bar" declarations.
2635 if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
2636 WARN("STATIC_CONST_CHAR_ARRAY",
2637 "static char array declaration should probably be static const char\n" .
2641 # check for uses of DEFINE_PCI_DEVICE_TABLE
2642 if ($line =~ /\bDEFINE_PCI_DEVICE_TABLE\s*\(\s*(\w+)\s*\)\s*=/) {
2643 if (WARN("DEFINE_PCI_DEVICE_TABLE",
2644 "Prefer struct pci_device_id over deprecated DEFINE_PCI_DEVICE_TABLE\n" . $herecurr) &&
2646 $fixed[$linenr - 1] =~ s/\b(?:static\s+|)DEFINE_PCI_DEVICE_TABLE\s*\(\s*(\w+)\s*\)\s*=\s*/static const struct pci_device_id $1\[\] = /;
2650 # check for new typedefs, only function parameters and sparse annotations
2652 if ($line =~ /\btypedef\s/ &&
2653 $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ &&
2654 $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
2655 $line !~ /\b$typeTypedefs\b/ &&
2656 $line !~ /\b__bitwise(?:__|)\b/) {
2657 WARN("NEW_TYPEDEFS",
2658 "do not add new typedefs\n" . $herecurr);
2661 # * goes on variable not on type
2663 while ($line =~ m{(\($NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)\))}g) {
2665 my ($ident, $from, $to) = ($1, $2, $2);
2667 # Should start with a space.
2668 $to =~ s/^(\S)/ $1/;
2669 # Should not end with a space.
2671 # '*'s should not have spaces between.
2672 while ($to =~ s/\*\s+\*/\*\*/) {
2675 ## print "1: from<$from> to<$to> ident<$ident>\n";
2677 if (ERROR("POINTER_LOCATION",
2678 "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr) &&
2680 my $sub_from = $ident;
2681 my $sub_to = $ident;
2682 $sub_to =~ s/\Q$from\E/$to/;
2683 $fixed[$linenr - 1] =~
2684 s@\Q$sub_from\E@$sub_to@;
2688 while ($line =~ m{(\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident))}g) {
2690 my ($match, $from, $to, $ident) = ($1, $2, $2, $3);
2692 # Should start with a space.
2693 $to =~ s/^(\S)/ $1/;
2694 # Should not end with a space.
2696 # '*'s should not have spaces between.
2697 while ($to =~ s/\*\s+\*/\*\*/) {
2699 # Modifiers should have spaces.
2700 $to =~ s/(\b$Modifier$)/$1 /;
2702 ## print "2: from<$from> to<$to> ident<$ident>\n";
2703 if ($from ne $to && $ident !~ /^$Modifier$/) {
2704 if (ERROR("POINTER_LOCATION",
2705 "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr) &&
2708 my $sub_from = $match;
2709 my $sub_to = $match;
2710 $sub_to =~ s/\Q$from\E/$to/;
2711 $fixed[$linenr - 1] =~
2712 s@\Q$sub_from\E@$sub_to@;
2717 # # no BUG() or BUG_ON()
2718 # if ($line =~ /\b(BUG|BUG_ON)\b/) {
2719 # print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n";
2720 # print "$herecurr";
2724 if ($line =~ /\bLINUX_VERSION_CODE\b/) {
2725 WARN("LINUX_VERSION_CODE",
2726 "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
2729 # check for uses of printk_ratelimit
2730 if ($line =~ /\bprintk_ratelimit\s*\(/) {
2731 WARN("PRINTK_RATELIMITED",
2732 "Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
2735 # printk should use KERN_* levels. Note that follow on printk's on the
2736 # same line do not need a level, so we use the current block context
2737 # to try and find and validate the current printk. In summary the current
2738 # printk includes all preceding printk's which have no newline on the end.
2739 # we assume the first bad printk is the one to report.
2740 if ($line =~ /\bprintk\((?!KERN_)\s*"/) {
2742 for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) {
2743 #print "CHECK<$lines[$ln - 1]\n";
2744 # we have a preceding printk if it ends
2745 # with "\n" ignore it, else it is to blame
2746 if ($lines[$ln - 1] =~ m{\bprintk\(}) {
2747 if ($rawlines[$ln - 1] !~ m{\\n"}) {
2754 WARN("PRINTK_WITHOUT_KERN_LEVEL",
2755 "printk() should include KERN_ facility level\n" . $herecurr);
2759 if ($line =~ /\bprintk\s*\(\s*KERN_([A-Z]+)/) {
2761 my $level = lc($orig);
2762 $level = "warn" if ($level eq "warning");
2763 my $level2 = $level;
2764 $level2 = "dbg" if ($level eq "debug");
2765 WARN("PREFER_PR_LEVEL",
2766 "Prefer netdev_$level2(netdev, ... then dev_$level2(dev, ... then pr_$level(... to printk(KERN_$orig ...\n" . $herecurr);
2769 if ($line =~ /\bpr_warning\s*\(/) {
2770 if (WARN("PREFER_PR_LEVEL",
2771 "Prefer pr_warn(... to pr_warning(...\n" . $herecurr) &&
2773 $fixed[$linenr - 1] =~
2774 s/\bpr_warning\b/pr_warn/;
2778 if ($line =~ /\bdev_printk\s*\(\s*KERN_([A-Z]+)/) {
2780 my $level = lc($orig);
2781 $level = "warn" if ($level eq "warning");
2782 $level = "dbg" if ($level eq "debug");
2783 WARN("PREFER_DEV_LEVEL",
2784 "Prefer dev_$level(... to dev_printk(KERN_$orig, ...\n" . $herecurr);
2787 # function brace can't be on same line, except for #defines of do while,
2788 # or if closed on same line
2789 if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and
2790 !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) {
2792 "open brace '{' following function declarations go on the next line\n" . $herecurr);
2795 # open braces for enum, union and struct go on the same line.
2796 if ($line =~ /^.\s*{/ &&
2797 $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
2799 "open brace '{' following $1 go on the same line\n" . $hereprev);
2802 # missing space after union, struct or enum definition
2803 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident){1,2}[=\{]/) {
2805 "missing space after $1 definition\n" . $herecurr) &&
2807 $fixed[$linenr - 1] =~
2808 s/^(.\s*(?:typedef\s+)?(?:enum|union|struct)(?:\s+$Ident){1,2})([=\{])/$1 $2/;
2812 # Function pointer declarations
2813 # check spacing between type, funcptr, and args
2814 # canonical declaration is "type (*funcptr)(args...)"
2816 # the $Declare variable will capture all spaces after the type
2817 # so check it for trailing missing spaces or multiple spaces
2818 if ($line =~ /^.\s*($Declare)\((\s*)\*(\s*)$Ident(\s*)\)(\s*)\(/) {
2820 my $pre_pointer_space = $2;
2821 my $post_pointer_space = $3;
2823 my $post_funcname_space = $5;
2824 my $pre_args_space = $6;
2826 if ($declare !~ /\s$/) {
2828 "missing space after return type\n" . $herecurr);
2831 # unnecessary space "type (*funcptr)(args...)"
2832 elsif ($declare =~ /\s{2,}$/) {
2834 "Multiple spaces after return type\n" . $herecurr);
2837 # unnecessary space "type ( *funcptr)(args...)"
2838 if (defined $pre_pointer_space &&
2839 $pre_pointer_space =~ /^\s/) {
2841 "Unnecessary space after function pointer open parenthesis\n" . $herecurr);
2844 # unnecessary space "type (* funcptr)(args...)"
2845 if (defined $post_pointer_space &&
2846 $post_pointer_space =~ /^\s/) {
2848 "Unnecessary space before function pointer name\n" . $herecurr);
2851 # unnecessary space "type (*funcptr )(args...)"
2852 if (defined $post_funcname_space &&
2853 $post_funcname_space =~ /^\s/) {
2855 "Unnecessary space after function pointer name\n" . $herecurr);
2858 # unnecessary space "type (*funcptr) (args...)"
2859 if (defined $pre_args_space &&
2860 $pre_args_space =~ /^\s/) {
2862 "Unnecessary space before function pointer arguments\n" . $herecurr);
2865 if (show_type("SPACING") && $fix) {
2866 $fixed[$linenr - 1] =~
2867 s/^(.\s*$Declare)\(\s*\*\s*($Ident)\s*\)\s*\(/rtrim($1) . " " . "\(\*$2\)\("/ex;
2871 # check for spacing round square brackets; allowed:
2872 # 1. with a type on the left -- int [] a;
2873 # 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
2874 # 3. inside a curly brace -- = { [0...10] = 5 }
2875 while ($line =~ /(.*?\s)\[/g) {
2876 my ($where, $prefix) = ($-[1], $1);
2877 if ($prefix !~ /$Type\s+$/ &&
2878 ($where != 0 || $prefix !~ /^.\s+$/) &&
2879 $prefix !~ /[{,]\s+$/) {
2880 if (ERROR("BRACKET_SPACE",
2881 "space prohibited before open square bracket '['\n" . $herecurr) &&
2883 $fixed[$linenr - 1] =~
2884 s/^(\+.*?)\s+\[/$1\[/;
2889 # check for spaces between functions and their parentheses.
2890 while ($line =~ /($Ident)\s+\(/g) {
2892 my $ctx_before = substr($line, 0, $-[1]);
2893 my $ctx = "$ctx_before$name";
2895 # Ignore those directives where spaces _are_ permitted.
2897 if|for|while|switch|return|case|
2898 volatile|__volatile__|
2899 __attribute__|format|__extension__|
2902 # cpp #define statements have non-optional spaces, ie
2903 # if there is a space between the name and the open
2904 # parenthesis it is simply not a parameter group.
2905 } elsif ($ctx_before =~ /^.\s*\#\s*define\s*$/) {
2907 # cpp #elif statement condition may start with a (
2908 } elsif ($ctx =~ /^.\s*\#\s*elif\s*$/) {
2910 # If this whole things ends with a type its most
2911 # likely a typedef for a function.
2912 } elsif ($ctx =~ /$Type$/) {
2916 "space prohibited between function name and open parenthesis '('\n" . $herecurr) &&
2918 $fixed[$linenr - 1] =~
2919 s/\b$name\s+\(/$name\(/;
2924 # Check operator spacing.
2925 if (!($line=~/\#\s*include/)) {
2926 my $fixed_line = "";
2930 <<=|>>=|<=|>=|==|!=|
2931 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
2932 =>|->|<<|>>|<|>|=|!|~|
2933 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%|
2936 my @elements = split(/($ops|;)/, $opline);
2938 ## print("element count: <" . $#elements . ">\n");
2939 ## foreach my $el (@elements) {
2940 ## print("el: <$el>\n");
2943 my @fix_elements = ();
2946 foreach my $el (@elements) {
2947 push(@fix_elements, substr($rawline, $off, length($el)));
2948 $off += length($el);
2953 my $blank = copy_spacing($opline);
2954 my $last_after = -1;
2956 for (my $n = 0; $n < $#elements; $n += 2) {
2958 my $good = $fix_elements[$n] . $fix_elements[$n + 1];
2960 ## print("n: <$n> good: <$good>\n");
2962 $off += length($elements[$n]);
2964 # Pick up the preceding and succeeding characters.
2965 my $ca = substr($opline, 0, $off);
2967 if (length($opline) >= ($off + length($elements[$n + 1]))) {
2968 $cc = substr($opline, $off + length($elements[$n + 1]));
2970 my $cb = "$ca$;$cc";
2973 $a = 'V' if ($elements[$n] ne '');
2974 $a = 'W' if ($elements[$n] =~ /\s$/);
2975 $a = 'C' if ($elements[$n] =~ /$;$/);
2976 $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
2977 $a = 'O' if ($elements[$n] eq '');
2978 $a = 'E' if ($ca =~ /^\s*$/);
2980 my $op = $elements[$n + 1];
2983 if (defined $elements[$n + 2]) {
2984 $c = 'V' if ($elements[$n + 2] ne '');
2985 $c = 'W' if ($elements[$n + 2] =~ /^\s/);
2986 $c = 'C' if ($elements[$n + 2] =~ /^$;/);
2987 $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
2988 $c = 'O' if ($elements[$n + 2] eq '');
2989 $c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/);
2994 my $ctx = "${a}x${c}";
2996 my $at = "(ctx:$ctx)";
2998 my $ptr = substr($blank, 0, $off) . "^";
2999 my $hereptr = "$hereline$ptr\n";
3001 # Pull out the value of this operator.
3002 my $op_type = substr($curr_values, $off + 1, 1);
3004 # Get the full operator variant.
3005 my $opv = $op . substr($curr_vars, $off, 1);
3007 # Ignore operators passed as parameters.
3008 if ($op_type ne 'V' &&
3009 $ca =~ /\s$/ && $cc =~ /^\s*,/) {
3012 # } elsif ($op =~ /^$;+$/) {
3014 # ; should have either the end of line or a space or \ after it
3015 } elsif ($op eq ';') {
3016 if ($ctx !~ /.x[WEBC]/ &&
3017 $cc !~ /^\\/ && $cc !~ /^;/) {
3018 if (ERROR("SPACING",
3019 "space required after that '$op' $at\n" . $hereptr)) {
3020 $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
3026 } elsif ($op eq '//') {
3030 # : when part of a bitfield
3031 } elsif ($op eq '->' || $opv eq ':B') {
3032 if ($ctx =~ /Wx.|.xW/) {
3033 if (ERROR("SPACING",
3034 "spaces prohibited around that '$op' $at\n" . $hereptr)) {
3035 $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
3036 if (defined $fix_elements[$n + 2]) {
3037 $fix_elements[$n + 2] =~ s/^\s+//;
3043 # , must have a space on the right.
3044 } elsif ($op eq ',') {
3045 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
3046 if (ERROR("SPACING",
3047 "space required after that '$op' $at\n" . $hereptr)) {
3048 $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
3054 # '*' as part of a type definition -- reported already.
3055 } elsif ($opv eq '*_') {
3056 #warn "'*' is part of type\n";
3058 # unary operators should have a space before and
3059 # none after. May be left adjacent to another
3060 # unary operator, or a cast
3061 } elsif ($op eq '!' || $op eq '~' ||
3062 $opv eq '*U' || $opv eq '-U' ||
3063 $opv eq '&U' || $opv eq '&&U') {
3064 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
3065 if (ERROR("SPACING",
3066 "space required before that '$op' $at\n" . $hereptr)) {
3067 if ($n != $last_after + 2) {
3068 $good = $fix_elements[$n] . " " . ltrim($fix_elements[$n + 1]);
3073 if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
3074 # A unary '*' may be const
3076 } elsif ($ctx =~ /.xW/) {
3077 if (ERROR("SPACING",
3078 "space prohibited after that '$op' $at\n" . $hereptr)) {
3079 $good = $fix_elements[$n] . rtrim($fix_elements[$n + 1]);
3080 if (defined $fix_elements[$n + 2]) {
3081 $fix_elements[$n + 2] =~ s/^\s+//;
3087 # unary ++ and unary -- are allowed no space on one side.
3088 } elsif ($op eq '++' or $op eq '--') {
3089 if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
3090 if (ERROR("SPACING",
3091 "space required one side of that '$op' $at\n" . $hereptr)) {
3092 $good = $fix_elements[$n] . trim($fix_elements[$n + 1]) . " ";
3096 if ($ctx =~ /Wx[BE]/ ||
3097 ($ctx =~ /Wx./ && $cc =~ /^;/)) {
3098 if (ERROR("SPACING",
3099 "space prohibited before that '$op' $at\n" . $hereptr)) {
3100 $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
3104 if ($ctx =~ /ExW/) {
3105 if (ERROR("SPACING",
3106 "space prohibited after that '$op' $at\n" . $hereptr)) {
3107 $good = $fix_elements[$n] . trim($fix_elements[$n + 1]);
3108 if (defined $fix_elements[$n + 2]) {
3109 $fix_elements[$n + 2] =~ s/^\s+//;
3115 # << and >> may either have or not have spaces both sides
3116 } elsif ($op eq '<<' or $op eq '>>' or
3117 $op eq '&' or $op eq '^' or $op eq '|' or
3118 $op eq '+' or $op eq '-' or
3119 $op eq '*' or $op eq '/' or
3122 if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
3123 if (ERROR("SPACING",
3124 "need consistent spacing around '$op' $at\n" . $hereptr)) {
3125 $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
3126 if (defined $fix_elements[$n + 2]) {
3127 $fix_elements[$n + 2] =~ s/^\s+//;
3133 # A colon needs no spaces before when it is
3134 # terminating a case value or a label.
3135 } elsif ($opv eq ':C' || $opv eq ':L') {
3136 if ($ctx =~ /Wx./) {
3137 if (ERROR("SPACING",
3138 "space prohibited before that '$op' $at\n" . $hereptr)) {
3139 $good = rtrim($fix_elements[$n]) . trim($fix_elements[$n + 1]);
3144 # All the others need spaces both sides.
3145 } elsif ($ctx !~ /[EWC]x[CWE]/) {
3148 # Ignore email addresses <foo@bar>
3150 $cc =~ /^\S+\@\S+>/) ||
3152 $ca =~ /<\S+\@\S+$/))
3157 # messages are ERROR, but ?: are CHK
3159 my $msg_type = \&ERROR;
3160 $msg_type = \&CHK if (($op eq '?:' || $op eq '?' || $op eq ':') && $ctx =~ /VxV/);
3162 if (&{$msg_type}("SPACING",
3163 "spaces required around that '$op' $at\n" . $hereptr)) {
3164 $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
3165 if (defined $fix_elements[$n + 2]) {
3166 $fix_elements[$n + 2] =~ s/^\s+//;
3172 $off += length($elements[$n + 1]);
3174 ## print("n: <$n> GOOD: <$good>\n");
3176 $fixed_line = $fixed_line . $good;
3179 if (($#elements % 2) == 0) {
3180 $fixed_line = $fixed_line . $fix_elements[$#elements];
3183 if ($fix && $line_fixed && $fixed_line ne $fixed[$linenr - 1]) {
3184 $fixed[$linenr - 1] = $fixed_line;
3190 # check for whitespace before a non-naked semicolon
3191 if ($line =~ /^\+.*\S\s+;\s*$/) {
3193 "space prohibited before semicolon\n" . $herecurr) &&
3195 1 while $fixed[$linenr - 1] =~
3196 s/^(\+.*\S)\s+;/$1;/;
3200 # check for multiple assignments
3201 if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
3202 CHK("MULTIPLE_ASSIGNMENTS",
3203 "multiple assignments should be avoided\n" . $herecurr);
3206 ## # check for multiple declarations, allowing for a function declaration
3208 ## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
3209 ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
3211 ## # Remove any bracketed sections to ensure we do not
3212 ## # falsly report the parameters of functions.
3214 ## while ($ln =~ s/\([^\(\)]*\)//g) {
3216 ## if ($ln =~ /,/) {
3217 ## WARN("MULTIPLE_DECLARATION",
3218 ## "declaring multiple variables together should be avoided\n" . $herecurr);
3222 #need space before brace following if, while, etc
3223 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) ||
3225 if (ERROR("SPACING",
3226 "space required before the open brace '{'\n" . $herecurr) &&
3228 $fixed[$linenr - 1] =~ s/^(\+.*(?:do|\))){/$1 {/;
3232 ## # check for blank lines before declarations
3233 ## if ($line =~ /^.\t+$Type\s+$Ident(?:\s*=.*)?;/ &&
3234 ## $prevrawline =~ /^.\s*$/) {
3236 ## "No blank lines before declarations\n" . $hereprev);
3240 # closing brace should have a space following it when it has anything
3242 if ($line =~ /}(?!(?:,|;|\)))\S/) {
3243 if (ERROR("SPACING",
3244 "space required after that close brace '}'\n" . $herecurr) &&
3246 $fixed[$linenr - 1] =~
3247 s/}((?!(?:,|;|\)))\S)/} $1/;
3251 # check spacing on square brackets
3252 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
3253 if (ERROR("SPACING",
3254 "space prohibited after that open square bracket '['\n" . $herecurr) &&
3256 $fixed[$linenr - 1] =~
3260 if ($line =~ /\s\]/) {
3261 if (ERROR("SPACING",
3262 "space prohibited before that close square bracket ']'\n" . $herecurr) &&
3264 $fixed[$linenr - 1] =~
3269 # check spacing on parentheses
3270 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
3271 $line !~ /for\s*\(\s+;/) {
3272 if (ERROR("SPACING",
3273 "space prohibited after that open parenthesis '('\n" . $herecurr) &&
3275 $fixed[$linenr - 1] =~
3279 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
3280 $line !~ /for\s*\(.*;\s+\)/ &&
3281 $line !~ /:\s+\)/) {
3282 if (ERROR("SPACING",
3283 "space prohibited before that close parenthesis ')'\n" . $herecurr) &&
3285 $fixed[$linenr - 1] =~
3290 #goto labels aren't indented, allow a single space however
3291 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
3292 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
3293 if (WARN("INDENTED_LABEL",
3294 "labels should not be indented\n" . $herecurr) &&
3296 $fixed[$linenr - 1] =~
3301 # Return is not a function.
3302 if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
3304 if ($^V && $^V ge 5.10.0 &&
3305 $stat =~ /^.\s*return\s*$balanced_parens\s*;\s*$/) {
3306 ERROR("RETURN_PARENTHESES",
3307 "return is not a function, parentheses are not required\n" . $herecurr);
3309 } elsif ($spacing !~ /\s+/) {
3311 "space required before the open parenthesis '('\n" . $herecurr);
3315 # if statements using unnecessary parentheses - ie: if ((foo == bar))
3316 if ($^V && $^V ge 5.10.0 &&
3317 $line =~ /\bif\s*((?:\(\s*){2,})/) {
3318 my $openparens = $1;
3319 my $count = $openparens =~ tr@\(@\(@;
3321 if ($line =~ /\bif\s*(?:\(\s*){$count,$count}$LvalOrFunc\s*($Compare)\s*$LvalOrFunc(?:\s*\)){$count,$count}/) {
3322 my $comp = $4; #Not $1 because of $LvalOrFunc
3323 $msg = " - maybe == should be = ?" if ($comp eq "==");
3324 WARN("UNNECESSARY_PARENTHESES",
3325 "Unnecessary parentheses$msg\n" . $herecurr);
3329 # Return of what appears to be an errno should normally be -'ve
3330 if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
3332 if ($name ne 'EOF' && $name ne 'ERROR') {
3333 WARN("USE_NEGATIVE_ERRNO",
3334 "return of an errno should typically be -ve (return -$1)\n" . $herecurr);
3338 # Need a space before open parenthesis after if, while etc
3339 if ($line =~ /\b(if|while|for|switch)\(/) {
3340 if (ERROR("SPACING",
3341 "space required before the open parenthesis '('\n" . $herecurr) &&
3343 $fixed[$linenr - 1] =~
3344 s/\b(if|while|for|switch)\(/$1 \(/;
3348 # Check for illegal assignment in if conditional -- and check for trailing
3349 # statements after the conditional.
3350 if ($line =~ /do\s*(?!{)/) {
3351 ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
3352 ctx_statement_block($linenr, $realcnt, 0)
3353 if (!defined $stat);
3354 my ($stat_next) = ctx_statement_block($line_nr_next,
3355 $remain_next, $off_next);
3356 $stat_next =~ s/\n./\n /g;
3357 ##print "stat<$stat> stat_next<$stat_next>\n";
3359 if ($stat_next =~ /^\s*while\b/) {
3360 # If the statement carries leading newlines,
3361 # then count those as offsets.
3363 ($stat_next =~ /^((?:\s*\n[+-])*\s*)/s);
3365 statement_rawlines($whitespace) - 1;
3367 $suppress_whiletrailers{$line_nr_next +
3371 if (!defined $suppress_whiletrailers{$linenr} &&
3372 defined($stat) && defined($cond) &&
3373 $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) {
3374 my ($s, $c) = ($stat, $cond);
3376 if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
3377 ERROR("ASSIGN_IN_IF",
3378 "do not use assignment in if condition\n" . $herecurr);
3381 # Find out what is on the end of the line after the
3383 substr($s, 0, length($c), '');
3385 $s =~ s/$;//g; # Remove any comments
3386 if (length($c) && $s !~ /^\s*{?\s*\\*\s*$/ &&
3387 $c !~ /}\s*while\s*/)
3389 # Find out how long the conditional actually is.
3390 my @newlines = ($c =~ /\n/gs);
3391 my $cond_lines = 1 + $#newlines;
3394 $stat_real = raw_line($linenr, $cond_lines)
3395 . "\n" if ($cond_lines);
3396 if (defined($stat_real) && $cond_lines > 1) {
3397 $stat_real = "[...]\n$stat_real";
3400 ERROR("TRAILING_STATEMENTS",
3401 "trailing statements should be on next line\n" . $herecurr . $stat_real);
3405 # Check for bitwise tests written as boolean
3417 WARN("HEXADECIMAL_BOOLEAN_TEST",
3418 "boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
3421 # if and else should not have general statements after it
3422 if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
3424 $s =~ s/$;//g; # Remove any comments
3425 if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
3426 ERROR("TRAILING_STATEMENTS",
3427 "trailing statements should be on next line\n" . $herecurr);
3430 # if should not continue a brace
3431 if ($line =~ /}\s*if\b/) {
3432 ERROR("TRAILING_STATEMENTS",
3433 "trailing statements should be on next line\n" .
3436 # case and default should not have general statements after them
3437 if ($line =~ /^.\s*(?:case\s*.*|default\s*):/g &&
3439 (?:\s*$;*)(?:\s*{)?(?:\s*$;*)(?:\s*\\)?\s*$|
3443 ERROR("TRAILING_STATEMENTS",
3444 "trailing statements should be on next line\n" . $herecurr);
3447 # Check for }<nl>else {, these must be at the same
3448 # indent level to be relevant to each other.
3449 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
3450 $previndent == $indent) {
3451 ERROR("ELSE_AFTER_BRACE",
3452 "else should follow close brace '}'\n" . $hereprev);
3455 if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and
3456 $previndent == $indent) {
3457 my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
3459 # Find out what is on the end of the line after the
3461 substr($s, 0, length($c), '');
3464 if ($s =~ /^\s*;/) {
3465 ERROR("WHILE_AFTER_BRACE",
3466 "while should follow close brace '}'\n" . $hereprev);
3470 #Specific variable tests
3471 while ($line =~ m{($Constant|$Lval)}g) {
3474 #gcc binary extension
3475 if ($var =~ /^$Binary$/) {
3476 if (WARN("GCC_BINARY_CONSTANT",
3477 "Avoid gcc v4.3+ binary constant extension: <$var>\n" . $herecurr) &&
3479 my $hexval = sprintf("0x%x", oct($var));
3480 $fixed[$linenr - 1] =~
3481 s/\b$var\b/$hexval/;
3486 if ($var !~ /^$Constant$/ &&
3487 $var =~ /[A-Z][a-z]|[a-z][A-Z]/ &&
3488 #Ignore Page<foo> variants
3489 $var !~ /^(?:Clear|Set|TestClear|TestSet|)Page[A-Z]/ &&
3490 #Ignore SI style variants like nS, mV and dB (ie: max_uV, regulator_min_uA_show)
3491 $var !~ /^(?:[a-z_]*?)_?[a-z][A-Z](?:_[a-z_]+)?$/) {
3492 while ($var =~ m{($Ident)}g) {
3494 next if ($word !~ /[A-Z][a-z]|[a-z][A-Z]/);
3496 seed_camelcase_includes();
3497 if (!$file && !$camelcase_file_seeded) {
3498 seed_camelcase_file($realfile);
3499 $camelcase_file_seeded = 1;
3502 if (!defined $camelcase{$word}) {
3503 $camelcase{$word} = 1;
3505 "Avoid CamelCase: <$word>\n" . $herecurr);
3511 #no spaces allowed after \ in define
3512 if ($line =~ /\#\s*define.*\\\s+$/) {
3513 if (WARN("WHITESPACE_AFTER_LINE_CONTINUATION",
3514 "Whitespace after \\ makes next lines useless\n" . $herecurr) &&
3516 $fixed[$linenr - 1] =~ s/\s+$//;
3520 #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
3521 if ($tree && $rawline =~ m{^.\s*\#\s*include\s*\<asm\/(.*)\.h\>}) {
3523 my $checkfile = "include/linux/$file";
3524 if (-f "$root/$checkfile" &&
3525 $realfile ne $checkfile &&
3526 $1 !~ /$allowed_asm_includes/)
3528 if ($realfile =~ m{^arch/}) {
3529 CHK("ARCH_INCLUDE_LINUX",
3530 "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
3532 WARN("INCLUDE_LINUX",
3533 "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
3538 # multi-statement macros should be enclosed in a do while loop, grab the
3539 # first statement and ensure its the whole macro if its not enclosed
3540 # in a known good container
3541 if ($realfile !~ m@/vmlinux.lds.h$@ &&
3542 $line =~ /^.\s*\#\s*define\s*$Ident(\()?/) {
3545 my ($off, $dstat, $dcond, $rest);
3547 ($dstat, $dcond, $ln, $cnt, $off) =
3548 ctx_statement_block($linenr, $realcnt, 0);
3550 #print "dstat<$dstat> dcond<$dcond> cnt<$cnt> off<$off>\n";
3551 #print "LINE<$lines[$ln-1]> len<" . length($lines[$ln-1]) . "\n";
3553 $dstat =~ s/^.\s*\#\s*define\s+$Ident(?:\([^\)]*\))?\s*//;
3555 $dstat =~ s/\\\n.//g;
3556 $dstat =~ s/^\s*//s;
3557 $dstat =~ s/\s*$//s;
3559 # Flatten any parentheses and braces
3560 while ($dstat =~ s/\([^\(\)]*\)/1/ ||
3561 $dstat =~ s/\{[^\{\}]*\}/1/ ||
3562 $dstat =~ s/\[[^\[\]]*\]/1/)
3566 # Flatten any obvious string concatentation.
3567 while ($dstat =~ s/("X*")\s*$Ident/$1/ ||
3568 $dstat =~ s/$Ident\s*("X*")/$1/)
3572 my $exceptions = qr{
3584 #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
3586 $dstat !~ /^(?:$Ident|-?$Constant),$/ && # 10, // foo(),
3587 $dstat !~ /^(?:$Ident|-?$Constant);$/ && # foo();
3588 $dstat !~ /^[!~-]?(?:$Lval|$Constant)$/ && # 10 // foo() // !foo // ~foo // -foo // foo->bar // foo.bar->baz
3589 $dstat !~ /^'X'$/ && # character constants
3590 $dstat !~ /$exceptions/ &&
3591 $dstat !~ /^\.$Ident\s*=/ && # .foo =
3592 $dstat !~ /^(?:\#\s*$Ident|\#\s*$Constant)\s*$/ && # stringification #foo
3593 $dstat !~ /^do\s*$Constant\s*while\s*$Constant;?$/ && # do {...} while (...); // do {...} while (...)
3594 $dstat !~ /^for\s*$Constant$/ && # for (...)
3595 $dstat !~ /^for\s*$Constant\s+(?:$Ident|-?$Constant)$/ && # for (...) bar()
3596 $dstat !~ /^do\s*{/ && # do {...
3597 $dstat !~ /^\({/ && # ({...
3598 $ctx !~ /^.\s*#\s*define\s+TRACE_(?:SYSTEM|INCLUDE_FILE|INCLUDE_PATH)\b/)
3601 my $herectx = $here . "\n";
3602 my $cnt = statement_rawlines($ctx);
3604 for (my $n = 0; $n < $cnt; $n++) {
3605 $herectx .= raw_line($linenr, $n) . "\n";
3608 if ($dstat =~ /;/) {
3609 ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
3610 "Macros with multiple statements should be enclosed in a do - while loop\n" . "$herectx");
3612 ERROR("COMPLEX_MACRO",
3613 "Macros with complex values should be enclosed in parenthesis\n" . "$herectx");
3617 # check for line continuations outside of #defines, preprocessor #, and asm
3620 if ($prevline !~ /^..*\\$/ &&
3621 $line !~ /^\+\s*\#.*\\$/ && # preprocessor
3622 $line !~ /^\+.*\b(__asm__|asm)\b.*\\$/ && # asm
3623 $line =~ /^\+.*\\$/) {
3624 WARN("LINE_CONTINUATIONS",
3625 "Avoid unnecessary line continuations\n" . $herecurr);
3629 # do {} while (0) macro tests:
3630 # single-statement macros do not need to be enclosed in do while (0) loop,
3631 # macro should not end with a semicolon
3632 if ($^V && $^V ge 5.10.0 &&
3633 $realfile !~ m@/vmlinux.lds.h$@ &&
3634 $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) {
3637 my ($off, $dstat, $dcond, $rest);
3639 ($dstat, $dcond, $ln, $cnt, $off) =
3640 ctx_statement_block($linenr, $realcnt, 0);
3643 $dstat =~ s/\\\n.//g;
3645 if ($dstat =~ /^\+\s*#\s*define\s+$Ident\s*${balanced_parens}\s*do\s*{(.*)\s*}\s*while\s*\(\s*0\s*\)\s*([;\s]*)\s*$/) {
3650 my $cnt = statement_rawlines($ctx);
3651 my $herectx = $here . "\n";
3653 for (my $n = 0; $n < $cnt; $n++) {
3654 $herectx .= raw_line($linenr, $n) . "\n";
3657 if (($stmts =~ tr/;/;/) == 1 &&
3658 $stmts !~ /^\s*(if|while|for|switch)\b/) {
3659 WARN("SINGLE_STATEMENT_DO_WHILE_MACRO",
3660 "Single statement macros should not use a do {} while (0) loop\n" . "$herectx");
3662 if (defined $semis && $semis ne "") {
3663 WARN("DO_WHILE_MACRO_WITH_TRAILING_SEMICOLON",
3664 "do {} while (0) macros should not be semicolon terminated\n" . "$herectx");
3669 # make sure symbols are always wrapped with VMLINUX_SYMBOL() ...
3670 # all assignments may have only one of the following with an assignment:
3673 # VMLINUX_SYMBOL(...)
3674 if ($realfile eq 'vmlinux.lds.h' && $line =~ /(?:(?:^|\s)$Ident\s*=|=\s*$Ident(?:\s|$))/) {
3675 WARN("MISSING_VMLINUX_SYMBOL",
3676 "vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr);
3679 # check for redundant bracing round if etc
3680 if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
3681 my ($level, $endln, @chunks) =
3682 ctx_statement_full($linenr, $realcnt, 1);
3683 #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
3684 #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
3685 if ($#chunks > 0 && $level == 0) {
3689 my $herectx = $here . "\n";
3690 my $ln = $linenr - 1;
3691 for my $chunk (@chunks) {
3692 my ($cond, $block) = @{$chunk};
3694 # If the condition carries leading newlines, then count those as offsets.
3695 my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
3696 my $offset = statement_rawlines($whitespace) - 1;
3698 $allowed[$allow] = 0;
3699 #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
3701 # We have looked at and allowed this specific line.
3702 $suppress_ifbraces{$ln + $offset} = 1;
3704 $herectx .= "$rawlines[$ln + $offset]\n[...]\n";
3705 $ln += statement_rawlines($block) - 1;
3707 substr($block, 0, length($cond), '');
3709 $seen++ if ($block =~ /^\s*{/);
3711 #print "cond<$cond> block<$block> allowed<$allowed[$allow]>\n";
3712 if (statement_lines($cond) > 1) {
3713 #print "APW: ALLOWED: cond<$cond>\n";
3714 $allowed[$allow] = 1;
3716 if ($block =~/\b(?:if|for|while)\b/) {
3717 #print "APW: ALLOWED: block<$block>\n";
3718 $allowed[$allow] = 1;
3720 if (statement_block_size($block) > 1) {
3721 #print "APW: ALLOWED: lines block<$block>\n";
3722 $allowed[$allow] = 1;
3727 my $sum_allowed = 0;
3728 foreach (@allowed) {
3731 if ($sum_allowed == 0) {
3733 "braces {} are not necessary for any arm of this statement\n" . $herectx);
3734 } elsif ($sum_allowed != $allow &&
3737 "braces {} should be used on all arms of this statement\n" . $herectx);
3742 if (!defined $suppress_ifbraces{$linenr - 1} &&
3743 $line =~ /\b(if|while|for|else)\b/) {
3746 # Check the pre-context.
3747 if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
3748 #print "APW: ALLOWED: pre<$1>\n";
3752 my ($level, $endln, @chunks) =
3753 ctx_statement_full($linenr, $realcnt, $-[0]);
3755 # Check the condition.
3756 my ($cond, $block) = @{$chunks[0]};
3757 #print "CHECKING<$linenr> cond<$cond> block<$block>\n";
3758 if (defined $cond) {
3759 substr($block, 0, length($cond), '');
3761 if (statement_lines($cond) > 1) {
3762 #print "APW: ALLOWED: cond<$cond>\n";
3765 if ($block =~/\b(?:if|for|while)\b/) {
3766 #print "APW: ALLOWED: block<$block>\n";
3769 if (statement_block_size($block) > 1) {
3770 #print "APW: ALLOWED: lines block<$block>\n";
3773 # Check the post-context.
3774 if (defined $chunks[1]) {
3775 my ($cond, $block) = @{$chunks[1]};
3776 if (defined $cond) {
3777 substr($block, 0, length($cond), '');
3779 if ($block =~ /^\s*\{/) {
3780 #print "APW: ALLOWED: chunk-1 block<$block>\n";
3784 if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
3785 my $herectx = $here . "\n";
3786 my $cnt = statement_rawlines($block);
3788 for (my $n = 0; $n < $cnt; $n++) {
3789 $herectx .= raw_line($linenr, $n) . "\n";
3793 "braces {} are not necessary for single statement blocks\n" . $herectx);
3797 # check for unnecessary blank lines around braces
3798 if (($line =~ /^.\s*}\s*$/ && $prevrawline =~ /^.\s*$/)) {
3800 "Blank lines aren't necessary before a close brace '}'\n" . $hereprev);
3802 if (($rawline =~ /^.\s*$/ && $prevline =~ /^..*{\s*$/)) {
3804 "Blank lines aren't necessary after an open brace '{'\n" . $hereprev);
3807 # no volatiles please
3808 my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
3809 if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
3811 "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
3815 if ($line =~ /^.\s*\#\s*if\s+0\b/) {
3816 CHK("REDUNDANT_CODE",
3817 "if this code is redundant consider removing it\n" .
3821 # check for needless "if (<foo>) fn(<foo>)" uses
3822 if ($prevline =~ /\bif\s*\(\s*($Lval)\s*\)/) {
3823 my $expr = '\s*\(\s*' . quotemeta($1) . '\s*\)\s*;';
3824 if ($line =~ /\b(kfree|usb_free_urb|debugfs_remove(?:_recursive)?)$expr/) {
3826 "$1(NULL) is safe this check is probably not required\n" . $hereprev);
3830 # check for bad placement of section $InitAttribute (e.g.: __initdata)
3831 if ($line =~ /(\b$InitAttribute\b)/) {
3833 if ($line =~ /^\+\s*static\s+(?:const\s+)?(?:$attr\s+)?($NonptrTypeWithAttr)\s+(?:$attr\s+)?($Ident(?:\[[^]]*\])?)\s*[=;]/) {
3836 if ((($ptr =~ /\b(union|struct)\s+$attr\b/ &&
3837 ERROR("MISPLACED_INIT",
3838 "$attr should be placed after $var\n" . $herecurr)) ||
3839 ($ptr !~ /\b(union|struct)\s+$attr\b/ &&
3840 WARN("MISPLACED_INIT",
3841 "$attr should be placed after $var\n" . $herecurr))) &&
3843 $fixed[$linenr - 1] =~ 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;
3848 # check for $InitAttributeData (ie: __initdata) with const
3849 if ($line =~ /\bconst\b/ && $line =~ /($InitAttributeData)/) {
3851 $attr =~ /($InitAttributePrefix)(.*)/;
3852 my $attr_prefix = $1;
3854 if (ERROR("INIT_ATTRIBUTE",
3855 "Use of const init definition must use ${attr_prefix}initconst\n" . $herecurr) &&
3857 $fixed[$linenr - 1] =~
3858 s/$InitAttributeData/${attr_prefix}initconst/;
3862 # check for $InitAttributeConst (ie: __initconst) without const
3863 if ($line !~ /\bconst\b/ && $line =~ /($InitAttributeConst)/) {
3865 if (ERROR("INIT_ATTRIBUTE",
3866 "Use of $attr requires a separate use of const\n" . $herecurr) &&
3868 my $lead = $fixed[$linenr - 1] =~
3869 /(^\+\s*(?:static\s+))/;
3871 $lead = "$lead " if ($lead !~ /^\+$/);
3872 $lead = "${lead}const ";
3873 $fixed[$linenr - 1] =~ s/(^\+\s*(?:static\s+))/$lead/;
3877 # prefer usleep_range over udelay
3878 if ($line =~ /\budelay\s*\(\s*(\d+)\s*\)/) {
3879 # ignore udelay's < 10, however
3882 "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line);
3886 # warn about unexpectedly long msleep's
3887 if ($line =~ /\bmsleep\s*\((\d+)\);/) {
3890 "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line);
3894 # check for comparisons of jiffies
3895 if ($line =~ /\bjiffies\s*$Compare|$Compare\s*jiffies\b/) {
3896 WARN("JIFFIES_COMPARISON",
3897 "Comparing jiffies is almost always wrong; prefer time_after, time_before and friends\n" . $herecurr);
3900 # check for comparisons of get_jiffies_64()
3901 if ($line =~ /\bget_jiffies_64\s*\(\s*\)\s*$Compare|$Compare\s*get_jiffies_64\s*\(\s*\)/) {
3902 WARN("JIFFIES_COMPARISON",
3903 "Comparing get_jiffies_64() is almost always wrong; prefer time_after64, time_before64 and friends\n" . $herecurr);
3906 # warn about #ifdefs in C files
3907 # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
3908 # print "#ifdef in C files should be avoided\n";
3909 # print "$herecurr";
3913 # warn about spacing in #ifdefs
3914 if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
3915 if (ERROR("SPACING",
3916 "exactly one space required after that #$1\n" . $herecurr) &&
3918 $fixed[$linenr - 1] =~
3919 s/^(.\s*\#\s*(ifdef|ifndef|elif))\s{2,}/$1 /;
3924 # check for spinlock_t definitions without a comment.
3925 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/ ||
3926 $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
3928 if (!ctx_has_comment($first_line, $linenr)) {
3929 CHK("UNCOMMENTED_DEFINITION",
3930 "$1 definition without comment\n" . $herecurr);
3933 # check for memory barriers without a comment.
3934 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
3935 if (!ctx_has_comment($first_line, $linenr)) {
3936 WARN("MEMORY_BARRIER",
3937 "memory barrier without comment\n" . $herecurr);
3940 # check of hardware specific defines
3941 if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
3943 "architecture specific defines should be avoided\n" . $herecurr);
3946 # Check that the storage class is at the beginning of a declaration
3947 if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) {
3948 WARN("STORAGE_CLASS",
3949 "storage class should be at the beginning of the declaration\n" . $herecurr)
3952 # check the location of the inline attribute, that it is between
3953 # storage class and type.
3954 if ($line =~ /\b$Type\s+$Inline\b/ ||
3955 $line =~ /\b$Inline\s+$Storage\b/) {
3956 ERROR("INLINE_LOCATION",
3957 "inline keyword should sit between storage class and type\n" . $herecurr);
3960 # Check for __inline__ and __inline, prefer inline
3961 if ($realfile !~ m@\binclude/uapi/@ &&
3962 $line =~ /\b(__inline__|__inline)\b/) {
3964 "plain inline is preferred over $1\n" . $herecurr) &&
3966 $fixed[$linenr - 1] =~ s/\b(__inline__|__inline)\b/inline/;
3971 # Check for __attribute__ packed, prefer __packed
3972 if ($realfile !~ m@\binclude/uapi/@ &&
3973 $line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
3974 WARN("PREFER_PACKED",
3975 "__packed is preferred over __attribute__((packed))\n" . $herecurr);
3978 # Check for __attribute__ aligned, prefer __aligned
3979 if ($realfile !~ m@\binclude/uapi/@ &&
3980 $line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
3981 WARN("PREFER_ALIGNED",
3982 "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
3985 # Check for __attribute__ format(printf, prefer __printf
3986 if ($realfile !~ m@\binclude/uapi/@ &&
3987 $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf/) {
3988 if (WARN("PREFER_PRINTF",
3989 "__printf(string-index, first-to-check) is preferred over __attribute__((format(printf, string-index, first-to-check)))\n" . $herecurr) &&
3991 $fixed[$linenr - 1] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*printf\s*,\s*(.*)\)\s*\)\s*\)/"__printf(" . trim($1) . ")"/ex;
3996 # Check for __attribute__ format(scanf, prefer __scanf
3997 if ($realfile !~ m@\binclude/uapi/@ &&
3998 $line =~ /\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\b/) {
3999 if (WARN("PREFER_SCANF",
4000 "__scanf(string-index, first-to-check) is preferred over __attribute__((format(scanf, string-index, first-to-check)))\n" . $herecurr) &&
4002 $fixed[$linenr - 1] =~ s/\b__attribute__\s*\(\s*\(\s*format\s*\(\s*scanf\s*,\s*(.*)\)\s*\)\s*\)/"__scanf(" . trim($1) . ")"/ex;
4006 # check for sizeof(&)
4007 if ($line =~ /\bsizeof\s*\(\s*\&/) {
4008 WARN("SIZEOF_ADDRESS",
4009 "sizeof(& should be avoided\n" . $herecurr);
4012 # check for sizeof without parenthesis
4013 if ($line =~ /\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/) {
4014 if (WARN("SIZEOF_PARENTHESIS",
4015 "sizeof $1 should be sizeof($1)\n" . $herecurr) &&
4017 $fixed[$linenr - 1] =~ s/\bsizeof\s+((?:\*\s*|)$Lval|$Type(?:\s+$Lval|))/"sizeof(" . trim($1) . ")"/ex;
4021 # check for line continuations in quoted strings with odd counts of "
4022 if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) {
4023 WARN("LINE_CONTINUATIONS",
4024 "Avoid line continuations in quoted strings\n" . $herecurr);
4027 # check for struct spinlock declarations
4028 if ($line =~ /^.\s*\bstruct\s+spinlock\s+\w+\s*;/) {
4029 WARN("USE_SPINLOCK_T",
4030 "struct spinlock should be spinlock_t\n" . $herecurr);
4033 # check for seq_printf uses that could be seq_puts
4034 if ($sline =~ /\bseq_printf\s*\(.*"\s*\)\s*;\s*$/) {
4035 my $fmt = get_quoted_string($line, $rawline);
4036 if ($fmt ne "" && $fmt !~ /[^\\]\%/) {
4037 if (WARN("PREFER_SEQ_PUTS",
4038 "Prefer seq_puts to seq_printf\n" . $herecurr) &&
4040 $fixed[$linenr - 1] =~ s/\bseq_printf\b/seq_puts/;
4045 # Check for misused memsets
4046 if ($^V && $^V ge 5.10.0 &&
4048 $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/s) {
4054 if ($ms_size =~ /^(0x|)0$/i) {
4056 "memset to 0's uses 0 as the 2nd argument, not the 3rd\n" . "$here\n$stat\n");
4057 } elsif ($ms_size =~ /^(0x|)1$/i) {
4059 "single byte memset is suspicious. Swapped 2nd/3rd argument?\n" . "$here\n$stat\n");
4063 # typecasts on min/max could be min_t/max_t
4064 if ($^V && $^V ge 5.10.0 &&
4066 $stat =~ /^\+(?:.*?)\b(min|max)\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\)/) {
4067 if (defined $2 || defined $7) {
4069 my $cast1 = deparenthesize($2);
4071 my $cast2 = deparenthesize($7);
4075 if ($cast1 ne "" && $cast2 ne "" && $cast1 ne $cast2) {
4076 $cast = "$cast1 or $cast2";
4077 } elsif ($cast1 ne "") {
4083 "$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . "$here\n$stat\n");
4087 # check usleep_range arguments
4088 if ($^V && $^V ge 5.10.0 &&
4090 $stat =~ /^\+(?:.*?)\busleep_range\s*\(\s*($FuncArg)\s*,\s*($FuncArg)\s*\)/) {
4094 WARN("USLEEP_RANGE",
4095 "usleep_range should not use min == max args; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n");
4096 } elsif ($min =~ /^\d+$/ && $max =~ /^\d+$/ &&
4098 WARN("USLEEP_RANGE",
4099 "usleep_range args reversed, use min then max; see Documentation/timers/timers-howto.txt\n" . "$here\n$stat\n");
4103 # check for naked sscanf
4104 if ($^V && $^V ge 5.10.0 &&
4106 $stat =~ /\bsscanf\b/ &&
4107 ($stat !~ /$Ident\s*=\s*sscanf\s*$balanced_parens/ &&
4108 $stat !~ /\bsscanf\s*$balanced_parens\s*(?:$Compare)/ &&
4109 $stat !~ /(?:$Compare)\s*\bsscanf\s*$balanced_parens/)) {
4110 my $lc = $stat =~ tr@\n@@;
4111 $lc = $lc + $linenr;
4112 my $stat_real = raw_line($linenr, 0);
4113 for (my $count = $linenr + 1; $count <= $lc; $count++) {
4114 $stat_real = $stat_real . "\n" . raw_line($count, 0);
4116 WARN("NAKED_SSCANF",
4117 "unchecked sscanf return value\n" . "$here\n$stat_real\n");
4120 # check for new externs in .h files.
4121 if ($realfile =~ /\.h$/ &&
4122 $line =~ /^\+\s*(extern\s+)$Type\s*$Ident\s*\(/s) {
4123 if (CHK("AVOID_EXTERNS",
4124 "extern prototypes should be avoided in .h files\n" . $herecurr) &&
4126 $fixed[$linenr - 1] =~ s/(.*)\bextern\b\s*(.*)/$1$2/;
4130 # check for new externs in .c files.
4131 if ($realfile =~ /\.c$/ && defined $stat &&
4132 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
4134 my $function_name = $1;
4135 my $paren_space = $2;
4138 if (defined $cond) {
4139 substr($s, 0, length($cond), '');
4141 if ($s =~ /^\s*;/ &&
4142 $function_name ne 'uninitialized_var')
4144 WARN("AVOID_EXTERNS",
4145 "externs should be avoided in .c files\n" . $herecurr);
4148 if ($paren_space =~ /\n/) {
4149 WARN("FUNCTION_ARGUMENTS",
4150 "arguments for function declarations should follow identifier\n" . $herecurr);
4153 } elsif ($realfile =~ /\.c$/ && defined $stat &&
4154 $stat =~ /^.\s*extern\s+/)
4156 WARN("AVOID_EXTERNS",
4157 "externs should be avoided in .c files\n" . $herecurr);
4160 # checks for new __setup's
4161 if ($rawline =~ /\b__setup\("([^"]*)"/) {
4164 if (!grep(/$name/, @setup_docs)) {
4165 CHK("UNDOCUMENTED_SETUP",
4166 "__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
4170 # check for pointless casting of kmalloc return
4171 if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) {
4172 WARN("UNNECESSARY_CASTS",
4173 "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
4177 # p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...)
4178 if ($^V && $^V ge 5.10.0 &&
4179 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*([kv][mz]alloc(?:_node)?)\s*\(\s*(sizeof\s*\(\s*struct\s+$Lval\s*\))/) {
4180 CHK("ALLOC_SIZEOF_STRUCT",
4181 "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
4184 # check for krealloc arg reuse
4185 if ($^V && $^V ge 5.10.0 &&
4186 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) {
4187 WARN("KREALLOC_ARG_REUSE",
4188 "Reusing the krealloc arg is almost always a bug\n" . $herecurr);
4191 # check for alloc argument mismatch
4192 if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
4193 WARN("ALLOC_ARRAY_ARGS",
4194 "$1 uses number as first arg, sizeof is generally wrong\n" . $herecurr);
4197 # check for GFP_NOWAIT use
4198 if ($line =~ /\b__GFP_NOFAIL\b/) {
4199 WARN("__GFP_NOFAIL",
4200 "Use of __GFP_NOFAIL is deprecated, no new users should be added\n" . $herecurr);
4203 # check for multiple semicolons
4204 if ($line =~ /;\s*;\s*$/) {
4205 if (WARN("ONE_SEMICOLON",
4206 "Statements terminations use 1 semicolon\n" . $herecurr) &&
4208 $fixed[$linenr - 1] =~ s/(\s*;\s*){2,}$/;/g;
4212 # check for case / default statements not preceeded by break/fallthrough/switch
4213 if ($line =~ /^.\s*(?:case\s+(?:$Ident|$Constant)\s*|default):/) {
4215 my $has_statement = 0;
4217 my $prevline = $linenr;
4218 while ($prevline > 1 && $count < 3 && !$has_break) {
4220 my $rline = $rawlines[$prevline - 1];
4221 my $fline = $lines[$prevline - 1];
4222 last if ($fline =~ /^\@\@/);
4223 next if ($fline =~ /^\-/);
4224 next if ($fline =~ /^.(?:\s*(?:case\s+(?:$Ident|$Constant)[\s$;]*|default):[\s$;]*)*$/);
4225 $has_break = 1 if ($rline =~ /fall[\s_-]*(through|thru)/i);
4226 next if ($fline =~ /^.[\s$;]*$/);
4229 $has_break = 1 if ($fline =~ /\bswitch\b|\b(?:break\s*;[\s$;]*$|return\b|goto\b|continue\b)/);
4231 if (!$has_break && $has_statement) {
4232 WARN("MISSING_BREAK",
4233 "Possible switch case/default not preceeded by break or fallthrough comment\n" . $herecurr);
4237 # check for switch/default statements without a break;
4238 if ($^V && $^V ge 5.10.0 &&
4240 $stat =~ /^\+[$;\s]*(?:case[$;\s]+\w+[$;\s]*:[$;\s]*|)*[$;\s]*\bdefault[$;\s]*:[$;\s]*;/g) {
4242 my $herectx = $here . "\n";
4243 my $cnt = statement_rawlines($stat);
4244 for (my $n = 0; $n < $cnt; $n++) {
4245 $herectx .= raw_line($linenr, $n) . "\n";
4247 WARN("DEFAULT_NO_BREAK",
4248 "switch default: should use break\n" . $herectx);
4251 # check for gcc specific __FUNCTION__
4252 if ($line =~ /\b__FUNCTION__\b/) {
4253 if (WARN("USE_FUNC",
4254 "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr) &&
4256 $fixed[$linenr - 1] =~ s/\b__FUNCTION__\b/__func__/g;
4260 # check for use of yield()
4261 if ($line =~ /\byield\s*\(\s*\)/) {
4263 "Using yield() is generally wrong. See yield() kernel-doc (sched/core.c)\n" . $herecurr);
4266 # check for comparisons against true and false
4267 if ($line =~ /\+\s*(.*?)\b(true|false|$Lval)\s*(==|\!=)\s*(true|false|$Lval)\b(.*)$/i) {
4275 ($arg, $otype) = ($otype, $arg) if ($arg =~ /^(?:true|false)$/i);
4277 my $type = lc($otype);
4278 if ($type =~ /^(?:true|false)$/) {
4279 if (("$test" eq "==" && "$type" eq "true") ||
4280 ("$test" eq "!=" && "$type" eq "false")) {
4284 CHK("BOOL_COMPARISON",
4285 "Using comparison to $otype is error prone\n" . $herecurr);
4287 ## maybe suggesting a correct construct would better
4288 ## "Using comparison to $otype is error prone. Perhaps use '${lead}${op}${arg}${trail}'\n" . $herecurr);
4293 # check for semaphores initialized locked
4294 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
4295 WARN("CONSIDER_COMPLETION",
4296 "consider using a completion\n" . $herecurr);
4299 # recommend kstrto* over simple_strto* and strict_strto*
4300 if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) {
4301 WARN("CONSIDER_KSTRTO",
4302 "$1 is obsolete, use k$3 instead\n" . $herecurr);
4305 # check for __initcall(), use device_initcall() explicitly please
4306 if ($line =~ /^.\s*__initcall\s*\(/) {
4307 WARN("USE_DEVICE_INITCALL",
4308 "please use device_initcall() instead of __initcall()\n" . $herecurr);
4311 # check for various ops structs, ensure they are const.
4312 my $struct_ops = qr{acpi_dock_ops|
4313 address_space_operations|
4315 block_device_operations|
4320 file_lock_operations|
4330 lock_manager_operations|
4336 pipe_buf_operations|
4337 platform_hibernation_ops|
4338 platform_suspend_ops|
4343 soc_pcmcia_socket_ops|
4349 if ($line !~ /\bconst\b/ &&
4350 $line =~ /\bstruct\s+($struct_ops)\b/) {
4351 WARN("CONST_STRUCT",
4352 "struct $1 should normally be const\n" .
4356 # use of NR_CPUS is usually wrong
4357 # ignore definitions of NR_CPUS and usage to define arrays as likely right
4358 if ($line =~ /\bNR_CPUS\b/ &&
4359 $line !~ /^.\s*\s*#\s*if\b.*\bNR_CPUS\b/ &&
4360 $line !~ /^.\s*\s*#\s*define\b.*\bNR_CPUS\b/ &&
4361 $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/ &&
4362 $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
4363 $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/)
4366 "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
4369 # Use of __ARCH_HAS_<FOO> or ARCH_HAVE_<BAR> is wrong.
4370 if ($line =~ /\+\s*#\s*define\s+((?:__)?ARCH_(?:HAS|HAVE)\w*)\b/) {
4371 ERROR("DEFINE_ARCH_HAS",
4372 "#define of '$1' is wrong - use Kconfig variables or standard guards instead\n" . $herecurr);
4375 # check for %L{u,d,i} in strings
4377 while ($line =~ /(?:^|")([X\t]*)(?:"|$)/g) {
4378 $string = substr($rawline, $-[1], $+[1] - $-[1]);
4379 $string =~ s/%%/__/g;
4380 if ($string =~ /(?<!%)%L[udi]/) {
4382 "\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr);
4387 # whine mightly about in_atomic
4388 if ($line =~ /\bin_atomic\s*\(/) {
4389 if ($realfile =~ m@^drivers/@) {
4391 "do not use in_atomic in drivers\n" . $herecurr);
4392 } elsif ($realfile !~ m@^kernel/@) {
4394 "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
4398 # check for lockdep_set_novalidate_class
4399 if ($line =~ /^.\s*lockdep_set_novalidate_class\s*\(/ ||
4400 $line =~ /__lockdep_no_validate__\s*\)/ ) {
4401 if ($realfile !~ m@^kernel/lockdep@ &&
4402 $realfile !~ m@^include/linux/lockdep@ &&
4403 $realfile !~ m@^drivers/base/core@) {
4405 "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
4409 if ($line =~ /debugfs_create_file.*S_IWUGO/ ||
4410 $line =~ /DEVICE_ATTR.*S_IWUGO/ ) {
4411 WARN("EXPORTED_WORLD_WRITABLE",
4412 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
4416 # If we have no input at all, then there is nothing to report on
4417 # so just keep quiet.
4418 if ($#rawlines == -1) {
4422 # In mailback mode only produce a report in the negative, for
4423 # things that appear to be patches.
4424 if ($mailback && ($clean == 1 || !$is_patch)) {
4428 # This is not a patch, and we are are in 'no-patch' mode so
4430 if (!$chk_patch && !$is_patch) {
4435 ERROR("NOT_UNIFIED_DIFF",
4436 "Does not appear to be a unified-diff format patch\n");
4438 if ($is_patch && $chk_signoff && $signoff == 0) {
4439 ERROR("MISSING_SIGN_OFF",
4440 "Missing Signed-off-by: line(s)\n");
4443 print report_dump();
4444 if ($summary && !($clean == 1 && $quiet == 1)) {
4445 print "$filename " if ($summary_file);
4446 print "total: $cnt_error errors, $cnt_warn warnings, " .
4447 (($check)? "$cnt_chk checks, " : "") .
4448 "$cnt_lines lines checked\n";
4449 print "\n" if ($quiet == 0);
4454 if ($^V lt 5.10.0) {
4455 print("NOTE: perl $^V is not modern enough to detect all possible issues.\n");
4456 print("An upgrade to at least perl v5.10.0 is suggested.\n\n");
4459 # If there were whitespace errors which cleanpatch can fix
4460 # then suggest that.
4461 if ($rpt_cleaners) {
4462 print "NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or\n";
4463 print " scripts/cleanfile\n\n";
4468 hash_show_words(\%use_type, "Used");
4469 hash_show_words(\%ignore_type, "Ignored");
4471 if ($clean == 0 && $fix && "@rawlines" ne "@fixed") {
4472 my $newfile = $filename;
4473 $newfile .= ".EXPERIMENTAL-checkpatch-fixes" if (!$fix_inplace);
4477 open($f, '>', $newfile)
4478 or die "$P: Can't open $newfile for write\n";
4479 foreach my $fixed_line (@fixed) {
4482 if ($linecount > 3) {
4483 $fixed_line =~ s/^\+//;
4484 print $f $fixed_line. "\n";
4487 print $f $fixed_line . "\n";
4494 Wrote EXPERIMENTAL --fix correction(s) to '$newfile'
4496 Do _NOT_ trust the results written to this file.
4497 Do _NOT_ submit these changes without inspecting them for correctness.
4499 This EXPERIMENTAL file is simply a convenience to help rewrite patches.
4500 No warranties, expressed or implied...
4506 if ($clean == 1 && $quiet == 0) {
4507 print "$vname has no obvious style problems and is ready for submission.\n"
4509 if ($clean == 0 && $quiet == 0) {
4511 $vname has style problems, please review.
4513 If any of these errors are false positives, please report
4514 them to the maintainer, see CHECKPATCH in MAINTAINERS.