2 # (c) 2001, Dave Jones. <davej@codemonkey.org.uk> (the file handling bit)
3 # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
4 # (c) 2007, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite, etc)
5 # Licensed under the terms of the GNU GPL License version 2
12 <<<<<<< HEAD
:scripts
/checkpatch
.pl
16 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
18 use Getopt
::Long
qw(:config no_auto_abbrev);
35 'q|quiet+' => \
$quiet,
37 'signoff!' => \
$chk_signoff,
38 'patch!' => \
$chk_patch,
42 'subjective!' => \
$check,
45 'summary!' => \
$summary,
46 'mailback!' => \
$mailback,
47 'summary-file!' => \
$summary_file,
50 'test-type!' => \
$tst_type,
56 print "usage: $P [options] patchfile\n";
57 print "version: $V\n";
58 print "options: -q => quiet\n";
59 print " --no-tree => run without a kernel tree\n";
60 print " --terse => one line per report\n";
61 print " --emacs => emacs compile window format\n";
62 print " --file => check a source file\n";
63 print " --strict => enable more subjective tests\n";
64 print " --root => path to the kernel tree root\n";
65 print " --no-summary => suppress the per-file summary\n";
66 print " --summary-file => include the filename in summary\n";
72 for my $key (keys %debug) {
73 eval "\${dbg_$key} = '$debug{$key}';"
83 if (!top_of_kernel_tree
($root)) {
84 die "$P: $root: --root does not point at a valid tree\n";
87 if (top_of_kernel_tree
('.')) {
89 } elsif ($0 =~ m@
(.*)/scripts/[^/]*$@
&&
90 top_of_kernel_tree
($1)) {
96 print "Must be run from the top-level dir. of a kernel tree\n";
101 my $emitted_corrupt = 0;
103 our $Ident = qr{[A-Za-z_][A-Za-z\d_]*};
104 our $Storage = qr{extern|static|asmlinkage};
112 <<<<<<< HEAD
:scripts
/checkpatch
.pl
117 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
123 __
(?
:mem
|cpu
|dev
|)(?
:initdata
|init
)
125 our $Inline = qr{inline|__always_inline|noinline};
126 our $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
127 our $Lval = qr{$Ident(?:$Member)*};
129 our $Constant = qr{(?:[0-9]+|0x[0-9a-fA-F]+)[UL]*};
130 our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)};
134 &&|\
|\
||,|\
^|\
+\
+|--|&|\
||\
+|-|\
*|\
/|%
153 qr{long\s+long\s+int},
154 qr{(?:__)?(?:u|s|be|le)(?:8|16|32|64)},
159 qr{${Ident}_handler
},
160 qr{${Ident}_handler_fn
},
164 my $all = "(?: \n" . join("|\n ", @typeList) . "\n)";
169 <<<<<<< HEAD
:scripts
/checkpatch
.pl
174 (?
:typeof
|__typeof__
)\s
*\
(\s
*\
**\s
*$Ident\s
*\
)
176 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
177 (?
:\s
+$Sparse|\s
+const
)*
182 (?
:\s
*\
*+\s
*const
|\s
*\
*+|(?
:\s
*\
[\s
*\
])+)?
183 (?
:\s
+$Inline|\s
+$Sparse|\s
+$Attribute)*
185 $Declare = qr{(?:$Storage\s+)?$Type};
189 $chk_signoff = 0 if ($file);
191 my @dep_includes = ();
192 my @dep_functions = ();
193 my $removal = "Documentation/feature-removal-schedule.txt";
194 if ($tree && -f
"$root/$removal") {
195 open(REMOVE
, "<$root/$removal") ||
196 die "$P: $removal: open failed - $!\n";
198 if (/^Check:\s+(.*\S)/) {
199 for my $entry (split(/[, ]+/, $1)) {
200 if ($entry =~ m
@include/(.*)@
) {
201 push(@dep_includes, $1);
203 } elsif ($entry !~ m@
/@
) {
204 push(@dep_functions, $entry);
214 for my $filename (@ARGV) {
216 open(FILE
, "diff -u /dev/null $filename|") ||
217 die "$P: $filename: diff failed - $!\n";
219 open(FILE
, "<$filename") ||
220 die "$P: $filename: open failed - $!\n";
222 if ($filename eq '-') {
223 $vname = 'Your patch';
232 if (!process
($filename)) {
241 sub top_of_kernel_tree
{
245 "COPYING", "CREDITS", "Kbuild", "MAINTAINERS", "Makefile",
246 "README", "Documentation", "arch", "include", "drivers",
247 "fs", "init", "ipc", "kernel", "lib", "scripts",
250 foreach my $check (@tree_check) {
251 if (! -e
$root . '/' . $check) {
263 for my $c (split(//, $str)) {
267 for (; ($n % 8) != 0; $n++) {
282 for my $c (split(//, $str)) {
296 # Drop the diff line leader and expand tabs
298 $line = expand_tabs
($line);
300 # Pick the indent from the front of the line.
301 my ($white) = ($line =~ /^(\s*)/);
303 return (length($line), length($white));
315 foreach my $c (split(//, $line)) {
316 # The second backslash of a pair is not a "quote".
317 if ($l eq "\\" && $c eq "\\") {
320 if ($l ne "\\" && ($c eq "'" || $c eq '"')) {
327 } elsif ($quote eq $c) {
331 if ($quote eq "'" && $qlen > 1) {
334 if ($quote && $c ne "\t") {
344 # Clear out the comments.
345 while ($res =~ m@
(/\*.*?\*/)@g) {
346 substr($res, $-[1], $+[1] - $-[1]) = $; x
($+[1] - $-[1]);
348 if ($res =~ m@
(/\
*.*)@
) {
349 substr($res, $-[1], $+[1] - $-[1]) = $; x
($+[1] - $-[1]);
351 if ($res =~ m@
^.(.*\
*/)@
) {
352 substr($res, $-[1], $+[1] - $-[1]) = $; x
($+[1] - $-[1]);
355 # The pathname on a #include may be surrounded by '<' and '>'.
356 if ($res =~ /^.#\s*include\s+\<(.*)\>/) {
357 my $clean = 'X' x
length($1);
358 $res =~ s@\
<.*\
>@
<$clean>@
;
360 # The whole of a #error is a string.
361 } elsif ($res =~ /^.#\s*(?:error|warning)\s+(.*)\b/) {
362 my $clean = 'X' x
length($1);
363 $res =~ s@
(#\s*(?:error|warning)\s+).*@$1$clean@;
369 sub ctx_statement_block
{
370 my ($linenr, $remain, $off) = @_;
371 my $line = $linenr - 1;
380 <<<<<<< HEAD
:scripts
/checkpatch
.pl
383 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
389 #warn "CSB: blk<$blk>\n";
390 # If we are about to drop off the end, pull in more
393 for (; $remain > 0; $line++) {
394 next if ($lines[$line] =~ /^-/);
397 $blk .= $lines[$line] . "\n";
402 # Bail if there is no further context.
403 #warn "CSB: blk<$blk> off<$off> len<$len>\n";
408 <<<<<<< HEAD
:scripts
/checkpatch
.pl
411 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
412 $c = substr($blk, $off, 1);
413 $remainder = substr($blk, $off);
415 #warn "CSB: c<$c> type<$type> level<$level>\n";
416 # Statement ends at the ';' or a close '}' at the
418 if ($level == 0 && $c eq ';') {
422 # An else is really a conditional as long as its not else if
423 <<<<<<< HEAD
:scripts
/checkpatch
.pl
424 if ($level == 0 && $remainder =~ /(\s+else)(?:\s|{)/ &&
425 $remainder !~ /\s+else\s+if\b/) {
427 if ($level == 0 && (!defined($p) || $p =~ /(?:\s|\})/) &&
428 $remainder =~ /(else)(?:\s|{)/ &&
429 $remainder !~ /else\s+if\b/) {
430 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
431 $coff = $off + length($1);
434 if (($type eq '' || $type eq '(') && $c eq '(') {
438 if ($type eq '(' && $c eq ')') {
440 $type = ($level != 0)?
'(' : '';
442 if ($level == 0 && $coff < $soff) {
446 if (($type eq '' || $type eq '{') && $c eq '{') {
450 if ($type eq '{' && $c eq '}') {
452 $type = ($level != 0)?
'{' : '';
465 my $statement = substr($blk, $soff, $off - $soff + 1);
466 my $condition = substr($blk, $soff, $coff - $soff + 1);
468 #warn "STATEMENT<$statement>\n";
469 #warn "CONDITION<$condition>\n";
471 #print "off<$off> loff<$loff>\n";
473 return ($statement, $condition,
474 $line, $remain + 1, $off - $loff + 1, $level);
477 <<<<<<< HEAD
:scripts
/checkpatch
.pl
479 sub statement_lines
{
482 # Strip the diff line prefixes and rip blank lines at start and end.
483 $stmt =~ s/(^|\n)./$1/g;
487 my @stmt_lines = ($stmt =~ /\n/g);
489 return $#stmt_lines + 2;
492 sub statement_rawlines
{
495 my @stmt_lines = ($stmt =~ /\n/g);
497 return $#stmt_lines + 2;
500 sub statement_block_size
{
503 $stmt =~ s/(^|\n)./$1/g;
509 my @stmt_lines = ($stmt =~ /\n/g);
510 my @stmt_statements = ($stmt =~ /;/g);
512 my $stmt_lines = $#stmt_lines + 2;
513 my $stmt_statements = $#stmt_statements + 1;
515 if ($stmt_lines > $stmt_statements) {
518 return $stmt_statements;
522 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
523 sub ctx_statement_full
{
524 my ($linenr, $remain, $off) = @_;
525 my ($statement, $condition, $level);
529 <<<<<<< HEAD
:scripts
/checkpatch
.pl
531 # Grab the first conditional/block pair.
532 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
533 ($statement, $condition, $linenr, $remain, $off, $level) =
534 ctx_statement_block
($linenr, $remain, $off);
535 #print "F: c<$condition> s<$statement>\n";
536 <<<<<<< HEAD
:scripts
/checkpatch
.pl
538 push(@chunks, [ $condition, $statement ]);
539 if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
540 return ($level, $linenr, @chunks);
543 # Pull in the following conditional/block pairs and see if they
544 # could continue the statement.
545 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
547 <<<<<<< HEAD
:scripts
/checkpatch
.pl
548 push(@chunks, [ $condition, $statement ]);
549 last if (!($remain > 0 && $condition =~ /^.\s*(?:if|else|do)/));
551 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
552 ($statement, $condition, $linenr, $remain, $off, $level) =
553 ctx_statement_block
($linenr, $remain, $off);
554 <<<<<<< HEAD
:scripts
/checkpatch
.pl
555 #print "C: c<$condition> s<$statement>\n";
557 #print "C: c<$condition> s<$statement> remain<$remain>\n";
558 last if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:else|do)\b/s));
560 push(@chunks, [ $condition, $statement ]);
561 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
564 return ($level, $linenr, @chunks);
568 my ($linenr, $remain, $outer, $open, $close, $off) = @_;
570 my $start = $linenr - 1;
577 for ($line = $start; $remain > 0; $line++) {
578 next if ($rawlines[$line] =~ /^-/);
581 $blk .= $rawlines[$line];
582 foreach my $c (split(//, $rawlines[$line])) {
583 ##print "C<$c>L<$level><$open$close>O<$off>\n";
589 if ($c eq $close && $level > 0) {
591 last if ($level == 0);
592 } elsif ($c eq $open) {
597 if (!$outer || $level <= 1) {
598 push(@res, $rawlines[$line]);
601 last if ($level == 0);
604 return ($level, @res);
606 sub ctx_block_outer
{
607 my ($linenr, $remain) = @_;
609 my ($level, @r) = ctx_block_get
($linenr, $remain, 1, '{', '}', 0);
613 my ($linenr, $remain) = @_;
615 my ($level, @r) = ctx_block_get
($linenr, $remain, 0, '{', '}', 0);
619 my ($linenr, $remain, $off) = @_;
621 my ($level, @r) = ctx_block_get
($linenr, $remain, 0, '(', ')', $off);
624 sub ctx_block_level
{
625 my ($linenr, $remain) = @_;
627 return ctx_block_get
($linenr, $remain, 0, '{', '}', 0);
629 sub ctx_statement_level
{
630 my ($linenr, $remain, $off) = @_;
632 return ctx_block_get
($linenr, $remain, 0, '(', ')', $off);
635 sub ctx_locate_comment
{
636 my ($first_line, $end_line) = @_;
638 # Catch a comment on the end of the line itself.
639 my ($current_comment) = ($rawlines[$end_line - 1] =~ m@
.*(/\*.*\*/)\s
*$@
);
640 return $current_comment if (defined $current_comment);
642 # Look through the context and try and figure out if there is a
645 $current_comment = '';
646 for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
647 my $line = $rawlines[$linenr - 1];
649 if ($linenr == $first_line and $line =~ m@
^.\s
*\
*@
) {
652 if ($line =~ m@
/\
*@
) {
655 if (!$in_comment && $current_comment ne '') {
656 $current_comment = '';
658 $current_comment .= $line . "\n" if ($in_comment);
659 if ($line =~ m@\
*/@
) {
664 chomp($current_comment);
665 return($current_comment);
667 sub ctx_has_comment
{
668 my ($first_line, $end_line) = @_;
669 my $cmt = ctx_locate_comment
($first_line, $end_line);
671 ##print "LINE: $rawlines[$end_line - 1 ]\n";
672 ##print "CMMT: $cmt\n";
682 while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]]|$)/g) {
685 $coded = sprintf("^%c", unpack('C', $2) + 64);
694 my $av_preprocessor = 0;
695 <<<<<<< HEAD
:scripts
/checkpatch
.pl
699 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
703 $av_preprocessor = 0;
704 <<<<<<< HEAD
:scripts
/checkpatch
.pl
709 @av_paren_type = ('E');
710 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
713 sub annotate_values
{
714 my ($stream, $type) = @_;
719 print "$stream\n" if ($dbg_values > 1);
721 while (length($cur)) {
722 <<<<<<< HEAD
:scripts
/checkpatch
.pl
723 print " <$type> " if ($dbg_values > 1);
725 print " <" . join('', @av_paren_type) .
726 "> <$type> " if ($dbg_values > 1);
727 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
728 if ($cur =~ /^(\s+)/o) {
729 print "WS($1)\n" if ($dbg_values > 1);
730 if ($1 =~ /\n/ && $av_preprocessor) {
731 <<<<<<< HEAD
:scripts
/checkpatch
.pl
733 $type = pop(@av_paren_type);
734 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
735 $av_preprocessor = 0;
736 <<<<<<< HEAD
:scripts
/checkpatch
.pl
739 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
742 } elsif ($cur =~ /^($Type)/) {
743 print "DECLARE($1)\n" if ($dbg_values > 1);
746 } elsif ($cur =~ /^(#\s*define\s*$Ident)(\(?)/o) {
747 print "DEFINE($1)\n" if ($dbg_values > 1);
748 $av_preprocessor = 1;
749 <<<<<<< HEAD
:scripts
/checkpatch
.pl
750 $av_paren_type[$av_paren] = 'N';
753 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
755 <<<<<<< HEAD
:scripts
/checkpatch
.pl
756 } elsif ($cur =~ /^(#\s*(?:ifdef|ifndef|if|else|elif|endif))/o) {
757 print "PRE($1)\n" if ($dbg_values > 1);
759 } elsif ($cur =~ /^(#\s*(?:ifdef|ifndef|if))/o) {
760 print "PRE_START($1)\n" if ($dbg_values > 1);
761 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
762 $av_preprocessor = 1;
763 <<<<<<< HEAD
:scripts
/checkpatch
.pl
766 push(@av_paren_type, $type);
767 push(@av_paren_type, $type);
770 } elsif ($cur =~ /^(#\s*(?:else|elif))/o) {
771 print "PRE_RESTART($1)\n" if ($dbg_values > 1);
772 $av_preprocessor = 1;
774 push(@av_paren_type, $av_paren_type[$#av_paren_type]);
778 } elsif ($cur =~ /^(#\s*(?:endif))/o) {
779 print "PRE_END($1)\n" if ($dbg_values > 1);
781 $av_preprocessor = 1;
783 # Assume all arms of the conditional end as this
784 # one does, and continue as if the #endif was not here.
786 push(@av_paren_type, $type);
787 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
790 } elsif ($cur =~ /^(\\\n)/o) {
791 print "PRECONT($1)\n" if ($dbg_values > 1);
793 } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
794 print "SIZEOF($1)\n" if ($dbg_values > 1);
796 <<<<<<< HEAD
:scripts
/checkpatch
.pl
797 $av_paren_type[$av_paren] = 'V';
800 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
804 } elsif ($cur =~ /^(if|while|typeof|__typeof__|for)\b/o) {
805 print "COND($1)\n" if ($dbg_values > 1);
806 <<<<<<< HEAD
:scripts
/checkpatch
.pl
807 $av_paren_type[$av_paren] = 'N';
810 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
813 } elsif ($cur =~/^(return|case|else)/o) {
814 print "KEYWORD($1)\n" if ($dbg_values > 1);
817 } elsif ($cur =~ /^(\()/o) {
818 print "PAREN('$1')\n" if ($dbg_values > 1);
819 <<<<<<< HEAD
:scripts
/checkpatch
.pl
822 push(@av_paren_type, $av_pending);
824 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
827 } elsif ($cur =~ /^(\))/o) {
828 <<<<<<< HEAD
:scripts
/checkpatch
.pl
829 $av_paren-- if ($av_paren > 0);
830 if (defined $av_paren_type[$av_paren]) {
831 $type = $av_paren_type[$av_paren];
832 undef $av_paren_type[$av_paren];
834 my $new_type = pop(@av_paren_type);
835 if ($new_type ne '_') {
837 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
838 print "PAREN('$1') -> $type\n"
839 if ($dbg_values > 1);
841 print "PAREN('$1')\n" if ($dbg_values > 1);
844 } elsif ($cur =~ /^($Ident)\(/o) {
845 print "FUNC($1)\n" if ($dbg_values > 1);
846 <<<<<<< HEAD
:scripts
/checkpatch
.pl
847 $av_paren_type[$av_paren] = 'V';
850 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
852 } elsif ($cur =~ /^($Ident|$Constant)/o) {
853 print "IDENT($1)\n" if ($dbg_values > 1);
856 } elsif ($cur =~ /^($Assignment)/o) {
857 print "ASSIGN($1)\n" if ($dbg_values > 1);
860 <<<<<<< HEAD
:scripts
/checkpatch
.pl
861 } elsif ($cur =~/^(;)/) {
863 } elsif ($cur =~/^(;|{|})/) {
864 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
865 print "END($1)\n" if ($dbg_values > 1);
868 <<<<<<< HEAD
:scripts
/checkpatch
.pl
869 } elsif ($cur =~ /^(;|{|}|\?|:|\[)/o) {
871 } elsif ($cur =~ /^(;|\?|:|\[)/o) {
872 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
873 print "CLOSE($1)\n" if ($dbg_values > 1);
876 } elsif ($cur =~ /^($Operators)/o) {
877 print "OP($1)\n" if ($dbg_values > 1);
878 if ($1 ne '++' && $1 ne '--') {
882 } elsif ($cur =~ /(^.)/o) {
883 print "C($1)\n" if ($dbg_values > 1);
886 $cur = substr($cur, length($1));
887 $res .= $type x
length($1);
895 my ($possible, $line) = @_;
897 #print "CHECK<$possible>\n";
898 if ($possible !~ /^(?:$Storage|$Type|DEFINE_\S+)$/ &&
899 $possible ne 'goto' && $possible ne 'return' &&
900 $possible ne 'struct' && $possible ne 'enum' &&
901 $possible ne 'case' && $possible ne 'else' &&
902 $possible ne 'typedef') {
903 warn "POSSIBLE: $possible ($line)\n" if ($dbg_possible);
904 push(@typeList, $possible);
912 my $line = $prefix . $_[0];
914 $line = (split('\n', $line))[0] . "\n" if ($terse);
916 push(our @report, $line);
922 report
("ERROR: $_[0]\n");
927 report
("WARNING: $_[0]\n");
933 report
("CHECK: $_[0]\n");
940 my $filename = shift;
963 # Trace the real file/line as we go.
969 my $comment_edge = 0;
972 my $prev_values = 'E';
975 my $suppress_ifbraces = 0;
977 # Pre-scan the patch sanitizing the lines.
978 # Pre-scan the patch looking for any __setup documentation.
983 foreach my $rawline (@rawlines) {
984 # Standardise the strings and chars within the input to
986 $line = sanitise_line
($rawline);
989 ##print "==>$rawline\n";
990 ##print "-->$line\n";
992 if ($line=~/^\+\+\+\s+(\S+)/) {
994 if ($1 =~ m
@Documentation/kernel
-parameters
.txt
$@
) {
1000 if ($setup_docs && $line =~ /^\+/) {
1001 push(@setup_docs, $line);
1007 foreach my $line (@lines) {
1010 my $rawline = $rawlines[$linenr - 1];
1012 #extract the filename as it passes
1013 if ($line=~/^\+\+\+\s+(\S+)/) {
1015 $realfile =~ s@
^[^/]*/@@
;
1019 #extract the line range in the file after the patch is applied
1020 if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
1022 $first_line = $linenr + 1;
1033 $suppress_ifbraces = $linenr - 1;
1037 # track the line number as we move through the hunk, note that
1038 # new versions of GNU diff omit the leading space on completely
1039 # blank context lines so we need to count that too.
1040 if ($line =~ /^( |\+|$)/) {
1042 $realcnt-- if ($realcnt != 0);
1044 # Guestimate if this is a continuing comment. Run
1045 # the context looking for a comment "edge". If this
1046 # edge is a close comment then we must be in a comment
1048 if ($linenr == $first_line) {
1050 for (my $ln = $first_line; $ln < ($linenr + $realcnt); $ln++) {
1051 ($edge) = ($rawlines[$ln - 1] =~ m@
(/\*|\*/)@
);
1052 last if (defined $edge);
1054 if (defined $edge && $edge eq '*/') {
1059 # Guestimate if this is a continuing comment. If this
1060 # is the start of a diff block and this line starts
1061 # ' *' then it is very likely a comment.
1062 if ($linenr == $first_line and $rawline =~ m@
^.\s
* \
*(?
:\s
|$)@
) {
1066 # Find the last comment edge on _this_ line.
1068 while (($rawline =~ m@
(/\*|\*/)@g)) {
1077 # Measure the line length and indent.
1078 ($length, $indent) = line_stats
($rawline);
1080 # Track the previous line.
1081 ($prevline, $stashline) = ($stashline, $line);
1082 ($previndent, $stashindent) = ($stashindent, $indent);
1083 ($prevrawline, $stashrawline) = ($stashrawline, $rawline);
1085 #warn "ic<$in_comment> ce<$comment_edge> line<$line>\n";
1087 } elsif ($realcnt == 1) {
1091 #make up the handle for any error we report on this line
1092 $here = "#$linenr: " if (!$file);
1093 $here = "#$realline: " if ($file);
1094 $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
1096 my $hereline = "$here\n$rawline\n";
1097 my $herecurr = "$here\n$rawline\n";
1098 my $hereprev = "$here\n$prevrawline\n$rawline\n";
1100 $prefix = "$filename:$realline: " if ($emacs && $file);
1101 $prefix = "$filename:$linenr: " if ($emacs && !$file);
1102 $cnt_lines++ if ($realcnt != 0);
1104 #check the patch for a signoff:
1105 if ($line =~ /^\s*signed-off-by:/i) {
1106 # This is a signoff, if ugly, so do not double report.
1108 if (!($line =~ /^\s*Signed-off-by:/)) {
1109 WARN
("Signed-off-by: is the preferred form\n" .
1112 if ($line =~ /^\s*signed-off-by:\S/i) {
1113 WARN
("need space after Signed-off-by:\n" .
1118 # Check for wrappage within a valid hunk of the file
1119 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
1120 ERROR
("patch seems to be corrupt (line wrapped?)\n" .
1121 $herecurr) if (!$emitted_corrupt++);
1124 # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
1125 if (($realfile =~ /^$/ || $line =~ /^\+/) &&
1127 [\x09\x0A\x0D\x20-\x7E] # ASCII
1128 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
1129 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
1130 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
1131 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
1132 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
1133 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
1134 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
1136 ERROR
("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $herecurr);
1139 #ignore lines being removed
1140 if ($line=~/^-/) {next;}
1142 # check we are in a valid source file if not then ignore this hunk
1143 next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);
1145 #trailing whitespace
1146 if ($line =~ /^\+.*\015/) {
1147 my $herevet = "$here\n" . cat_vet
($rawline) . "\n";
1148 ERROR
("DOS line endings\n" . $herevet);
1150 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
1151 my $herevet = "$here\n" . cat_vet
($rawline) . "\n";
1152 ERROR
("trailing whitespace\n" . $herevet);
1155 if ($line =~ /^\+/ && !($prevrawline=~/\/\
*\
*/) && $length > 80) {
1156 WARN
("line over 80 characters\n" . $herecurr);
1159 # check for adding lines without a newline.
1160 if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
1161 WARN
("adding a line without newline at end of file\n" . $herecurr);
1164 # check we are in a valid source file *.[hc] if not then ignore this hunk
1165 next if ($realfile !~ /\.[hc]$/);
1167 # at the beginning of a line any tabs must come first and anything
1168 # more than 8 must use tabs.
1169 if ($rawline =~ /^\+\s* \t\s*\S/ ||
1170 $rawline =~ /^\+\s* \s*/) {
1171 my $herevet = "$here\n" . cat_vet
($rawline) . "\n";
1172 ERROR
("use tabs not spaces\n" . $herevet);
1175 # check for RCS/CVS revision markers
1176 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1177 if ($rawline =~ /\$(Revision|Log|Id)(?:\$|)/) {
1179 if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
1180 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1181 WARN
("CVS style keyword markers, these will _not_ be updated\n". $herecurr);
1184 # The rest of our checks refer specifically to C style
1185 # only apply those _outside_ comments. Only skip
1186 # lines in the middle of comments.
1187 next if (!$comment_edge && $in_comment);
1189 # Check for potential 'bare' types
1191 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1193 my ($s, $c) = ctx_statement_block
($linenr, $realcnt, 0);
1197 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1198 # Ignore goto labels.
1199 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1200 if ($line =~ /$Ident:\*$/) {
1202 if ($s =~ /$Ident:\*$/) {
1203 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1205 # Ignore functions being called
1206 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1207 } elsif ($line =~ /^.\s*$Ident\s*\(/) {
1209 } elsif ($s =~ /^.\s*$Ident\s*\(/) {
1210 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1212 # definitions in global scope can only start with types
1213 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1214 } elsif ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) {
1215 possible
($1, $line);
1217 } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) {
1219 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1221 # declarations always start with types
1222 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1223 } elsif ($prev_values eq 'E' && $line =~ /^.\s*(?:$Storage\s+)?(?:const\s+)?($Ident)\b(:?\s+$Sparse)?\s*\**\s*$Ident\s*(?:;|=|,)/) {
1226 } elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:const\s+)?($Ident)\b(:?\s+$Sparse)?\s*\**\s*$Ident\s*(?:;|=|,)/) {
1228 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1231 # any (foo ... *) is a pointer cast, and foo is a type
1232 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1233 while ($line =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/g) {
1234 possible
($1, $line);
1236 while ($s =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/g) {
1238 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1241 # Check for any sort of function declaration.
1242 # int foo(something bar, other baz);
1243 # void (*store_gdt)(x86_descr_ptr *);
1244 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1245 if ($prev_values eq 'E' && $line =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) {
1247 if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) {
1248 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1249 my ($name_len) = length($1);
1250 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1251 my ($level, @ctx) = ctx_statement_level
($linenr, $realcnt, $name_len);
1252 my $ctx = join("\n", @ctx);
1254 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1256 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1260 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1261 substr($ctx, 0, $name_len + 1) = '';
1262 $ctx =~ s/\)[^\)]*$//;
1263 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1266 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1267 for my $arg (split(/\s*,\s*/, $ctx)) {
1268 if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/ || $arg =~ /^($Ident)$/) {
1270 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1271 possible
($1, $line);
1274 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1282 # Checks which may be anchored in the context.
1285 # Check for switch () and associated case and default
1286 # statements should be at the same indent.
1287 if ($line=~/\bswitch\s*\(.*\)/) {
1290 my @ctx = ctx_block_outer
($linenr, $realcnt);
1292 for my $ctx (@ctx) {
1293 my ($clen, $cindent) = line_stats
($ctx);
1294 if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
1295 $indent != $cindent) {
1296 $err .= "$sep$ctx\n";
1303 ERROR
("switch and case should be at the same indent\n$hereline$err");
1307 # if/while/etc brace do not go on next line, unless defining a do while loop,
1308 # or if that brace on the next line is for something else
1309 if ($line =~ /\b(?:(if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.#/) {
1310 my ($level, @ctx) = ctx_statement_level
($linenr, $realcnt, 0);
1311 my $ctx_ln = $linenr + $#ctx + 1;
1312 my $ctx_cnt = $realcnt - $#ctx - 1;
1313 my $ctx = join("\n", @ctx);
1315 # Skip over any removed lines in the context following statement.
1316 while ($ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^-/) {
1320 ##warn "line<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>";
1322 if ($ctx !~ /{\s*/ && $ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
1323 ERROR
("That open brace { should be on the previous line\n" .
1324 "$here\n$ctx\n$lines[$ctx_ln - 1]");
1326 if ($level == 0 && $ctx =~ /\)\s*\;\s*$/ && defined $lines[$ctx_ln - 1]) {
1327 my ($nlength, $nindent) = line_stats
($lines[$ctx_ln - 1]);
1328 if ($nindent > $indent) {
1329 WARN
("Trailing semicolon indicates no statements, indent implies otherwise\n" .
1330 "$here\n$ctx\n$lines[$ctx_ln - 1]");
1335 # Track the 'values' across context and added lines.
1336 my $opline = $line; $opline =~ s/^./ /;
1337 my $curr_values = annotate_values
($opline . "\n", $prev_values);
1338 $curr_values = $prev_values . $curr_values;
1340 my $outline = $opline; $outline =~ s/\t/ /g;
1341 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1342 warn "--> .$outline\n";
1343 warn "--> $curr_values\n";
1345 print "$linenr > .$outline\n";
1346 print "$linenr > $curr_values\n";
1347 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1349 $prev_values = substr($curr_values, -1);
1351 #ignore lines not being added
1352 if ($line=~/^[^\+]/) {next;}
1354 # TEST: allow direct testing of the type matcher.
1355 if ($tst_type && $line =~ /^.$Declare$/) {
1356 ERROR
("TEST: is type $Declare\n" . $herecurr);
1360 # check for initialisation to aggregates open brace on the next line
1361 if ($prevline =~ /$Declare\s*$Ident\s*=\s*$/ &&
1362 $line =~ /^.\s*{/) {
1363 ERROR
("That open brace { should be on the previous line\n" . $hereprev);
1367 # Checks which are anchored on the added line.
1370 # check for malformed paths in #include statements (uses RAW line)
1371 if ($rawline =~ m{^.#\s*include\s+[<"](.*)[">]}) {
1373 if ($path =~ m{//}) {
1374 ERROR
("malformed #include filename\n" .
1379 # no C99 // comments
1380 if ($line =~ m{//}) {
1381 ERROR
("do not use C99 // comments\n" . $herecurr);
1383 # Remove C99 comments.
1385 $opline =~ s@
//.*@@
;
1387 #EXPORT_SYMBOL should immediately follow its function closing }.
1388 if (($line =~ /EXPORT_SYMBOL.*\((.*)\)/) ||
1389 ($line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
1391 if (($prevline !~ /^}/) &&
1392 ($prevline !~ /^\+}/) &&
1393 ($prevline !~ /^ }/) &&
1394 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1395 ($prevline !~ /\b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=)/)) {
1397 ($prevline !~ /^.DECLARE_$Ident\(\Q$name\E\)/) &&
1398 ($prevline !~ /^.LIST_HEAD\(\Q$name\E\)/) &&
1399 ($prevline !~ /\b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=|\[)/)) {
1400 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1401 WARN
("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
1405 # check for external initialisers.
1406 if ($line =~ /^.$Type\s*$Ident\s*=\s*(0|NULL);/) {
1407 ERROR
("do not initialise externals to 0 or NULL\n" .
1410 # check for static initialisers.
1411 if ($line =~ /\s*static\s.*=\s*(0|NULL);/) {
1412 ERROR
("do not initialise statics to 0 or NULL\n" .
1416 # check for new typedefs, only function parameters and sparse annotations
1418 if ($line =~ /\btypedef\s/ &&
1419 $line !~ /\btypedef\s+$Type\s+\(\s*\*?$Ident\s*\)\s*\(/ &&
1420 $line !~ /\b__bitwise(?:__|)\b/) {
1421 WARN
("do not add new typedefs\n" . $herecurr);
1424 # * goes on variable not on type
1425 if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) {
1426 ERROR
("\"(foo$1)\" should be \"(foo $1)\"\n" .
1429 } elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) {
1430 ERROR
("\"(foo $1 )\" should be \"(foo $1)\"\n" .
1433 } elsif ($line =~ m{$NonptrType(\*+)(?:\s+(?:$Attribute|$Sparse))?\s+[A-Za-z\d_]+}) {
1434 ERROR
("\"foo$1 bar\" should be \"foo $1bar\"\n" .
1437 } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+(?:$Attribute|$Sparse))\s+[A-Za-z\d_]+}) {
1438 ERROR
("\"foo $1 bar\" should be \"foo $1bar\"\n" .
1442 # # no BUG() or BUG_ON()
1443 # if ($line =~ /\b(BUG|BUG_ON)\b/) {
1444 # print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n";
1445 # print "$herecurr";
1449 if ($line =~ /\bLINUX_VERSION_CODE\b/) {
1450 WARN
("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
1453 # printk should use KERN_* levels. Note that follow on printk's on the
1454 # same line do not need a level, so we use the current block context
1455 # to try and find and validate the current printk. In summary the current
1456 # printk includes all preceeding printk's which have no newline on the end.
1457 # we assume the first bad printk is the one to report.
1458 if ($line =~ /\bprintk\((?!KERN_)\s*"/) {
1460 for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) {
1461 #print "CHECK<$lines[$ln - 1]\n";
1462 # we have a preceeding printk if it ends
1463 # with "\n" ignore it, else it is to blame
1464 if ($lines[$ln - 1] =~ m{\bprintk\(}) {
1465 if ($rawlines[$ln - 1] !~ m{\\n"}) {
1472 WARN
("printk() should include KERN_ facility level\n" . $herecurr);
1476 # function brace can't be on same line, except for #defines of do while,
1477 # or if closed on same line
1478 if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).*\s{/) and
1479 !($line=~/\#define.*do\s{/) and !($line=~/}/)) {
1480 ERROR
("open brace '{' following function declarations go on the next line\n" . $herecurr);
1483 # open braces for enum, union and struct go on the same line.
1484 if ($line =~ /^.\s*{/ &&
1485 $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
1486 ERROR
("open brace '{' following $1 go on the same line\n" . $hereprev);
1489 # check for spaces between functions and their parentheses.
1490 while ($line =~ /($Ident)\s+\(/g) {
1492 my $ctx = substr($line, 0, $-[1]);
1494 # Ignore those directives where spaces _are_ permitted.
1495 if ($name =~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright|case|__asm__)$/) {
1497 # cpp #define statements have non-optional spaces, ie
1498 # if there is a space between the name and the open
1499 # parenthesis it is simply not a parameter group.
1500 } elsif ($ctx =~ /^.\#\s*define\s*$/) {
1502 # If this whole things ends with a type its most
1503 # likely a typedef for a function.
1504 } elsif ("$ctx$name" =~ /$Type$/) {
1507 WARN
("no space between function name and open parenthesis '('\n" . $herecurr);
1510 # Check operator spacing.
1511 if (!($line=~/\#\s*include/)) {
1513 <<=|>>=|<=|>=|==|!=|
1514 \
+=|-=|\
*=|\
/=|%=|\
^=|\
|=|&=|
1515 =>|->|<<|>>|<|>|=|!|~|
1516 &&|\
|\
||,|\
^|\
+\
+|--|&|\
||\
+|-|\
*|\
/|%
1518 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1519 my @elements = split(/($;+|$ops|;)/, $opline);
1521 my @elements = split(/($ops|;)/, $opline);
1522 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1525 my $blank = copy_spacing
($opline);
1527 for (my $n = 0; $n < $#elements; $n += 2) {
1528 $off += length($elements[$n]);
1531 $a = 'V' if ($elements[$n] ne '');
1532 $a = 'W' if ($elements[$n] =~ /\s$/);
1533 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1535 $a = 'C' if ($elements[$n] =~ /$;$/);
1536 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1537 $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
1538 $a = 'O' if ($elements[$n] eq '');
1539 $a = 'E' if ($elements[$n] eq '' && $n == 0);
1541 my $op = $elements[$n + 1];
1544 if (defined $elements[$n + 2]) {
1545 $c = 'V' if ($elements[$n + 2] ne '');
1546 $c = 'W' if ($elements[$n + 2] =~ /^\s/);
1547 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1549 $c = 'C' if ($elements[$n + 2] =~ /^$;/);
1550 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1551 $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
1552 $c = 'O' if ($elements[$n + 2] eq '');
1553 $c = 'E' if ($elements[$n + 2] =~ /\s*\\$/);
1558 # Pick up the preceeding and succeeding characters.
1559 my $ca = substr($opline, 0, $off);
1561 if (length($opline) >= ($off + length($elements[$n + 1]))) {
1562 $cc = substr($opline, $off + length($elements[$n + 1]));
1564 my $cb = "$ca$;$cc";
1566 my $ctx = "${a}x${c}";
1568 my $at = "(ctx:$ctx)";
1570 my $ptr = substr($blank, 0, $off) . "^";
1571 my $hereptr = "$hereline$ptr\n";
1573 # Classify operators into binary, unary, or
1574 # definitions (* only) where they have more
1576 my $op_type = substr($curr_values, $off + 1, 1);
1577 my $op_left = substr($curr_values, $off, 1);
1579 if ($op_type eq 'T') {
1581 } elsif ($op_left eq 'V') {
1586 #if ($op eq '-' || $op eq '&' || $op eq '*') {
1587 # print "UNARY: <$op_left$op_type $is_unary $a:$op:$c> <$ca:$op:$cc> <$unary_ctx>\n";
1590 # Ignore operators passed as parameters.
1591 if ($op_type ne 'V' &&
1592 $ca =~ /\s$/ && $cc =~ /^\s*,/) {
1594 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1596 } elsif ($op =~ /^$;+$/) {
1599 # } elsif ($op =~ /^$;+$/) {
1600 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1602 # ; should have either the end of line or a space or \ after it
1603 } elsif ($op eq ';') {
1604 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1605 if ($ctx !~ /.x[WEB]/ && $cc !~ /^\\/ &&
1608 if ($ctx !~ /.x[WEBC]/ &&
1609 $cc !~ /^\\/ && $cc !~ /^;/) {
1610 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1611 ERROR
("need space after that '$op' $at\n" . $hereptr);
1615 } elsif ($op eq '//') {
1617 # -> should have no spaces
1618 } elsif ($op eq '->') {
1619 if ($ctx =~ /Wx.|.xW/) {
1620 ERROR
("no spaces around that '$op' $at\n" . $hereptr);
1623 # , must have a space on the right.
1624 } elsif ($op eq ',') {
1625 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1626 if ($ctx !~ /.xW|.xE/ && $cc !~ /^}/) {
1628 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
1629 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1630 ERROR
("need space after that '$op' $at\n" . $hereptr);
1633 # '*' as part of a type definition -- reported already.
1634 } elsif ($op eq '*' && $is_unary == 2) {
1635 #warn "'*' is part of type\n";
1637 # unary operators should have a space before and
1638 # none after. May be left adjacent to another
1639 # unary operator, or a cast
1640 } elsif ($op eq '!' || $op eq '~' ||
1641 ($is_unary && ($op eq '*' || $op eq '-' || $op eq '&'))) {
1642 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1643 if ($ctx !~ /[WEB]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
1645 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
1646 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1647 ERROR
("need space before that '$op' $at\n" . $hereptr);
1649 if ($ctx =~ /.xW/) {
1650 ERROR
("no space after that '$op' $at\n" . $hereptr);
1653 # unary ++ and unary -- are allowed no space on one side.
1654 } elsif ($op eq '++' or $op eq '--') {
1655 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1656 if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) {
1658 if ($ctx !~ /[WOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
1659 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1660 ERROR
("need space one side of that '$op' $at\n" . $hereptr);
1662 if ($ctx =~ /WxB/ || ($ctx =~ /Wx./ && $cc =~ /^;/)) {
1663 ERROR
("no space before that '$op' $at\n" . $hereptr);
1666 # << and >> may either have or not have spaces both sides
1667 } elsif ($op eq '<<' or $op eq '>>' or
1668 $op eq '&' or $op eq '^' or $op eq '|' or
1669 $op eq '+' or $op eq '-' or
1670 $op eq '*' or $op eq '/' or
1673 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1674 if ($ctx !~ /VxV|WxW|VxE|WxE|VxO/) {
1676 if ($ctx !~ /VxV|WxW|VxE|WxE|VxO|Cx.|.xC/) {
1677 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1678 ERROR
("need consistent spacing around '$op' $at\n" .
1682 # All the others need spaces both sides.
1683 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1684 } elsif ($ctx !~ /[EW]x[WE]/) {
1686 } elsif ($ctx !~ /[EWC]x[CWE]/) {
1687 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1688 # Ignore email addresses <foo@bar>
1689 if (!($op eq '<' && $cb =~ /$;\S+\@\S+>/) &&
1690 !($op eq '>' && $cb =~ /<\S+\@\S+$;/)) {
1691 ERROR
("need spaces around that '$op' $at\n" . $hereptr);
1694 $off += length($elements[$n + 1]);
1698 # check for multiple assignments
1699 if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
1700 CHK
("multiple assignments should be avoided\n" . $herecurr);
1703 ## # check for multiple declarations, allowing for a function declaration
1705 ## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
1706 ## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
1708 ## # Remove any bracketed sections to ensure we do not
1709 ## # falsly report the parameters of functions.
1711 ## while ($ln =~ s/\([^\(\)]*\)//g) {
1713 ## if ($ln =~ /,/) {
1714 ## WARN("declaring multiple variables together should be avoided\n" . $herecurr);
1718 #need space before brace following if, while, etc
1719 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) ||
1721 ERROR
("need a space before the open brace '{'\n" . $herecurr);
1724 # closing brace should have a space following it when it has anything
1726 if ($line =~ /}(?!(?:,|;|\)))\S/) {
1727 ERROR
("need a space after that close brace '}'\n" . $herecurr);
1730 # check spacing on square brackets
1731 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
1732 ERROR
("no space after that open square bracket '['\n" . $herecurr);
1734 if ($line =~ /\s\]/) {
1735 ERROR
("no space before that close square bracket ']'\n" . $herecurr);
1738 # check spacing on paretheses
1739 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
1740 $line !~ /for\s*\(\s+;/) {
1741 ERROR
("no space after that open parenthesis '('\n" . $herecurr);
1743 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
1744 $line !~ /for\s*\(.*;\s+\)/) {
1745 ERROR
("no space before that close parenthesis ')'\n" . $herecurr);
1748 #goto labels aren't indented, allow a single space however
1749 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
1750 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
1751 WARN
("labels should not be indented\n" . $herecurr);
1754 # Need a space before open parenthesis after if, while etc
1755 if ($line=~/\b(if|while|for|switch)\(/) {
1756 ERROR
("need a space before the open parenthesis '('\n" . $herecurr);
1759 # Check for illegal assignment in if conditional.
1760 if ($line =~ /\bif\s*\(/) {
1761 my ($s, $c) = ctx_statement_block
($linenr, $realcnt, 0);
1763 if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) {
1764 ERROR
("do not use assignment in if condition\n" . $herecurr);
1767 # Find out what is on the end of the line after the
1769 substr($s, 0, length($c)) = '';
1771 $s =~ s/$;//g; # Remove any comments
1772 if (length($c) && $s !~ /^\s*({|;|)\s*\\*\s*$/) {
1773 ERROR
("trailing statements should be on next line\n" . $herecurr);
1777 # Check for bitwise tests written as boolean
1789 WARN
("boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
1792 # if and else should not have general statements after it
1793 if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/) {
1795 $s =~ s/$;//g; # Remove any comments
1796 if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
1797 ERROR
("trailing statements should be on next line\n" . $herecurr);
1801 # Check for }<nl>else {, these must be at the same
1802 # indent level to be relevant to each other.
1803 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
1804 $previndent == $indent) {
1805 ERROR
("else should follow close brace '}'\n" . $hereprev);
1808 if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and
1809 $previndent == $indent) {
1810 my ($s, $c) = ctx_statement_block
($linenr, $realcnt, 0);
1812 # Find out what is on the end of the line after the
1814 substr($s, 0, length($c)) = '';
1817 if ($s =~ /^\s*;/) {
1818 ERROR
("while should follow close brace '}'\n" . $hereprev);
1822 #studly caps, commented out until figure out how to distinguish between use of existing and adding new
1823 # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) {
1824 # print "No studly caps, use _\n";
1825 # print "$herecurr";
1829 #no spaces allowed after \ in define
1830 if ($line=~/\#define.*\\\s$/) {
1831 WARN
("Whitepspace after \\ makes next lines useless\n" . $herecurr);
1834 #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
1835 if ($tree && $rawline =~ m{^.\#\s*include\s*\<asm\/(.*)\.h\>}) {
1836 my $checkfile = "$root/include/linux/$1.h";
1837 if (-f
$checkfile && $1 ne 'irq.h') {
1838 CHK
("Use #include <linux/$1.h> instead of <asm/$1.h>\n" .
1843 # multi-statement macros should be enclosed in a do while loop, grab the
1844 # first statement and ensure its the whole macro if its not enclosed
1845 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1846 # in a known goot container
1848 # in a known good container
1849 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1850 if ($prevline =~ /\#define.*\\/ &&
1851 $prevline !~/(?:do\s+{|\(\{|\{)/ &&
1852 $line !~ /(?:do\s+{|\(\{|\{)/ &&
1853 $line !~ /^.\s*$Declare\s/) {
1854 # Grab the first statement, if that is the entire macro
1855 # its ok. This may start either on the #define line
1861 # If the macro starts on the define line start
1862 # grabbing the statement after the identifier
1863 $prevline =~ m{^(.#\s*define\s*$Ident(?:\([^\)]*\))?\s*)(.*)\\\s*$};
1864 ##print "1<$1> 2<$2>\n";
1865 if (defined $2 && $2 ne '') {
1869 while ($lines[$ln - 1] =~ /^-/) {
1874 my @ctx = ctx_statement
($ln, $cnt, $off);
1875 my $ctx_ln = $ln + $#ctx + 1;
1876 my $ctx = join("\n", @ctx);
1878 # Pull in any empty extension lines.
1879 while ($ctx =~ /\\$/ &&
1880 $lines[$ctx_ln - 1] =~ /^.\s*(?:\\)?$/) {
1881 $ctx .= $lines[$ctx_ln - 1];
1885 if ($ctx =~ /\\$/) {
1887 ERROR
("Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n");
1889 ERROR
("Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n");
1894 # check for redundant bracing round if etc
1895 if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
1896 my ($level, $endln, @chunks) =
1897 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1898 ctx_statement_full
($linenr, $realcnt, 0);
1900 ctx_statement_full
($linenr, $realcnt, 1);
1901 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1902 #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
1903 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1904 if ($#chunks > 1 && $level == 0) {
1906 #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
1907 if ($#chunks > 0 && $level == 0) {
1908 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1911 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1913 my $herectx = $here . "\n";;
1914 my $ln = $linenr - 1;
1915 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1916 for my $chunk (@chunks) {
1917 my ($cond, $block) = @
{$chunk};
1919 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1921 $herectx .= "$rawlines[$ln]\n[...]\n";
1922 $ln += statement_rawlines
($block) - 1;
1924 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1925 substr($block, 0, length($cond)) = '';
1927 $seen++ if ($block =~ /^\s*{/);
1929 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1930 $block =~ s/(^|\n)./$1/g;
1931 $block =~ s/^\s*{//;
1932 $block =~ s/}\s*$//;
1936 my @lines = ($block =~ /\n/g);
1937 my @statements = ($block =~ /;/g);
1939 #print "cond<$cond> block<$block> lines<" . scalar(@lines) . "> statements<" . scalar(@statements) . "> seen<$seen> allowed<$allowed>\n";
1940 if (scalar(@lines) != 0) {
1942 #print "cond<$cond> block<$block> allowed<$allowed>\n";
1943 if (statement_lines
($cond) > 1) {
1944 #print "APW: ALLOWED: cond<$cond>\n";
1945 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1948 if ($block =~/\b(?:if|for|while)\b/) {
1949 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1951 #print "APW: ALLOWED: block<$block>\n";
1952 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1955 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1956 if (scalar(@statements) > 1) {
1958 if (statement_block_size
($block) > 1) {
1959 #print "APW: ALLOWED: lines block<$block>\n";
1960 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1964 if ($seen && !$allowed) {
1965 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1966 WARN
("braces {} are not necessary for any arm of this statement\n" . $herecurr);
1967 $suppress_ifbraces = $endln;
1969 WARN
("braces {} are not necessary for any arm of this statement\n" . $herectx);
1970 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1972 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1974 # Either way we have looked over this whole
1975 # statement and said what needs to be said.
1976 $suppress_ifbraces = $endln;
1977 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
1980 if ($linenr > $suppress_ifbraces &&
1981 $line =~ /\b(if|while|for|else)\b/) {
1982 <<<<<<< HEAD
:scripts
/checkpatch
.pl
1983 # Locate the end of the opening statement.
1984 my @control = ctx_statement
($linenr, $realcnt, 0);
1985 my $nr = $linenr + (scalar(@control) - 1);
1986 my $cnt = $realcnt - (scalar(@control) - 1);
1988 my $off = $realcnt - $cnt;
1989 #print "$off: line<$line>end<" . $lines[$nr - 1] . ">\n";
1991 # If this is is a braced statement group check it
1992 if ($lines[$nr - 1] =~ /{\s*$/) {
1993 my ($lvl, @block) = ctx_block_level
($nr, $cnt);
1995 my $stmt = join("\n", @block);
1996 # Drop the diff line leader.
1997 $stmt =~ s/\n./\n/g;
1998 # Drop the code outside the block.
1999 $stmt =~ s/(^[^{]*){\s*//;
2001 $stmt =~ s/\s*}([^}]*$)//;
2004 #print "block<" . join(' ', @block) . "><" . scalar(@block) . ">\n";
2005 #print "before<$before> stmt<$stmt> after<$after>\n\n";
2007 # Count the newlines, if there is only one
2008 # then the block should not have {}'s.
2009 my @lines = ($stmt =~ /\n/g);
2010 my @statements = ($stmt =~ /;/g);
2011 #print "lines<" . scalar(@lines) . ">\n";
2012 #print "statements<" . scalar(@statements) . ">\n";
2013 if ($lvl == 0 && scalar(@lines) == 0 &&
2014 scalar(@statements) < 2 &&
2015 $stmt !~ /{/ && $stmt !~ /\bif\b/ &&
2016 $before !~ /}/ && $after !~ /{/) {
2017 my $herectx = "$here\n" . join("\n", @control, @block[1 .. $#block]) . "\n";
2019 WARN
("braces {} are not necessary for single statement blocks\n" . $herectx);
2021 my ($level, $endln, @chunks) =
2022 ctx_statement_full
($linenr, $realcnt, $-[0]);
2026 # Check the pre-context.
2027 if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
2028 #print "APW: ALLOWED: pre<$1>\n";
2031 # Check the condition.
2032 my ($cond, $block) = @
{$chunks[0]};
2033 if (defined $cond) {
2034 substr($block, 0, length($cond)) = '';
2036 if (statement_lines
($cond) > 1) {
2037 #print "APW: ALLOWED: cond<$cond>\n";
2040 if ($block =~/\b(?:if|for|while)\b/) {
2041 #print "APW: ALLOWED: block<$block>\n";
2044 if (statement_block_size
($block) > 1) {
2045 #print "APW: ALLOWED: lines block<$block>\n";
2048 # Check the post-context.
2049 if (defined $chunks[1]) {
2050 my ($cond, $block) = @
{$chunks[1]};
2051 if (defined $cond) {
2052 substr($block, 0, length($cond)) = '';
2054 if ($block =~ /^\s*\{/) {
2055 #print "APW: ALLOWED: chunk-1 block<$block>\n";
2059 if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
2060 my $herectx = $here . "\n";;
2061 my $end = $linenr + statement_rawlines
($block) - 1;
2063 for (my $ln = $linenr - 1; $ln < $end; $ln++) {
2064 $herectx .= $rawlines[$ln] . "\n";;
2065 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
2067 <<<<<<< HEAD
:scripts
/checkpatch
.pl
2070 WARN
("braces {} are not necessary for single statement blocks\n" . $herectx);
2071 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl
2075 # don't include deprecated include files (uses RAW line)
2076 for my $inc (@dep_includes) {
2077 if ($rawline =~ m@\#\s
*include\s
*\
<$inc>@
) {
2078 ERROR
("Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr);
2082 # don't use deprecated functions
2083 for my $func (@dep_functions) {
2084 if ($line =~ /\b$func\b/) {
2085 ERROR
("Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr);
2089 # no volatiles please
2090 my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
2091 if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
2092 WARN
("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
2095 # SPIN_LOCK_UNLOCKED & RW_LOCK_UNLOCKED are deprecated
2096 if ($line =~ /\b(SPIN_LOCK_UNLOCKED|RW_LOCK_UNLOCKED)/) {
2097 ERROR
("Use of $1 is deprecated: see Documentation/spinlocks.txt\n" . $herecurr);
2101 if ($line =~ /^.#\s*if\s+0\b/) {
2102 CHK
("if this code is redundant consider removing it\n" .
2106 # check for needless kfree() checks
2107 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
2109 if ($line =~ /\bkfree\(\Q$expr\E\);/) {
2110 WARN
("kfree(NULL) is safe this check is probabally not required\n" . $hereprev);
2114 # warn about #ifdefs in C files
2115 # if ($line =~ /^.#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
2116 # print "#ifdef in C files should be avoided\n";
2117 # print "$herecurr";
2121 # warn about spacing in #ifdefs
2122 if ($line =~ /^.#\s*(ifdef|ifndef|elif)\s\s+/) {
2123 ERROR
("exactly one space required after that #$1\n" . $herecurr);
2126 # check for spinlock_t definitions without a comment.
2127 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) {
2129 if (!ctx_has_comment
($first_line, $linenr)) {
2130 CHK
("$1 definition without comment\n" . $herecurr);
2133 # check for memory barriers without a comment.
2134 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
2135 if (!ctx_has_comment
($first_line, $linenr)) {
2136 CHK
("memory barrier without comment\n" . $herecurr);
2139 # check of hardware specific defines
2140 if ($line =~ m@
^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
2141 CHK
("architecture specific defines should be avoided\n" . $herecurr);
2144 # check the location of the inline attribute, that it is between
2145 # storage class and type.
2146 if ($line =~ /\b$Type\s+$Inline\b/ ||
2147 $line =~ /\b$Inline\s+$Storage\b/) {
2148 ERROR
("inline keyword should sit between storage class and type\n" . $herecurr);
2151 # Check for __inline__ and __inline, prefer inline
2152 if ($line =~ /\b(__inline__|__inline)\b/) {
2153 WARN
("plain inline is preferred over $1\n" . $herecurr);
2156 # check for new externs in .c files.
2157 if ($line =~ /^.\s*extern\s/ && ($realfile =~ /\.c$/)) {
2158 WARN
("externs should be avoided in .c files\n" . $herecurr);
2161 # checks for new __setup's
2162 if ($rawline =~ /\b__setup\("([^"]*)"/) {
2165 if (!grep(/$name/, @setup_docs)) {
2166 CHK
("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
2170 # check for pointless casting of kmalloc return
2171 if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) {
2172 WARN
("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
2175 # check for gcc specific __FUNCTION__
2176 if ($line =~ /__FUNCTION__/) {
2177 WARN
("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr);
2181 # If we have no input at all, then there is nothing to report on
2182 # so just keep quiet.
2183 if ($#rawlines == -1) {
2187 # In mailback mode only produce a report in the negative, for
2188 # things that appear to be patches.
2189 if ($mailback && ($clean == 1 || !$is_patch)) {
2193 # This is not a patch, and we are are in 'no-patch' mode so
2195 if (!$chk_patch && !$is_patch) {
2200 ERROR
("Does not appear to be a unified-diff format patch\n");
2202 if ($is_patch && $chk_signoff && $signoff == 0) {
2203 ERROR
("Missing Signed-off-by: line(s)\n");
2206 print report_dump
();
2207 if ($summary && !($clean == 1 && $quiet == 1)) {
2208 print "$filename " if ($summary_file);
2209 print "total: $cnt_error errors, $cnt_warn warnings, " .
2210 (($check)?
"$cnt_chk checks, " : "") .
2211 "$cnt_lines lines checked\n";
2212 print "\n" if ($quiet == 0);
2215 if ($clean == 1 && $quiet == 0) {
2216 print "$vname has no obvious style problems and is ready for submission.\n"
2218 if ($clean == 0 && $quiet == 0) {
2219 print "$vname has style problems, please review. If any of these errors\n";
2220 print "are false positives report them to the maintainer, see\n";
2221 print "CHECKPATCH in MAINTAINERS.\n";
2223 <<<<<<< HEAD
:scripts
/checkpatch
.pl
2224 print <<EOL if ($file == 1 && $quiet == 0);
2226 WARNING: Using --file mode. Please do not send patches to linux-kernel
2227 that change whole existing files if you did not significantly change most
2228 of the the file for other reasons anyways or just wrote the file newly
2229 from scratch. Pure code style patches have a significant cost in a
2230 quickly changing code base like Linux because they cause rejects
2234 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a
:scripts
/checkpatch
.pl