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
14 use Getopt::Long qw(:config no_auto_abbrev);
24 'signoff!' => \$chk_signoff,
25 'patch!' => \$chk_patch,
26 'test-type!' => \$tst_type,
32 print "usage: $P [options] patchfile\n";
33 print "version: $V\n";
34 print "options: -q => quiet\n";
35 print " --no-tree => run without a kernel tree\n";
39 if ($tree && !top_of_kernel_tree()) {
40 print "Must be run from the top-level dir. of a kernel tree\n";
44 my @dep_includes = ();
45 my @dep_functions = ();
46 my $removal = 'Documentation/feature-removal-schedule.txt';
47 if ($tree && -f $removal) {
48 open(REMOVE, "<$removal") || die "$P: $removal: open failed - $!\n";
50 if (/^Files:\s+(.*\S)/) {
51 for my $file (split(/[, ]+/, $1)) {
52 if ($file =~ m@include/(.*)@) {
53 push(@dep_includes, $1);
57 } elsif (/^Funcs:\s+(.*\S)/) {
58 for my $func (split(/[, ]+/, $1)) {
59 push(@dep_functions, $func);
70 if (!process($ARGV, @rawlines)) {
79 sub top_of_kernel_tree {
80 if ((-f "COPYING") && (-f "CREDITS") && (-f "Kbuild") &&
81 (-f "MAINTAINERS") && (-f "Makefile") && (-f "README") &&
82 (-d "Documentation") && (-d "arch") && (-d "include") &&
83 (-d "drivers") && (-d "fs") && (-d "init") && (-d "ipc") &&
84 (-d "kernel") && (-d "lib") && (-d "scripts")) {
95 for my $c (split(//, $str)) {
99 for (; ($n % 8) != 0; $n++) {
114 # Drop the diff line leader and expand tabs
116 $line = expand_tabs($line);
118 # Pick the indent from the front of the line.
119 my ($white) = ($line =~ /^(\s*)/);
121 return (length($line), length($white));
132 foreach my $c (split(//, $line)) {
133 if ($l ne "\\" && ($c eq "'" || $c eq '"')) {
139 } elsif ($quote eq $c) {
143 if ($quote && $c ne "\t") {
156 my ($linenr, $remain, $outer, $open, $close) = @_;
158 my $start = $linenr - 1;
164 for ($line = $start; $remain > 0; $line++) {
165 next if ($rawlines[$line] =~ /^-/);
168 $blk .= $rawlines[$line];
170 @o = ($blk =~ /$open/g);
171 @c = ($blk =~ /$close/g);
173 if (!$outer || (scalar(@o) - scalar(@c)) == 1) {
174 push(@res, $rawlines[$line]);
177 last if (scalar(@o) == scalar(@c));
182 sub ctx_block_outer {
183 my ($linenr, $remain) = @_;
185 return ctx_block_get($linenr, $remain, 1, '\{', '\}');
188 my ($linenr, $remain) = @_;
190 return ctx_block_get($linenr, $remain, 0, '\{', '\}');
193 my ($linenr, $remain) = @_;
195 return ctx_block_get($linenr, $remain, 0, '\(', '\)');
198 sub ctx_locate_comment {
199 my ($first_line, $end_line) = @_;
201 # Catch a comment on the end of the line itself.
202 my ($current_comment) = ($rawlines[$end_line - 1] =~ m@.*(/\*.*\*/)\s*$@);
203 return $current_comment if (defined $current_comment);
205 # Look through the context and try and figure out if there is a
208 $current_comment = '';
209 for (my $linenr = $first_line; $linenr < $end_line; $linenr++) {
210 my $line = $rawlines[$linenr - 1];
212 if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
215 if ($line =~ m@/\*@) {
218 if (!$in_comment && $current_comment ne '') {
219 $current_comment = '';
221 $current_comment .= $line . "\n" if ($in_comment);
222 if ($line =~ m@\*/@) {
227 chomp($current_comment);
228 return($current_comment);
230 sub ctx_has_comment {
231 my ($first_line, $end_line) = @_;
232 my $cmt = ctx_locate_comment($first_line, $end_line);
234 ##print "LINE: $rawlines[$end_line - 1 ]\n";
235 ##print "CMMT: $cmt\n";
250 print "ERROR: $_[0]\n";
254 print "WARNING: $_[0]\n";
258 print "CHECK: $_[0]\n";
263 my $filename = shift;
279 # Trace the real file/line as we go.
287 my $Ident = qr{[A-Za-z\d_]+};
288 my $Storage = qr{extern|static};
289 my $Sparse = qr{__user|__kernel|__force|__iomem};
318 (?:\s*\*+\s*const|\s*\*+)?
320 my $Declare = qr{(?:$Storage\s+)?$Type};
321 my $Attribute = qr{__read_mostly|__init|__initdata};
323 # Pre-scan the patch looking for any __setup documentation.
326 foreach my $line (@lines) {
327 if ($line=~/^\+\+\+\s+(\S+)/) {
329 if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
335 if ($setup_docs && $line =~ /^\+/) {
336 push(@setup_docs, $line);
340 foreach my $line (@lines) {
345 #extract the filename as it passes
346 if ($line=~/^\+\+\+\s+(\S+)/) {
348 $realfile =~ s@^[^/]*/@@;
352 #extract the line range in the file after the patch is applied
353 if ($line=~/^\@\@ -\d+,\d+ \+(\d+)(,(\d+))? \@\@/) {
355 $first_line = $linenr + 1;
366 # track the line number as we move through the hunk, note that
367 # new versions of GNU diff omit the leading space on completely
368 # blank context lines so we need to count that too.
369 if ($line =~ /^( |\+|$)/) {
371 $realcnt-- if ($realcnt != 0);
373 # track any sort of multi-line comment. Obviously if
374 # the added text or context do not include the whole
375 # comment we will not see it. Such is life.
377 # Guestimate if this is a continuing comment. If this
378 # is the start of a diff block and this line starts
379 # ' *' then it is very likely a comment.
380 if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
383 if ($line =~ m@/\*@) {
386 if ($line =~ m@\*/@) {
390 # Measure the line length and indent.
391 ($length, $indent) = line_stats($line);
393 # Track the previous line.
394 ($prevline, $stashline) = ($stashline, $line);
395 ($previndent, $stashindent) = ($stashindent, $indent);
396 } elsif ($realcnt == 1) {
400 #make up the handle for any error we report on this line
401 $here = "#$linenr: ";
402 $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
404 my $hereline = "$here\n$line\n";
405 my $herecurr = "$here\n$line\n";
406 my $hereprev = "$here\n$prevline\n$line\n";
408 #check the patch for a signoff:
409 if ($line =~ /^\s*signed-off-by:/i) {
410 # This is a signoff, if ugly, so do not double report.
412 if (!($line =~ /^\s*Signed-off-by:/)) {
413 WARN("Signed-off-by: is the preferred form\n" .
416 if ($line =~ /^\s*signed-off-by:\S/i) {
417 WARN("need space after Signed-off-by:\n" .
422 # Check for wrappage within a valid hunk of the file
423 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |$)}) {
424 ERROR("patch seems to be corrupt (line wrapped?)\n" .
428 # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
429 if (($realfile =~ /^$/ || $line =~ /^\+/) &&
431 [\x09\x0A\x0D\x20-\x7E] # ASCII
432 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
433 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
434 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
435 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
436 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
437 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
438 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
440 ERROR("Invalid UTF-8\n" . $herecurr);
443 #ignore lines being removed
444 if ($line=~/^-/) {next;}
446 # check we are in a valid source file if not then ignore this hunk
447 next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/);
450 if ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) {
451 my $herevet = "$here\n" . cat_vet($line) . "\n";
452 ERROR("trailing whitespace\n" . $herevet);
455 if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) {
456 WARN("line over 80 characters\n" . $herecurr);
459 # check we are in a valid source file *.[hc] if not then ignore this hunk
460 next if ($realfile !~ /\.[hc]$/);
462 # at the beginning of a line any tabs must come first and anything
463 # more than 8 must use tabs.
464 if ($line=~/^\+\s* \t\s*\S/ or $line=~/^\+\s* \s*/) {
465 my $herevet = "$here\n" . cat_vet($line) . "\n";
466 ERROR("use tabs not spaces\n" . $herevet);
470 # The rest of our checks refer specifically to C style
471 # only apply those _outside_ comments.
473 next if ($in_comment);
475 # Remove comments from the line before processing.
476 $line =~ s@/\*.*\*/@@g;
480 # Standardise the strings and chars within the input to simplify matching.
481 $line = sanitise_line($line);
484 # Checks which may be anchored in the context.
487 # Check for switch () and associated case and default
488 # statements should be at the same indent.
489 if ($line=~/\bswitch\s*\(.*\)/) {
492 my @ctx = ctx_block_outer($linenr, $realcnt);
495 my ($clen, $cindent) = line_stats($ctx);
496 if ($ctx =~ /^\+\s*(case\s+|default:)/ &&
497 $indent != $cindent) {
498 $err .= "$sep$ctx\n";
505 ERROR("switch and case should be at the same indent\n$hereline\n$err\n");
509 # if/while/etc brace do not go on next line, unless defining a do while loop,
510 # or if that brace on the next line is for something else
511 if ($line =~ /\b(?:(if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.#/) {
512 my @ctx = ctx_statement($linenr, $realcnt);
513 my $ctx_ln = $linenr + $#ctx + 1;
514 my $ctx_cnt = $realcnt - $#ctx - 1;
515 my $ctx = join("\n", @ctx);
517 while ($ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^-/) {
521 ##warn "line<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>";
523 if ($ctx !~ /{\s*/ && $ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
524 ERROR("That { should be on the previous line\n" .
525 "$here\n$ctx\n$lines[$ctx_ln - 1]");
529 #ignore lines not being added
530 if ($line=~/^[^\+]/) {next;}
532 # TEST: allow direct testing of the type matcher.
533 if ($tst_type && $line =~ /^.$Declare$/) {
534 ERROR("TEST: is type $Declare\n" . $herecurr);
539 # Checks which are anchored on the added line.
542 # check for malformed paths in #include statements (uses RAW line)
543 if ($rawline =~ m{^.#\s*include\s+[<"](.*)[">]}) {
545 if ($path =~ m{//}) {
546 ERROR("malformed #include filename\n" .
549 # Sanitise this special form of string.
550 $path = 'X' x length($path);
551 $line =~ s{\<.*\>}{<$path>};
555 if ($line =~ m{//}) {
556 ERROR("do not use C99 // comments\n" . $herecurr);
558 # Remove C99 comments.
561 #EXPORT_SYMBOL should immediately follow its function closing }.
562 if (($line =~ /EXPORT_SYMBOL.*\((.*)\)/) ||
563 ($line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
565 if (($prevline !~ /^}/) &&
566 ($prevline !~ /^\+}/) &&
567 ($prevline !~ /^ }/) &&
568 ($prevline !~ /\s$name(?:\s+$Attribute)?\s*(?:;|=)/)) {
569 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
573 # check for static initialisers.
574 if ($line=~/\s*static\s.*=\s+(0|NULL);/) {
575 ERROR("do not initialise statics to 0 or NULL\n" .
579 # check for new typedefs, only function parameters and sparse annotations
581 if ($line =~ /\btypedef\s/ &&
582 $line !~ /\btypedef\s+$Type\s+\(\s*\*$Ident\s*\)\s*\(/ &&
583 $line !~ /\b__bitwise(?:__|)\b/) {
584 WARN("do not add new typedefs\n" . $herecurr);
587 # * goes on variable not on type
588 if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) {
589 ERROR("\"(foo$1)\" should be \"(foo $1)\"\n" .
592 } elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) {
593 ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" .
596 } elsif ($line =~ m{$NonptrType(\*+)(?:\s+const)?\s+[A-Za-z\d_]+}) {
597 ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" .
600 } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+const)\s+[A-Za-z\d_]+}) {
601 ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" .
605 # # no BUG() or BUG_ON()
606 # if ($line =~ /\b(BUG|BUG_ON)\b/) {
607 # print "Try to use WARN_ON & Recovery code rather than BUG() or BUG_ON()\n";
612 # printk should use KERN_* levels. Note that follow on printk's on the
613 # same line do not need a level, so we use the current block context
614 # to try and find and validate the current printk. In summary the current
615 # printk includes all preceeding printk's which have no newline on the end.
616 # we assume the first bad printk is the one to report.
617 if ($line =~ /\bprintk\((?!KERN_)/) {
619 for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) {
620 #print "CHECK<$lines[$ln - 1]\n";
621 # we have a preceeding printk if it ends
622 # with "\n" ignore it, else it is to blame
623 if ($lines[$ln - 1] =~ m{\bprintk\(}) {
624 if ($rawlines[$ln - 1] !~ m{\\n"}) {
631 WARN("printk() should include KERN_ facility level\n" . $herecurr);
635 # function brace can't be on same line, except for #defines of do while,
636 # or if closed on same line
637 if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).* {/) and
638 !($line=~/\#define.*do\s{/) and !($line=~/}/)) {
639 ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr);
642 # Check operator spacing.
643 # Note we expand the line with the leading + as the real
644 # line will be displayed with the leading + and the tabs
645 # will therefore also expand that way.
647 $opline = expand_tabs($opline);
649 if (!($line=~/\#\s*include/)) {
650 my @elements = split(/(<<=|>>=|<=|>=|==|!=|\+=|-=|\*=|\/=|%=|\^=|\|=|&=|->|<<|>>|<|>|=|!|~|&&|\|\||,|\^|\+\+|--|;|&|\||\+|-|\*|\/\/|\/)/, $opline);
652 for (my $n = 0; $n < $#elements; $n += 2) {
653 $off += length($elements[$n]);
656 $a = 'V' if ($elements[$n] ne '');
657 $a = 'W' if ($elements[$n] =~ /\s$/);
658 $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
659 $a = 'O' if ($elements[$n] eq '');
660 $a = 'E' if ($elements[$n] eq '' && $n == 0);
662 my $op = $elements[$n + 1];
665 if (defined $elements[$n + 2]) {
666 $c = 'V' if ($elements[$n + 2] ne '');
667 $c = 'W' if ($elements[$n + 2] =~ /^\s/);
668 $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
669 $c = 'O' if ($elements[$n + 2] eq '');
674 # Pick up the preceeding and succeeding characters.
675 my $ca = substr($opline, 0, $off);
677 if (length($opline) >= ($off + length($elements[$n + 1]))) {
678 $cc = substr($opline, $off + length($elements[$n + 1]));
682 my $ctx = "${a}x${c}";
684 my $at = "(ctx:$ctx)";
686 my $ptr = (" " x $off) . "^";
687 my $hereptr = "$hereline$ptr\n";
689 ##print "<$s1:$op:$s2> <$elements[$n]:$elements[$n + 1]:$elements[$n + 2]>\n";
691 # ; should have either the end of line or a space or \ after it
693 if ($ctx !~ /.x[WEB]/ && $cc !~ /^\\/ &&
695 ERROR("need space after that '$op' $at\n" . $hereptr);
699 } elsif ($op eq '//') {
701 # -> should have no spaces
702 } elsif ($op eq '->') {
703 if ($ctx =~ /Wx.|.xW/) {
704 ERROR("no spaces around that '$op' $at\n" . $hereptr);
707 # , must have a space on the right.
708 } elsif ($op eq ',') {
709 if ($ctx !~ /.xW|.xE/ && $cc !~ /^}/) {
710 ERROR("need space after that '$op' $at\n" . $hereptr);
713 # unary ! and unary ~ are allowed no space on the right
714 } elsif ($op eq '!' or $op eq '~') {
715 if ($ctx !~ /[WOEB]x./) {
716 ERROR("need space before that '$op' $at\n" . $hereptr);
719 ERROR("no space after that '$op' $at\n" . $hereptr);
722 # unary ++ and unary -- are allowed no space on one side.
723 } elsif ($op eq '++' or $op eq '--') {
724 if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) {
725 ERROR("need space one side of that '$op' $at\n" . $hereptr);
727 if ($ctx =~ /Wx./ && $cc =~ /^;/) {
728 ERROR("no space before that '$op' $at\n" . $hereptr);
731 # & is both unary and binary
734 # binary (consistent spacing):
738 # boiling down to: if there is a space on the right then there
739 # should be one on the left.
743 } elsif ($op eq '&' or $op eq '-') {
744 if ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]/) {
745 ERROR("need space before that '$op' $at\n" . $hereptr);
748 # * is the same as & only adding:
753 } elsif ($op eq '*') {
754 if ($ca !~ /$Type$/ && $cb !~ /(\*$;|$;\*)/ &&
755 $ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]|OxV|WxB|BxB/) {
756 ERROR("need space before that '$op' $at\n" . $hereptr);
759 # << and >> may either have or not have spaces both sides
760 } elsif ($op eq '<<' or $op eq '>>' or $op eq '+' or $op eq '/' or
761 $op eq '^' or $op eq '|')
763 if ($ctx !~ /VxV|WxW|VxE|WxE/) {
764 ERROR("need consistent spacing around '$op' $at\n" .
768 # All the others need spaces both sides.
769 } elsif ($ctx !~ /[EW]x[WE]/) {
770 ERROR("need spaces around that '$op' $at\n" . $hereptr);
772 $off += length($elements[$n + 1]);
776 #need space before brace following if, while, etc
777 if ($line =~ /\(.*\){/ || $line =~ /do{/) {
778 ERROR("need a space before the open brace '{'\n" . $herecurr);
781 # closing brace should have a space following it when it has anything
783 if ($line =~ /}(?!(?:,|;|\)))\S/) {
784 ERROR("need a space after that close brace '}'\n" . $herecurr);
787 #goto labels aren't indented, allow a single space however
788 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
789 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
790 WARN("labels should not be indented\n" . $herecurr);
793 # Need a space before open parenthesis after if, while etc
794 if ($line=~/\b(if|while|for|switch)\(/) {
795 ERROR("need a space before the open parenthesis '('\n" . $herecurr);
798 # Check for illegal assignment in if conditional.
799 if ($line=~/\bif\s*\(.*[^<>!=]=[^=].*\)/) {
800 #next if ($line=~/\".*\Q$op\E.*\"/ or $line=~/\'\Q$op\E\'/);
801 ERROR("do not use assignment in if condition\n" . $herecurr);
804 # Check for }<nl>else {, these must be at the same
805 # indent level to be relevant to each other.
806 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
807 $previndent == $indent) {
808 ERROR("else should follow close brace '}'\n" . $hereprev);
811 #studly caps, commented out until figure out how to distinguish between use of existing and adding new
812 # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) {
813 # print "No studly caps, use _\n";
818 #no spaces allowed after \ in define
819 if ($line=~/\#define.*\\\s$/) {
820 WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr);
823 #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
824 if ($tree && $rawline =~ m{^.\#\s*include\s*\<asm\/(.*)\.h\>}) {
825 my $checkfile = "include/linux/$1.h";
827 CHK("Use #include <linux/$1.h> instead of <asm/$1.h>\n" .
832 # if and else should not have general statements after it
833 if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/ &&
834 $1 !~ /^\s*(?:\sif|{|\\|$)/) {
835 ERROR("trailing statements should be on next line\n" . $herecurr);
838 # multi-statement macros should be enclosed in a do while loop, grab the
839 # first statement and ensure its the whole macro if its not enclosed
840 # in a known goot container
841 if (($prevline=~/\#define.*\\/) and
842 !($prevline=~/do\s+{/) and !($prevline=~/\(\{/) and
843 !($line=~/do.*{/) and !($line=~/\(\{/) and
844 !($line=~/^.\s*$Declare\s/)) {
845 # Grab the first statement, if that is the entire macro
846 # its ok. This may start either on the #define line
851 # If the macro starts on the define line start there.
852 if ($prevline !~ m{^.#\s*define\s*$Ident(?:\([^\)]*\))?\s*\\\s*$}) {
856 my @ctx = ctx_statement($ln, $cnt);
857 my $ctx_ln = $ln + $#ctx + 1;
858 my $ctx = join("\n", @ctx);
860 # Pull in any empty extension lines.
861 while ($ctx =~ /\\$/ &&
862 $lines[$ctx_ln - 1] =~ /^.\s*(?:\\)?$/) {
863 $ctx .= $lines[$ctx_ln - 1];
869 ERROR("Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n");
871 ERROR("Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n");
876 # don't include deprecated include files (uses RAW line)
877 for my $inc (@dep_includes) {
878 if ($rawline =~ m@\#\s*include\s*\<$inc>@) {
879 ERROR("Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr);
883 # don't use deprecated functions
884 for my $func (@dep_functions) {
885 if ($line =~ /\b$func\b/) {
886 ERROR("Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr);
890 # no volatiles please
891 if ($line =~ /\bvolatile\b/ && $line !~ /\basm\s+volatile\b/) {
892 WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
896 if ($line =~ /^.#\s*if\s+0\b/) {
897 CHK("if this code is redundant consider removing it\n" .
901 # warn about #ifdefs in C files
902 # if ($line =~ /^.#\s*if(|n)def/ && ($realfile =~ /\.c$/)) {
903 # print "#ifdef in C files should be avoided\n";
908 # check for spinlock_t definitions without a comment.
909 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) {
911 if (!ctx_has_comment($first_line, $linenr)) {
912 CHK("$1 definition without comment\n" . $herecurr);
915 # check for memory barriers without a comment.
916 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
917 if (!ctx_has_comment($first_line, $linenr)) {
918 CHK("memory barrier without comment\n" . $herecurr);
921 # check of hardware specific defines
922 if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@) {
923 CHK("architecture specific defines should be avoided\n" . $herecurr);
926 # check the location of the inline attribute, that it is between
927 # storage class and type.
928 if ($line =~ /$Type\s+(?:inline|__always_inline)\b/ ||
929 $line =~ /\b(?:inline|always_inline)\s+$Storage/) {
930 ERROR("inline keyword should sit between storage class and type\n" . $herecurr);
933 # check for new externs in .c files.
934 if ($line =~ /^.\s*extern\s/ && ($realfile =~ /\.c$/)) {
935 WARN("externs should be avoided in .c files\n" . $herecurr);
938 # checks for new __setup's
939 if ($rawline =~ /\b__setup\("([^"]*)"/) {
942 if (!grep(/$name/, @setup_docs)) {
943 CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
948 if ($chk_patch && !$is_patch) {
949 ERROR("Does not appear to be a unified-diff format patch\n");
951 if ($is_patch && $chk_signoff && $signoff == 0) {
952 ERROR("Missing Signed-off-by: line(s)\n");
955 if ($clean == 1 && $quiet == 0) {
956 print "Your patch has no obvious style problems and is ready for submission.\n"
958 if ($clean == 0 && $quiet == 0) {
959 print "Your patch has style problems, please review. If any of these errors\n";
960 print "are false positives report them to the maintainer, see\n";
961 print "CHECKPATCH in MAINTAINERS.\n";