History

update checkpatch.pl to version 0.13

This version brings a large number of fixes which have built up over the Christmas period. Mostly these are fixes for false positives, both through improvments to unary checks and possible type detection. It also brings new checks for while location and CVS keywords. Of note: - a number of fixes to unary detection - detection of a number of new forms of types to improve type matching - better inline handling - recognision of '%' as an operator Andy Whitcroft (28): Version: 0.13 unary detection: maintain bracket state across lines move to pre-sanitising the entire file the text of a #error statement should be treated like it is in quotes line sanitisation needs to target double backslash correctly tighten comment guestimation for lines starting ' * ' debug: add a debug framework prevent unclosed single quotes from spreading add % as an operator the text of a #warning statement should be treated like it is in quotes possible matching applies in typedefs single statement block checks must not trigger when two or more statements possible types: local variables may also be const treat inline as a type attribute to even when out of place possible types: sparse annotations are valid indicators possible types: beef up the possible type testing check for hanging while statements on the wrong line utf8 checks need to occur against the raw lines function brace checks should use any whitespece matches comments should take up space in the line when sanitised remove debugging from if assignment checks possible types -- ensure we detect all pointer casts fix tests for function spacing in the presence of #define clean up the UTF-8 error message to be clearer test-lib: invert the status report, output success counts detect and report CVS keywords tests: break out tests Add $Id$ to the CVS keyword checks Benny Halevy (1): checkpatch.pl: recognize the #elif preprocessor directive Geert Uytterhoeven (1): print the filenames of patches where available Mauro Carvalho Chehab (1): Fix missing \n in checkpatch.pl

Andy Whitcroft committed 18 years ago

Commit c2fdda01 parent 69759451 file · +198 −96Browse files

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

Unified · Split

