History

update checkpatch.pl to version 0.07

This version brings a number of new checks, fixes for flase positives, plus a clarification of the output to better guide use. Of note: - checks for documentation for new __setup calls - clearer reporting where braces and parenthesis are involved - reports for closing brace and semi-colon spacing - reports on unwanted externs This patch includes an update to the documentation on checkpatch.pl itself to clarify when it should be used and to indicate that it is not intended as the final arbitor of style. Full changelog: Andy Whitcroft (19): Version: 0.07 ensure we do not apply control brace checks to preprocesor directives add {u,s}{8,16,32,64} to the type matcher accept lack of spacing after the semicolons in for (;;) report new externs in .c files fix up typedef exclusion for function prototypes else trailing statements check need to account for \ at end of line add enums to the type matcher add missing check descriptions suppress double reporting of ** spacing report on do{ spacing issues include an example of the brace/parenthesis in output check for spacing after closing braces prevent double reports on pointer spacing issues handle blank continuation lines on macros classify all reports error, warning, or check revamp hanging { checks and apply in context no spaces after the last ; in a for is ok check __setup has a corresponding addition to documentation David Woodhouse (1): limit character set used in patches and descriptions to UTF-8

Andy Whitcroft committed 19 years ago

Commit de7d4f01 parent f2a11b12 files · +196 −198Browse files

Showing the changes to scripts/checkpatch.pl (1 of 2 files). Show all

Unified · Split

scripts/checkpatch.pl+178−196
@@ -9,7 +9,7 @@ use strict; · 8 unmodified lines
99 my $P = $0;
1010 $P =~ s@.*/@@g;
1111
12−my $V = '0.06';
12+my $V = '0.07';
1313
1414 use Getopt::Long qw(:config no_auto_abbrev);
1515
@@ -246,6 +246,19 @@ sub cat_vet { · 230 unmodified lines
246246 return $vet;
247247 }
248248
249+sub ERROR {
250+ print "ERROR: $_[0]\n";
251+ our $clean = 0;
252+}
253+sub WARN {
254+ print "WARNING: $_[0]\n";
255+ our $clean = 0;
256+}
257+sub CHK {
258+ print "CHECK: $_[0]\n";
259+ our $clean = 0;
260+}
261+
249262 sub process {
250263 my $filename = shift;
251264 my @lines = @_;
@@ -259,7 +272,7 @@ sub process { · 7 unmodified lines
259272 my $previndent=0;
260273 my $stashindent=0;
261274
262− my $clean = 1;
275+ our $clean = 1;
263276 my $signoff = 0;
264277 my $is_patch = 0;
265278
@@ -290,8 +303,11 @@ sub process { · 24 unmodified lines
290303 long\s+int|
291304 long\s+long|
292305 long\s+long\s+int|
306+ u8|u16|u32|u64|
307+ s8|s16|s32|s64|
293308 struct\s+$Ident|
294309 union\s+$Ident|
310+ enum\s+$Ident|
295311 ${Ident}_t
296312 )
297313 (?:\s+$Sparse)*
@@ -304,6 +320,23 @@ sub process { · 6 unmodified lines
304320 my $Declare = qr{(?:$Storage\s+)?$Type};
305321 my $Attribute = qr{__read_mostly|__init|__initdata};
306322
323+ # Pre-scan the patch looking for any __setup documentation.
324+ my @setup_docs = ();
325+ my $setup_docs = 0;
326+ foreach my $line (@lines) {
327+ if ($line=~/^\+\+\+\s+(\S+)/) {
328+ $setup_docs = 0;
329+ if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
330+ $setup_docs = 1;
331+ }
332+ next;
333+ }
334+
335+ if ($setup_docs && $line =~ /^\+/) {
336+ push(@setup_docs, $line);
337+ }
338+ }
339+
307340 foreach my $line (@lines) {
308341 $linenr++;
309342
@@ -369,30 +402,42 @@ sub process { · 59 unmodified lines
369402 $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
370403
371404 my $hereline = "$here\n$line\n";
372− my $herecurr = "$here\n$line\n\n";
373− my $hereprev = "$here\n$prevline\n$line\n\n";
405+ my $herecurr = "$here\n$line\n";
406+ my $hereprev = "$here\n$prevline\n$line\n";
374407
375408 #check the patch for a signoff:
376409 if ($line =~ /^\s*signed-off-by:/i) {
377410 # This is a signoff, if ugly, so do not double report.
378411 $signoff++;
379412 if (!($line =~ /^\s*Signed-off-by:/)) {
380− print "Signed-off-by: is the preferred form\n";
381− print "$herecurr";
382− $clean = 0;
413+ WARN("Signed-off-by: is the preferred form\n" .
414+ $herecurr);
383415 }
384416 if ($line =~ /^\s*signed-off-by:\S/i) {
385− print "need space after Signed-off-by:\n";
386− print "$herecurr";
387− $clean = 0;
417+ WARN("need space after Signed-off-by:\n" .
418+ $herecurr);
388419 }
389420 }
390421
391422 # Check for wrappage within a valid hunk of the file
392423 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |$)}) {
393− print "patch seems to be corrupt (line wrapped?) [$realcnt]\n";
394− print "$herecurr";
395− $clean = 0;
424+ ERROR("patch seems to be corrupt (line wrapped?)\n" .
425+ $herecurr);
426+ }
427+
428+# UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
429+ if (($realfile =~ /^$/ || $line =~ /^\+/) &&
430+ !($line =~ m/^(
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
439+ )*$/x )) {
440+ ERROR("Invalid UTF-8\n" . $herecurr);
396441 }
397442
398443 #ignore lines being removed
@@ -403,16 +448,12 @@ sub process { · 4 unmodified lines
403448
404449 #trailing whitespace
405450 if ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) {
406− my $herevet = "$here\n" . cat_vet($line) . "\n\n";
407− print "trailing whitespace\n";
408− print "$herevet";
409− $clean = 0;
451+ my $herevet = "$here\n" . cat_vet($line) . "\n";
452+ ERROR("trailing whitespace\n" . $herevet);
410453 }
411454 #80 column limit
412455 if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) {
413− print "line over 80 characters\n";
414− print "$herecurr";
415− $clean = 0;
456+ WARN("line over 80 characters\n" . $herecurr);
416457 }
417458
418459 # check we are in a valid source file *.[hc] if not then ignore this hunk
@@ -421,10 +462,8 @@ sub process { · 2 unmodified lines
421462 # at the beginning of a line any tabs must come first and anything
422463 # more than 8 must use tabs.
423464 if ($line=~/^\+\s* \t\s*\S/ or $line=~/^\+\s* \s*/) {
424− my $herevet = "$here\n" . cat_vet($line) . "\n\n";
425− print "use tabs not spaces\n";
426− print "$herevet";
427− $clean = 0;
465+ my $herevet = "$here\n" . cat_vet($line) . "\n";
466+ ERROR("use tabs not spaces\n" . $herevet);
428467 }
429468
430469 #
@@ -463,9 +502,27 @@ sub process { · 32 unmodified lines
463502 }
464503 }
465504 if ($err ne '') {
466− print "switch and case should be at the same indent\n";
467− print "$here\n$line\n$err\n";
468− $clean = 0;
505+ ERROR("switch and case should be at the same indent\n$hereline\n$err\n");
506+ }
507+ }
508+
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);
516+
517+ while ($ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^-/) {
518+ $ctx_ln++;
519+ $ctx_cnt--;
520+ }
521+ ##warn "line<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>";
522+
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]");
469526 }
470527 }
471528
@@ -474,9 +531,7 @@ sub process { · 2 unmodified lines
474531
475532 # TEST: allow direct testing of the type matcher.
476533 if ($tst_type && $line =~ /^.$Declare$/) {
477− print "TEST: is type $Declare\n";
478− print "$herecurr";
479− $clean = 0;
534+ ERROR("TEST: is type $Declare\n" . $herecurr);
480535 next;
481536 }
482537
@@ -488,9 +543,8 @@ sub process { · 5 unmodified lines
488543 if ($rawline =~ m{^.#\s*include\s+[<"](.*)[">]}) {
489544 my $path = $1;
490545 if ($path =~ m{//}) {
491− print "malformed #include filename\n";
492− print "$herecurr";
493− $clean = 0;
546+ ERROR("malformed #include filename\n" .
547+ $herecurr);
494548 }
495549 # Sanitise this special form of string.
496550 $path = 'X' x length($path);
@@ -499,9 +553,7 @@ sub process { · 2 unmodified lines
499553
500554 # no C99 // comments
501555 if ($line =~ m{//}) {
502− print "do not use C99 // comments\n";
503− print "$herecurr";
504− $clean = 0;
556+ ERROR("do not use C99 // comments\n" . $herecurr);
505557 }
506558 # Remove C99 comments.
507559 $line =~ s@//.*@@;
@@ -514,49 +566,40 @@ sub process { · 6 unmodified lines
514566 ($prevline !~ /^\+}/) &&
515567 ($prevline !~ /^ }/) &&
516568 ($prevline !~ /\s$name(?:\s+$Attribute)?\s*(?:;|=)/)) {
517− print "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n";
518− print "$herecurr";
519− $clean = 0;
569+ WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
520570 }
521571 }
522572
523573 # check for static initialisers.
524574 if ($line=~/\s*static\s.*=\s+(0|NULL);/) {
525− print "do not initialise statics to 0 or NULL\n";
526− print "$herecurr";
527− $clean = 0;
575+ ERROR("do not initialise statics to 0 or NULL\n" .
576+ $herecurr);
528577 }
529578
530579 # check for new typedefs, only function parameters and sparse annotations
531580 # make sense.
532581 if ($line =~ /\btypedef\s/ &&
533− $line !~ /\btypedef\s+$Type\s+\(\s*$Ident\s*\)\s*\(/ &&
582+ $line !~ /\btypedef\s+$Type\s+\(\s*\*$Ident\s*\)\s*\(/ &&
534583 $line !~ /\b__bitwise(?:__|)\b/) {
535− print "do not add new typedefs\n";
536− print "$herecurr";
537− $clean = 0;
584+ WARN("do not add new typedefs\n" . $herecurr);
538585 }
539586
540587 # * goes on variable not on type
541588 if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) {
542− print "\"(foo$1)\" should be \"(foo $1)\"\n";
543− print "$herecurr";
544− $clean = 0;
589+ ERROR("\"(foo$1)\" should be \"(foo $1)\"\n" .
590+ $herecurr);
545591
546592 } elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) {
547− print "\"(foo $1 )\" should be \"(foo $1)\"\n";
548− print "$herecurr";
549− $clean = 0;
593+ ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" .
594+ $herecurr);
550595
551596 } elsif ($line =~ m{$NonptrType(\*+)(?:\s+const)?\s+[A-Za-z\d_]+}) {
552− print "\"foo$1 bar\" should be \"foo $1bar\"\n";
553− print "$herecurr";
554− $clean = 0;
597+ ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" .
598+ $herecurr);
555599
556600 } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+const)\s+[A-Za-z\d_]+}) {
557− print "\"foo $1 bar\" should be \"foo $1bar\"\n";
558− print "$herecurr";
559− $clean = 0;
601+ ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" .
602+ $herecurr);
560603 }
561604
562605 # # no BUG() or BUG_ON()
@@ -585,9 +628,7 @@ sub process { · 22 unmodified lines
585628 }
586629 }
587630 if ($ok == 0) {
588− print "printk() should include KERN_ facility level\n";
589− print "$herecurr";
590− $clean = 0;
631+ WARN("printk() should include KERN_ facility level\n" . $herecurr);
591632 }
592633 }
593634
@@ -595,9 +636,7 @@ sub process { · 1 unmodified line
595636 # or if closed on same line
596637 if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).* {/) and
597638 !($line=~/\#define.*do\s{/) and !($line=~/}/)) {
598− print "braces following function declarations go on the next line\n";
599− print "$herecurr";
600− $clean = 0;
639+ ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr);
601640 }
602641
603642 # Check operator spacing.
@@ -633,27 +672,27 @@ sub process { · 29 unmodified lines
633672 }
634673
635674 # Pick up the preceeding and succeeding characters.
636− my $ca = substr($opline, $off - 1, 1);
675+ my $ca = substr($opline, 0, $off);
637676 my $cc = '';
638677 if (length($opline) >= ($off + length($elements[$n + 1]))) {
639678 $cc = substr($opline, $off + length($elements[$n + 1]));
640679 }
680+ my $cb = "$ca$;$cc";
641681
642682 my $ctx = "${a}x${c}";
643683
644684 my $at = "(ctx:$ctx)";
645685
646686 my $ptr = (" " x $off) . "^";
647− my $hereptr = "$hereline$ptr\n\n";
687+ my $hereptr = "$hereline$ptr\n";
648688
649689 ##print "<$s1:$op:$s2> <$elements[$n]:$elements[$n + 1]:$elements[$n + 2]>\n";
650690
651691 # ; should have either the end of line or a space or \ after it
652692 if ($op eq ';') {
653− if ($ctx !~ /.x[WE]/ && $cc !~ /^\\/) {
654− print "need space after that '$op' $at\n";
655− print "$hereptr";
656− $clean = 0;
693+ if ($ctx !~ /.x[WEB]/ && $cc !~ /^\\/ &&
694+ $cc !~ /^;/) {
695+ ERROR("need space after that '$op' $at\n" . $hereptr);
657696 }
658697
659698 # // is a comment
@@ -662,43 +701,31 @@ sub process { · 2 unmodified lines
662701 # -> should have no spaces
663702 } elsif ($op eq '->') {
664703 if ($ctx =~ /Wx.|.xW/) {
665− print "no spaces around that '$op' $at\n";
666− print "$hereptr";
667− $clean = 0;
704+ ERROR("no spaces around that '$op' $at\n" . $hereptr);
668705 }
669706
670707 # , must have a space on the right.
671708 } elsif ($op eq ',') {
672709 if ($ctx !~ /.xW|.xE/ && $cc !~ /^}/) {
673− print "need space after that '$op' $at\n";
674− print "$hereptr";
675− $clean = 0;
710+ ERROR("need space after that '$op' $at\n" . $hereptr);
676711 }
677712
678713 # unary ! and unary ~ are allowed no space on the right
679714 } elsif ($op eq '!' or $op eq '~') {
680715 if ($ctx !~ /[WOEB]x./) {
681− print "need space before that '$op' $at\n";
682− print "$hereptr";
683− $clean = 0;
716+ ERROR("need space before that '$op' $at\n" . $hereptr);
684717 }
685718 if ($ctx =~ /.xW/) {
686− print "no space after that '$op' $at\n";
687− print "$hereptr";
688− $clean = 0;
719+ ERROR("no space after that '$op' $at\n" . $hereptr);
689720 }
690721
691722 # unary ++ and unary -- are allowed no space on one side.
692723 } elsif ($op eq '++' or $op eq '--') {
693724 if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) {
694− print "need space one side of that '$op' $at\n";
695− print "$hereptr";
696− $clean = 0;
725+ ERROR("need space one side of that '$op' $at\n" . $hereptr);
697726 }
698727 if ($ctx =~ /Wx./ && $cc =~ /^;/) {
699− print "no space before that '$op' $at\n";
700− print "$hereptr";
701− $clean = 0;
728+ ERROR("no space before that '$op' $at\n" . $hereptr);
702729 }
703730
704731 # & is both unary and binary
@@ -715,9 +742,7 @@ sub process { · 10 unmodified lines
715742 #
716743 } elsif ($op eq '&' or $op eq '-') {
717744 if ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]/) {
718− print "need space before that '$op' $at\n";
719− print "$hereptr";
720− $clean = 0;
745+ ERROR("need space before that '$op' $at\n" . $hereptr);
721746 }
722747
723748 # * is the same as & only adding:
@@ -726,16 +751,9 @@ sub process { · 2 unmodified lines
726751 # (foo **)
727752 #
728753 } elsif ($op eq '*') {
729− if ($ca eq '*') {
730− if ($cc =~ /^\s(?!\s*const)/) {
731− print "no space after that '$op' $at\n";
732− print "$hereptr";
733− $clean = 0;
734− }
735− } elsif ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]|OxV|WxB|BxB/) {
736− print "need space before that '$op' $at\n";
737− print "$hereptr";
738− $clean = 0;
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);
739757 }
740758
741759 # << and >> may either have or not have spaces both sides
@@ -743,58 +761,51 @@ sub process { · 1 unmodified line
743761 $op eq '^' or $op eq '|')
744762 {
745763 if ($ctx !~ /VxV|WxW|VxE|WxE/) {
746− print "need consistent spacing around '$op' $at\n";
747− print "$hereptr";
748− $clean = 0;
764+ ERROR("need consistent spacing around '$op' $at\n" .
765+ $hereptr);
749766 }
750767
751768 # All the others need spaces both sides.
752769 } elsif ($ctx !~ /[EW]x[WE]/) {
753− print "need spaces around that '$op' $at\n";
754− print "$hereptr";
755− $clean = 0;
770+ ERROR("need spaces around that '$op' $at\n" . $hereptr);
756771 }
757772 $off += length($elements[$n + 1]);
758773 }
759774 }
760775
761776 #need space before brace following if, while, etc
762− if ($line=~/\(.*\){/) {
763− print "need a space before the brace\n";
764− print "$herecurr";
765− $clean = 0;
777+ if ($line =~ /\(.*\){/ || $line =~ /do{/) {
778+ ERROR("need a space before the open brace '{'\n" . $herecurr);
779+ }
780+
781+# closing brace should have a space following it when it has anything
782+# on the line
783+ if ($line =~ /}(?!(?:,|;|\)))\S/) {
784+ ERROR("need a space after that close brace '}'\n" . $herecurr);
766785 }
767786
768787 #goto labels aren't indented, allow a single space however
769788 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
770789 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
771− print "labels should not be indented\n";
772− print "$herecurr";
773− $clean = 0;
790+ WARN("labels should not be indented\n" . $herecurr);
774791 }
775792
776793 # Need a space before open parenthesis after if, while etc
777794 if ($line=~/\b(if|while|for|switch)\(/) {
778− print "need a space before the open parenthesis\n";
779− print "$herecurr";
780− $clean = 0;
795+ ERROR("need a space before the open parenthesis '('\n" . $herecurr);
781796 }
782797
783798 # Check for illegal assignment in if conditional.
784799 if ($line=~/\bif\s*\(.*[^<>!=]=[^=].*\)/) {
785800 #next if ($line=~/\".*\Q$op\E.*\"/ or $line=~/\'\Q$op\E\'/);
786− print "do not use assignment in if condition\n";
787− print "$herecurr";
788− $clean = 0;
801+ ERROR("do not use assignment in if condition\n" . $herecurr);
789802 }
790803
791804 # Check for }<nl>else {, these must be at the same
792805 # indent level to be relevant to each other.
793806 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
794807 $previndent == $indent) {
795− print "else should follow close brace\n";
796− print "$hereprev";
797− $clean = 0;
808+ ERROR("else should follow close brace '}'\n" . $hereprev);
798809 }
799810
800811 #studly caps, commented out until figure out how to distinguish between use of existing and adding new
@@ -806,57 +817,22 @@ sub process { · 5 unmodified lines
806817
807818 #no spaces allowed after \ in define
808819 if ($line=~/\#define.*\\\s$/) {
809− print("Whitepspace after \\ makes next lines useless\n");
810− print "$herecurr";
811− $clean = 0;
820+ WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr);
812821 }
813822
814823 #warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
815824 if ($tree && $rawline =~ m{^.\#\s*include\s*\<asm\/(.*)\.h\>}) {
816825 my $checkfile = "include/linux/$1.h";
817826 if (-f $checkfile) {
818− print "Use #include <linux/$1.h> instead of <asm/$1.h>\n";
819− print $herecurr;
820− $clean = 0;
821− }
822− }
823−
824−# if/while/etc brace do not go on next line, unless defining a do while loop,
825−# or if that brace on the next line is for something else
826− if ($prevline=~/\b(?:(if|while|for|switch)\s*\(|do\b|else\b)/) {
827− my @opened = $prevline=~/\(/g;
828− my @closed = $prevline=~/\)/g;
829− my $nr_line = $linenr;
830− my $remaining = $realcnt - 1;
831− my $next_line = $line;
832− my $extra_lines = 0;
833− my $display_segment = $prevline;
834−
835− while ($remaining > 0 && scalar @opened > scalar @closed) {
836− $prevline .= $next_line;
837− $display_segment .= "\n" . $next_line;
838− $next_line = $lines[$nr_line];
839− $nr_line++;
840− $remaining--;
841−
842− @opened = $prevline=~/\(/g;
843− @closed = $prevline=~/\)/g;
844− }
845−
846− if (($prevline=~/\b(?:(if|while|for|switch)\s*\(.*\)|do|else)\s*$/) and ($next_line=~/{/) and
847− !($next_line=~/\b(?:if|while|for|switch|do|else)\b/) and !($next_line=~/\#define.*do.*while/)) {
848− print "That { should be on the previous line\n";
849− print "$here\n$display_segment\n$next_line\n\n";
850− $clean = 0;
827+ CHK("Use #include <linux/$1.h> instead of <asm/$1.h>\n" .
828+ $herecurr);
851829 }
852830 }
853831
854832 # if and else should not have general statements after it
855833 if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/ &&
856− $1 !~ /^\s*(?:\sif|{|$)/) {
857− print "trailing statements should be on next line\n";
858− print "$herecurr";
859− $clean = 0;
834+ $1 !~ /^\s*(?:\sif|{|\\|$)/) {
835+ ERROR("trailing statements should be on next line\n" . $herecurr);
860836 }
861837
862838 # multi-statement macros should be enclosed in a do while loop, grab the
@@ -877,49 +853,49 @@ sub process { · 14 unmodified lines
877853 $ln--;
878854 $cnt++;
879855 }
880− my $ctx = join('', ctx_statement($ln, $cnt));
856+ my @ctx = ctx_statement($ln, $cnt);
857+ my $ctx_ln = $ln + $#ctx + 1;
858+ my $ctx = join("\n", @ctx);
859+
860+ # Pull in any empty extension lines.
861+ while ($ctx =~ /\\$/ &&
862+ $lines[$ctx_ln - 1] =~ /^.\s*(?:\\)?$/) {
863+ $ctx .= $lines[$ctx_ln - 1];
864+ $ctx_ln++;
865+ }
881866
882867 if ($ctx =~ /\\$/) {
883868 if ($ctx =~ /;/) {
884− print "Macros with multiple statements should be enclosed in a do - while loop\n";
869+ ERROR("Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n");
885870 } else {
886− print "Macros with complex values should be enclosed in parenthesis\n";
871+ ERROR("Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n");
887872 }
888− print "$hereprev";
889− $clean = 0;
890873 }
891874 }
892875
893876 # don't include deprecated include files (uses RAW line)
894877 for my $inc (@dep_includes) {
895878 if ($rawline =~ m@\#\s*include\s*\<$inc>@) {
896− print "Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n";
897− print "$herecurr";
898− $clean = 0;
879+ ERROR("Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr);
899880 }
900881 }
901882
902883 # don't use deprecated functions
903884 for my $func (@dep_functions) {
904885 if ($line =~ /\b$func\b/) {
905− print "Don't use $func(): see Documentation/feature-removal-schedule.txt\n";
906− print "$herecurr";
907− $clean = 0;
886+ ERROR("Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr);
908887 }
909888 }
910889
911890 # no volatiles please
912891 if ($line =~ /\bvolatile\b/ && $line !~ /\basm\s+volatile\b/) {
913− print "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n";
914− print "$herecurr";
915− $clean = 0;
892+ WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
916893 }
917894
918895 # warn about #if 0
919896 if ($line =~ /^.#\s*if\s+0\b/) {
920− print "#if 0 -- if this code redundant remove it\n";
921− print "$herecurr";
922− $clean = 0;
897+ CHK("if this code is redundant consider removing it\n" .
898+ $herecurr);
923899 }
924900
925901 # warn about #ifdefs in C files
@@ -933,41 +909,47 @@ sub process { · 7 unmodified lines
933909 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) {
934910 my $which = $1;
935911 if (!ctx_has_comment($first_line, $linenr)) {
936− print "$1 definition without comment\n";
937− print "$herecurr";
938− $clean = 0;
912+ CHK("$1 definition without comment\n" . $herecurr);
939913 }
940914 }
941915 # check for memory barriers without a comment.
942916 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
943917 if (!ctx_has_comment($first_line, $linenr)) {
944− print "memory barrier without comment\n";
945− print "$herecurr";
946− $clean = 0;
918+ CHK("memory barrier without comment\n" . $herecurr);
947919 }
948920 }
949921 # check of hardware specific defines
950922 if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@) {
951− print "architecture specific defines should be avoided\n";
952− print "$herecurr";
953− $clean = 0;
923+ CHK("architecture specific defines should be avoided\n" . $herecurr);
954924 }
955925
926+# check the location of the inline attribute, that it is between
927+# storage class and type.
956928 if ($line =~ /$Type\s+(?:inline|__always_inline)\b/ ||
957929 $line =~ /\b(?:inline|always_inline)\s+$Storage/) {
958− print "inline keyword should sit between storage class and type\n";
959− print "$herecurr";
960− $clean = 0;
930+ ERROR("inline keyword should sit between storage class and type\n" . $herecurr);
931+ }
932+
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);
936+ }
937+
938+# checks for new __setup's
939+ if ($rawline =~ /\b__setup\("([^"]*)"/) {
940+ my $name = $1;
941+
942+ if (!grep(/$name/, @setup_docs)) {
943+ CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
944+ }
961945 }
962946 }
963947
964948 if ($chk_patch && !$is_patch) {
965− $clean = 0;
966− print "Does not appear to be a unified-diff format patch\n";
949+ ERROR("Does not appear to be a unified-diff format patch\n");
967950 }
968951 if ($is_patch && $chk_signoff && $signoff == 0) {
969− $clean = 0;
970− print "Missing Signed-off-by: line(s)\n";
952+ ERROR("Missing Signed-off-by: line(s)\n");
971953 }
972954
973955 if ($clean == 1 && $quiet == 0) {