scripts/checkpatch.pl+198−96
@@ -9,7 +9,7 @@ use strict; · 8 unmodified lines
99 my $P = $0;
1010 $P =~ s@.*/@@g;
1111
12−my $V = '0.12';
12+my $V = '0.13';
1313
1414 use Getopt::Long qw(:config no_auto_abbrev);
1515
@@ -25,6 +25,7 @@ my $check = 0; · 9 unmodified lines
2525 my $summary = 1;
2626 my $mailback = 0;
2727 my $root;
28+my %debug;
2829 GetOptions(
2930 'q|quiet+' => \$quiet,
3031 'tree!' => \$tree,
@@ -39,6 +40,7 @@ GetOptions( · 8 unmodified lines
3940 'root=s' => \$root,
4041 'summary!' => \$summary,
4142 'mailback!' => \$mailback,
43+ 'debug=s' => \%debug,
4244 ) or exit;
4345
4446 my $exit = 0;
@@ -56,6 +58,12 @@ if ($#ARGV < 0) { · 11 unmodified lines
5658 exit(1);
5759 }
5860
61+my $dbg_values = 0;
62+my $dbg_possible = 0;
63+for my $key (keys %debug) {
64+ eval "\${dbg_$key} = '$debug{$key}';"
65+}
66+
5967 if ($terse) {
6068 $emacs = 1;
6169 $quiet++;
@@ -110,7 +118,7 @@ our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)}; · 48 unmodified lines
110118 our $Operators = qr{
111119 <=|>=|==|!=|
112120 =>|->|<<|>>|<|>|!|~|
113− &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/
121+ &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%
114122 }x;
115123
116124 our $NonptrType;
@@ -152,7 +160,7 @@ sub build_types { · 35 unmodified lines
152160 $Type = qr{
153161 \b$NonptrType\b
154162 (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)?
155− (?:\s+$Sparse|\s+$Attribute)*
163+ (?:\s+$Inline|\s+$Sparse|\s+$Attribute)*
156164 }x;
157165 $Declare = qr{(?:$Storage\s+)?$Type};
158166 }
@@ -181,6 +189,8 @@ if ($tree && -f "$root/$removal") { · 22 unmodified lines
181189 }
182190
183191 my @rawlines = ();
192+my @lines = ();
193+my $vname;
184194 for my $filename (@ARGV) {
185195 if ($file) {
186196 open(FILE, "diff -u /dev/null $filename|") ||
@@ -189,12 +199,17 @@ for my $filename (@ARGV) { · 2 unmodified lines
189199 open(FILE, "<$filename") ||
190200 die "$P: $filename: open failed - $!\n";
191201 }
202+ if ($filename eq '-') {
203+ $vname = 'Your patch';
204+ } else {
205+ $vname = $filename;
206+ }
192207 while (<FILE>) {
193208 chomp;
194209 push(@rawlines, $_);
195210 }
196211 close(FILE);
197− if (!process($filename, @rawlines)) {
212+ if (!process($filename)) {
198213 $exit = 1;
199214 }
200215 @rawlines = ();
@@ -274,20 +289,30 @@ sub sanitise_line { · 73 unmodified lines
274289 my $l = '';
275290
276291 my $quote = '';
292+ my $qlen = 0;
277293
278294 foreach my $c (split(//, $line)) {
295+ # The second backslash of a pair is not a "quote".
296+ if ($l eq "\\" && $c eq "\\") {
297+ $c = 'X';
298+ }
279299 if ($l ne "\\" && ($c eq "'" || $c eq '"')) {
280300 if ($quote eq '') {
281301 $quote = $c;
282302 $res .= $c;
283303 $l = $c;
304+ $qlen = 0;
284305 next;
285306 } elsif ($quote eq $c) {
286307 $quote = '';
287308 }
288309 }
310+ if ($quote eq "'" && $qlen > 1) {
311+ $quote = '';
312+ }
289313 if ($quote && $c ne "\t") {
290314 $res .= "X";
315+ $qlen++;
291316 } else {
292317 $res .= $c;
293318 }
@@ -295,6 +320,28 @@ sub sanitise_line { · 1 unmodified line
295320 $l = $c;
296321 }
297322
323+ # Clear out the comments.
324+ while ($res =~ m@(/\*.*?\*/)@) {
325+ substr($res, $-[1], $+[1] - $-[1]) = ' ' x ($+[1] - $-[1]);
326+ }
327+ if ($res =~ m@(/\*.*)@) {
328+ substr($res, $-[1], $+[1] - $-[1]) = ' ' x ($+[1] - $-[1]);
329+ }
330+ if ($res =~ m@^.(.*\*/)@) {
331+ substr($res, $-[1], $+[1] - $-[1]) = ' ' x ($+[1] - $-[1]);
332+ }
333+
334+ # The pathname on a #include may be surrounded by '<' and '>'.
335+ if ($res =~ /^.#\s*include\s+\<(.*)\>/) {
336+ my $clean = 'X' x length($1);
337+ $res =~ s@\<.*\>@<$clean>@;
338+
339+ # The whole of a #error is a string.
340+ } elsif ($res =~ /^.#\s*(?:error|warning)\s+(.*)\b/) {
341+ my $clean = 'X' x length($1);
342+ $res =~ s@(#\s*(?:error|warning)\s+).*@$1$clean@;
343+ }
344+
298345 return $res;
299346 }
300347
@@ -315,9 +362,9 @@ sub ctx_statement_block { · 14 unmodified lines
315362 # context.
316363 if ($off >= $len) {
317364 for (; $remain > 0; $line++) {
318− next if ($rawlines[$line] =~ /^-/);
365+ next if ($lines[$line] =~ /^-/);
319366 $remain--;
320− $blk .= sanitise_line($rawlines[$line]) . "\n";
367+ $blk .= $lines[$line] . "\n";
321368 $len = length($blk);
322369 $line++;
323370 last;
@@ -500,103 +547,106 @@ sub cat_vet { · 176 unmodified lines
500547 return $res;
501548 }
502549
550+my $av_preprocessor = 0;
551+my $av_paren = 0;
552+my @av_paren_type;
553+
554+sub annotate_reset {
555+ $av_preprocessor = 0;
556+ $av_paren = 0;
557+ @av_paren_type = ();
558+}
559+
503560 sub annotate_values {
504561 my ($stream, $type) = @_;
505562
506563 my $res;
507564 my $cur = $stream;
508565
509− my $debug = 0;
510−
511− print "$stream\n" if ($debug);
512−
513− ##my $type = 'N';
514− my $pos = 0;
515− my $preprocessor = 0;
516− my $paren = 0;
517− my @paren_type;
566+ print "$stream\n" if ($dbg_values > 1);
518567
519568 while (length($cur)) {
520− print " <$type> " if ($debug);
569+ print " <$type> " if ($dbg_values > 1);
521570 if ($cur =~ /^(\s+)/o) {
522− print "WS($1)\n" if ($debug);
523− if ($1 =~ /\n/ && $preprocessor) {
524− $preprocessor = 0;
571+ print "WS($1)\n" if ($dbg_values > 1);
572+ if ($1 =~ /\n/ && $av_preprocessor) {
573+ $av_preprocessor = 0;
525574 $type = 'N';
526575 }
527576
528577 } elsif ($cur =~ /^($Type)/) {
529− print "DECLARE($1)\n" if ($debug);
578+ print "DECLARE($1)\n" if ($dbg_values > 1);
530579 $type = 'T';
531580
532581 } elsif ($cur =~ /^(#\s*define\s*$Ident)(\(?)/o) {
533− print "DEFINE($1)\n" if ($debug);
534− $preprocessor = 1;
535− $paren_type[$paren] = 'N';
582+ print "DEFINE($1)\n" if ($dbg_values > 1);
583+ $av_preprocessor = 1;
584+ $av_paren_type[$av_paren] = 'N';
536585
537− } elsif ($cur =~ /^(#\s*(?:ifdef|ifndef|if|else|endif))/o) {
538− print "PRE($1)\n" if ($debug);
539− $preprocessor = 1;
586+ } elsif ($cur =~ /^(#\s*(?:ifdef|ifndef|if|else|elif|endif))/o) {
587+ print "PRE($1)\n" if ($dbg_values > 1);
588+ $av_preprocessor = 1;
540589 $type = 'N';
541590
542591 } elsif ($cur =~ /^(\\\n)/o) {
543− print "PRECONT($1)\n" if ($debug);
592+ print "PRECONT($1)\n" if ($dbg_values > 1);
544593
545594 } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
546− print "SIZEOF($1)\n" if ($debug);
595+ print "SIZEOF($1)\n" if ($dbg_values > 1);
547596 if (defined $2) {
548− $paren_type[$paren] = 'V';
597+ $av_paren_type[$av_paren] = 'V';
549598 }
550599 $type = 'N';
551600
552601 } elsif ($cur =~ /^(if|while|typeof|for)\b/o) {
553− print "COND($1)\n" if ($debug);
554− $paren_type[$paren] = 'N';
602+ print "COND($1)\n" if ($dbg_values > 1);
603+ $av_paren_type[$av_paren] = 'N';
555604 $type = 'N';
556605
557606 } elsif ($cur =~/^(return|case|else)/o) {
558− print "KEYWORD($1)\n" if ($debug);
607+ print "KEYWORD($1)\n" if ($dbg_values > 1);
559608 $type = 'N';
560609
561610 } elsif ($cur =~ /^(\()/o) {
562− print "PAREN('$1')\n" if ($debug);
563− $paren++;
611+ print "PAREN('$1')\n" if ($dbg_values > 1);
612+ $av_paren++;
564613 $type = 'N';
565614
566615 } elsif ($cur =~ /^(\))/o) {
567− $paren-- if ($paren > 0);
568− if (defined $paren_type[$paren]) {
569− $type = $paren_type[$paren];
570− undef $paren_type[$paren];
571− print "PAREN('$1') -> $type\n" if ($debug);
616+ $av_paren-- if ($av_paren > 0);
617+ if (defined $av_paren_type[$av_paren]) {
618+ $type = $av_paren_type[$av_paren];
619+ undef $av_paren_type[$av_paren];
620+ print "PAREN('$1') -> $type\n"
621+ if ($dbg_values > 1);
572622 } else {
573− print "PAREN('$1')\n" if ($debug);
623+ print "PAREN('$1')\n" if ($dbg_values > 1);
574624 }
575625
576626 } elsif ($cur =~ /^($Ident)\(/o) {
577− print "FUNC($1)\n" if ($debug);
578− $paren_type[$paren] = 'V';
627+ print "FUNC($1)\n" if ($dbg_values > 1);
628+ $av_paren_type[$av_paren] = 'V';
579629
580630 } elsif ($cur =~ /^($Ident|$Constant)/o) {
581− print "IDENT($1)\n" if ($debug);
631+ print "IDENT($1)\n" if ($dbg_values > 1);
582632 $type = 'V';
583633
584634 } elsif ($cur =~ /^($Assignment)/o) {
585− print "ASSIGN($1)\n" if ($debug);
635+ print "ASSIGN($1)\n" if ($dbg_values > 1);
586636 $type = 'N';
587637
588638 } elsif ($cur =~ /^(;|{|}|\?|:|\[)/o) {
589− print "END($1)\n" if ($debug);
639+ print "END($1)\n" if ($dbg_values > 1);
590640 $type = 'N';
591641
592642 } elsif ($cur =~ /^($Operators)/o) {
593− print "OP($1)\n" if ($debug);
643+ print "OP($1)\n" if ($dbg_values > 1);
594644 if ($1 ne '++' && $1 ne '--') {
595645 $type = 'N';
596646 }
597647
598648 } elsif ($cur =~ /(^.)/o) {
599− print "C($1)\n" if ($debug);
649+ print "C($1)\n" if ($dbg_values > 1);
600650 }
601651 if (defined $1) {
602652 $cur = substr($cur, length($1));
@@ -616,7 +666,7 @@ sub possible { · 13 unmodified lines
616666 $possible ne 'struct' && $possible ne 'enum' &&
617667 $possible ne 'case' && $possible ne 'else' &&
618668 $possible ne 'typedef') {
619− #print "POSSIBLE<$possible>\n";
669+ warn "POSSIBLE: $possible\n" if ($dbg_possible);
620670 push(@typeList, $possible);
621671 build_types();
622672 }
@@ -655,11 +705,12 @@ sub CHK { · 32 unmodified lines
655705
656706 sub process {
657707 my $filename = shift;
658− my @lines = @_;
659708
660709 my $linenr=0;
661710 my $prevline="";
711+ my $prevrawline="";
662712 my $stashline="";
713+ my $stashrawline="";
663714
664715 my $length;
665716 my $indent;
@@ -681,14 +732,26 @@ sub process { · 15 unmodified lines
681732 my $realcnt = 0;
682733 my $here = '';
683734 my $in_comment = 0;
735+ my $comment_edge = 0;
684736 my $first_line = 0;
685737
686738 my $prev_values = 'N';
687739
740+ # Pre-scan the patch sanitizing the lines.
688741 # Pre-scan the patch looking for any __setup documentation.
742+ #
689743 my @setup_docs = ();
690744 my $setup_docs = 0;
691− foreach my $line (@lines) {
745+ my $line;
746+ foreach my $rawline (@rawlines) {
747+ # Standardise the strings and chars within the input to
748+ # simplify matching.
749+ $line = sanitise_line($rawline);
750+ push(@lines, $line);
751+
752+ ##print "==>$rawline\n";
753+ ##print "-->$line\n";
754+
692755 if ($line=~/^\+\+\+\s+(\S+)/) {
693756 $setup_docs = 0;
694757 if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
@@ -707,8 +770,7 @@ sub process { · 12 unmodified lines
707770 foreach my $line (@lines) {
708771 $linenr++;
709772
710− my $rawline = $line;
711−
773+ my $rawline = $rawlines[$linenr - 1];
712774
713775 #extract the filename as it passes
714776 if ($line=~/^\+\+\+\s+(\S+)/) {
@@ -728,6 +790,7 @@ sub process { · 13 unmodified lines
728790 } else {
729791 $realcnt=1+1;
730792 }
793+ annotate_reset();
731794 $prev_values = 'N';
732795 next;
733796 }
@@ -746,7 +809,7 @@ sub process { · 12 unmodified lines
746809 if ($linenr == $first_line) {
747810 my $edge;
748811 for (my $ln = $first_line; $ln < ($linenr + $realcnt); $ln++) {
749− ($edge) = ($lines[$ln - 1] =~ m@(/\*|\*/)@);
812+ ($edge) = ($rawlines[$ln - 1] =~ m@(/\*|\*/)@);
750813 last if (defined $edge);
751814 }
752815 if (defined $edge && $edge eq '*/') {
@@ -757,25 +820,30 @@ sub process { · 4 unmodified lines
757820 # Guestimate if this is a continuing comment. If this
758821 # is the start of a diff block and this line starts
759822 # ' *' then it is very likely a comment.
760− if ($linenr == $first_line and $line =~ m@^.\s*\*@) {
823+ if ($linenr == $first_line and $rawline =~ m@^.\s* \*(?:\s|$)@) {
761824 $in_comment = 1;
762825 }
763826
764827 # Find the last comment edge on _this_ line.
765− while (($line =~ m@(/\*|\*/)@g)) {
828+ $comment_edge = 0;
829+ while (($rawline =~ m@(/\*|\*/)@g)) {
766830 if ($1 eq '/*') {
767831 $in_comment = 1;
768832 } else {
769833 $in_comment = 0;
770834 }
835+ $comment_edge = 1;
771836 }
772837
773838 # Measure the line length and indent.
774− ($length, $indent) = line_stats($line);
839+ ($length, $indent) = line_stats($rawline);
775840
776841 # Track the previous line.
777842 ($prevline, $stashline) = ($stashline, $line);
778843 ($previndent, $stashindent) = ($stashindent, $indent);
844+ ($prevrawline, $stashrawline) = ($stashrawline, $rawline);
845+
846+ #warn "ic<$in_comment> ce<$comment_edge> line<$line>\n";
779847
780848 } elsif ($realcnt == 1) {
781849 $realcnt--;
@@ -786,9 +854,9 @@ sub process { · 4 unmodified lines
786854 $here = "#$realline: " if ($file);
787855 $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
788856
789− my $hereline = "$here\n$line\n";
790− my $herecurr = "$here\n$line\n";
791− my $hereprev = "$here\n$prevline\n$line\n";
857+ my $hereline = "$here\n$rawline\n";
858+ my $herecurr = "$here\n$rawline\n";
859+ my $hereprev = "$here\n$prevrawline\n$rawline\n";
792860
793861 $prefix = "$filename:$realline: " if ($emacs && $file);
794862 $prefix = "$filename:$linenr: " if ($emacs && !$file);
@@ -816,7 +884,7 @@ sub process { · 21 unmodified lines
816884
817885 # UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
818886 if (($realfile =~ /^$/ || $line =~ /^\+/) &&
819− !($line =~ m/^(
887+ !($rawline =~ m/^(
820888 [\x09\x0A\x0D\x20-\x7E] # ASCII
821889 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
822890 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
@@ -826,7 +894,7 @@ sub process { · 3 unmodified lines
826894 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
827895 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
828896 )*$/x )) {
829− ERROR("Invalid UTF-8\n" . $herecurr);
897+ ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $herecurr);
830898 }
831899
832900 #ignore lines being removed
@@ -837,15 +905,15 @@ sub process { · 4 unmodified lines
837905
838906 #trailing whitespace
839907 if ($line =~ /^\+.*\015/) {
840− my $herevet = "$here\n" . cat_vet($line) . "\n";
908+ my $herevet = "$here\n" . cat_vet($rawline) . "\n";
841909 ERROR("DOS line endings\n" . $herevet);
842910
843− } elsif ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) {
844− my $herevet = "$here\n" . cat_vet($line) . "\n";
911+ } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
912+ my $herevet = "$here\n" . cat_vet($rawline) . "\n";
845913 ERROR("trailing whitespace\n" . $herevet);
846914 }
847915 #80 column limit
848− if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) {
916+ if ($line =~ /^\+/ && !($prevrawline=~/\/\*\*/) && $length > 80) {
849917 WARN("line over 80 characters\n" . $herecurr);
850918 }
851919
@@ -859,46 +927,48 @@ sub process { · 7 unmodified lines
859927
860928 # at the beginning of a line any tabs must come first and anything
861929 # more than 8 must use tabs.
862− if ($line=~/^\+\s* \t\s*\S/ or $line=~/^\+\s* \s*/) {
863− my $herevet = "$here\n" . cat_vet($line) . "\n";
930+ if ($rawline =~ /^\+\s* \t\s*\S/ ||
931+ $rawline =~ /^\+\s* \s*/) {
932+ my $herevet = "$here\n" . cat_vet($rawline) . "\n";
864933 ERROR("use tabs not spaces\n" . $herevet);
865934 }
866935
867−# Remove comments from the line before processing.
868− my $comment_edge = ($line =~ s@/\*.*\*/@@g) +
869− ($line =~ s@/\*.*@@) +
870− ($line =~ s@^(.).*\*/@$1@);
936+# check for RCS/CVS revision markers
937+ if ($rawline =~ /\$(Revision|Log|Id)(?:\$|)/) {
938+ WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr);
939+ }
871940
872941 # The rest of our checks refer specifically to C style
873942 # only apply those _outside_ comments. Only skip
874943 # lines in the middle of comments.
875944 next if (!$comment_edge && $in_comment);
876945
877−# Standardise the strings and chars within the input to simplify matching.
878− $line = sanitise_line($line);
879−
880946 # Check for potential 'bare' types
881− if ($realcnt &&
882− $line !~ /$Ident:\s*$/ &&
883− ($line =~ /^.\s*$Ident\s*\(\*+\s*$Ident\)\s*\(/ ||
884− $line !~ /^.\s*$Ident\s*\(/)) {
947+ if ($realcnt) {
948+ # Ignore goto labels.
949+ if ($line =~ /$Ident:\*$/) {
950+
951+ # Ignore functions being called
952+ } elsif ($line =~ /^.\s*$Ident\s*\(/) {
953+
885954 # definitions in global scope can only start with types
886− if ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) {
955+ } elsif ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) {
887956 possible($1);
888957
889958 # declarations always start with types
890− } elsif ($prev_values eq 'N' && $line =~ /^.\s*(?:$Storage\s+)?($Ident)\b\s*\**\s*$Ident\s*(?:;|=)/) {
959+ } elsif ($prev_values eq 'N' && $line =~ /^.\s*(?:$Storage\s+)?(?:const\s+)?($Ident)\b(:?\s+$Sparse)?\s*\**\s*$Ident\s*(?:;|=)/) {
891960 possible($1);
961+ }
892962
893963 # any (foo ... *) is a pointer cast, and foo is a type
894− } elsif ($line =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/) {
964+ while ($line =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/g) {
895965 possible($1);
896966 }
897967
898968 # Check for any sort of function declaration.
899969 # int foo(something bar, other baz);
900970 # void (*store_gdt)(x86_descr_ptr *);
901− if ($prev_values eq 'N' && $line =~ /^(.(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) {
971+ if ($prev_values eq 'N' && $line =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) {
902972 my ($name_len) = length($1);
903973 my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, $name_len);
904974 my $ctx = join("\n", @ctx);
@@ -974,8 +1044,11 @@ sub process { · 69 unmodified lines
9741044 my $opline = $line; $opline =~ s/^./ /;
9751045 my $curr_values = annotate_values($opline . "\n", $prev_values);
9761046 $curr_values = $prev_values . $curr_values;
977− #warn "--> $opline\n";
978− #warn "--> $curr_values ($prev_values)\n";
1047+ if ($dbg_values) {
1048+ my $outline = $opline; $outline =~ s/\t/ /g;
1049+ warn "--> .$outline\n";
1050+ warn "--> $curr_values\n";
1051+ }
9791052 $prev_values = substr($curr_values, -1);
9801053
9811054 #ignore lines not being added
@@ -1004,9 +1077,6 @@ sub process { · 22 unmodified lines
10041077 ERROR("malformed #include filename\n" .
10051078 $herecurr);
10061079 }
1007− # Sanitise this special form of string.
1008− $path = 'X' x length($path);
1009− $line =~ s{\<.*\>}{<$path>};
10101080 }
10111081
10121082 # no C99 // comments
@@ -1074,7 +1144,7 @@ sub process { · 61 unmodified lines
10741144 # }
10751145
10761146 if ($line =~ /\bLINUX_VERSION_CODE\b/) {
1077− WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged" . $herecurr);
1147+ WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
10781148 }
10791149
10801150 # printk should use KERN_* levels. Note that follow on printk's on the
@@ -1102,7 +1172,7 @@ sub process { · 21 unmodified lines
11021172
11031173 # function brace can't be on same line, except for #defines of do while,
11041174 # or if closed on same line
1105− if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).* {/) and
1175+ if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).*\s{/) and
11061176 !($line=~/\#define.*do\s{/) and !($line=~/}/)) {
11071177 ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr);
11081178 }
@@ -1115,8 +1185,22 @@ sub process { · 6 unmodified lines
11151185
11161186 # check for spaces between functions and their parentheses.
11171187 while ($line =~ /($Ident)\s+\(/g) {
1118− if ($1 !~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright|case)$/ &&
1119− $line !~ /$Type\s+\(/ && $line !~ /^.\#\s*define\b/) {
1188+ my $name = $1;
1189+ my $ctx = substr($line, 0, $-[1]);
1190+
1191+ # Ignore those directives where spaces _are_ permitted.
1192+ if ($name =~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright|case)$/) {
1193+
1194+ # cpp #define statements have non-optional spaces, ie
1195+ # if there is a space between the name and the open
1196+ # parenthesis it is simply not a parameter group.
1197+ } elsif ($ctx =~ /^.\#\s*define\s*$/) {
1198+
1199+ # If this whole things ends with a type its most
1200+ # likely a typedef for a function.
1201+ } elsif ("$ctx$name" =~ /$Type$/) {
1202+
1203+ } else {
11201204 WARN("no space between function name and open parenthesis '('\n" . $herecurr);
11211205 }
11221206 }
@@ -1126,7 +1210,7 @@ sub process { · 3 unmodified lines
11261210 <<=|>>=|<=|>=|==|!=|
11271211 \+=|-=|\*=|\/=|%=|\^=|\|=|&=|
11281212 =>|->|<<|>>|<|>|=|!|~|
1129− &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/
1213+ &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%
11301214 }x;
11311215 my @elements = split(/($ops|;)/, $opline);
11321216 my $off = 0;
@@ -1239,7 +1323,8 @@ sub process { · 106 unmodified lines
12391323 } elsif ($op eq '<<' or $op eq '>>' or
12401324 $op eq '&' or $op eq '^' or $op eq '|' or
12411325 $op eq '+' or $op eq '-' or
1242− $op eq '*' or $op eq '/')
1326+ $op eq '*' or $op eq '/' or
1327+ $op eq '%')
12431328 {
12441329 if ($ctx !~ /VxV|WxW|VxE|WxE|VxO/) {
12451330 ERROR("need consistent spacing around '$op' $at\n" .
@@ -1324,7 +1409,7 @@ sub process { · 78 unmodified lines
13241409 my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
13251410
13261411 if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) {
1327− ERROR("do not use assignment in if condition ($c)\n" . $herecurr);
1412+ ERROR("do not use assignment in if condition\n" . $herecurr);
13281413 }
13291414
13301415 # Find out what is on the end of the line after the
@@ -1350,6 +1435,20 @@ sub process { · 19 unmodified lines
13501435 ERROR("else should follow close brace '}'\n" . $hereprev);
13511436 }
13521437
1438+ if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and
1439+ $previndent == $indent) {
1440+ my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
1441+
1442+ # Find out what is on the end of the line after the
1443+ # conditional.
1444+ substr($s, 0, length($c)) = '';
1445+ $s =~ s/\n.*//g;
1446+
1447+ if ($s =~ /^\s*;/) {
1448+ ERROR("while should follow close brace '}'\n" . $hereprev);
1449+ }
1450+ }
1451+
13531452 #studly caps, commented out until figure out how to distinguish between use of existing and adding new
13541453 # if (($line=~/[\w_][a-z\d]+[A-Z]/) and !($line=~/print/)) {
13551454 # print "No studly caps, use _\n";
@@ -1447,8 +1546,11 @@ sub process { · 91 unmodified lines
14471546 # Count the newlines, if there is only one
14481547 # then the block should not have {}'s.
14491548 my @lines = ($stmt =~ /\n/g);
1549+ my @statements = ($stmt =~ /;/g);
14501550 #print "lines<" . scalar(@lines) . ">\n";
1551+ #print "statements<" . scalar(@statements) . ">\n";
14511552 if ($lvl == 0 && scalar(@lines) == 0 &&
1553+ scalar(@statements) < 2 &&
14521554 $stmt !~ /{/ && $stmt !~ /\bif\b/ &&
14531555 $before !~ /}/ && $after !~ /{/) {
14541556 my $herectx = "$here\n" . join("\n", @control, @block[1 .. $#block]) . "\n";
@@ -1587,10 +1689,10 @@ sub process { · 132 unmodified lines
15871689 }
15881690
15891691 if ($clean == 1 && $quiet == 0) {
1590− print "Your patch has no obvious style problems and is ready for submission.\n"
1692+ print "$vname has no obvious style problems and is ready for submission.\n"
15911693 }
15921694 if ($clean == 0 && $quiet == 0) {
1593− print "Your patch has style problems, please review. If any of these errors\n";
1695+ print "$vname has style problems, please review. If any of these errors\n";
15941696 print "are false positives report them to the maintainer, see\n";
15951697 print "CHECKPATCH in MAINTAINERS.\n";
15961698 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t