Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

update checkpatch.pl to version 0.06

Update to checkpatch.pl v0.06. Of note:

- do { and else handled correctly as control structures for { matching
- trailing whitespace correctly tripped when line otherwise empty
- support for const, including const foo * const bar
- multiline macros defining values correctly reported

This version of checkpatch.pl can be found at the following URL:

http://www.kernel.org/pub/linux/kernel/people/apw/checkpatch/checkpatch.pl-0.06

Full Changelog:

Andy Whitcroft (14):
Version: 0.06
cleanup the Type regular expression declarations
fix up block counting
end of line counts as a space for ++ and --
do { needs the same checks as if, for et al
handle "const foo * const a" as a valid type
add spacing checks following ;
complete whitespace lines should trip trailing whitespace check
else is also a block control structure
badly formatted else can trip function declaration
detect and report trailing statements after else
types need to be terminated by a boundary
multiline macros defining values should be surrounded by parentheses
soften the wording of the Signed-off-by: warnings

Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Cc: "Randy.Dunlap" <rdunlap@xenotime.net>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Andy Whitcroft and committed by
Linus Torvalds
d8aaf121 debee076

+94 -55
+94 -55
scripts/checkpatch.pl
··· 9 9 my $P = $0; 10 10 $P =~ s@.*/@@g; 11 11 12 - my $V = '0.05'; 12 + my $V = '0.06'; 13 13 14 14 use Getopt::Long qw(:config no_auto_abbrev); 15 15 ··· 271 271 my $in_comment = 0; 272 272 my $first_line = 0; 273 273 274 - my $ident = '[A-Za-z\d_]+'; 275 - my $storage = '(?:extern|static)'; 276 - my $sparse = '(?:__user|__kernel|__force|__iomem)'; 277 - my $type = '(?:unsigned\s+)?' . 278 - '(?:void|char|short|int|long|unsigned|float|double|' . 279 - 'long\s+long|' . 280 - "struct\\s+${ident}|" . 281 - "union\\s+${ident}|" . 282 - "${ident}_t)" . 283 - "(?:\\s+$sparse)*" . 284 - '(?:\s*\*+)?'; 285 - my $attribute = '(?:__read_mostly|__init|__initdata)'; 286 - 287 - my $Ident = $ident; 288 - my $Type = $type; 289 - my $Storage = $storage; 290 - my $Declare = "(?:$storage\\s+)?$type"; 291 - my $Attribute = $attribute; 274 + my $Ident = qr{[A-Za-z\d_]+}; 275 + my $Storage = qr{extern|static}; 276 + my $Sparse = qr{__user|__kernel|__force|__iomem}; 277 + my $NonptrType = qr{ 278 + \b 279 + (?:const\s+)? 280 + (?:unsigned\s+)? 281 + (?: 282 + void| 283 + char| 284 + short| 285 + int| 286 + long| 287 + unsigned| 288 + float| 289 + double| 290 + long\s+int| 291 + long\s+long| 292 + long\s+long\s+int| 293 + struct\s+$Ident| 294 + union\s+$Ident| 295 + ${Ident}_t 296 + ) 297 + (?:\s+$Sparse)* 298 + \b 299 + }x; 300 + my $Type = qr{ 301 + \b$NonptrType\b 302 + (?:\s*\*+\s*const|\s*\*+)? 303 + }x; 304 + my $Declare = qr{(?:$Storage\s+)?$Type}; 305 + my $Attribute = qr{__read_mostly|__init|__initdata}; 292 306 293 307 foreach my $line (@lines) { 294 308 $linenr++; ··· 335 321 # blank context lines so we need to count that too. 336 322 if ($line =~ /^( |\+|$)/) { 337 323 $realline++; 324 + $realcnt-- if ($realcnt != 0); 338 325 339 326 # track any sort of multi-line comment. Obviously if 340 327 # the added text or context do not include the whole ··· 360 345 # Track the previous line. 361 346 ($prevline, $stashline) = ($stashline, $line); 362 347 ($previndent, $stashindent) = ($stashindent, $indent); 348 + } elsif ($realcnt == 1) { 349 + $realcnt--; 363 350 } 364 - $realcnt-- if ($realcnt != 0); 365 351 366 352 #make up the handle for any error we report on this line 367 353 $here = "#$linenr: "; ··· 373 357 my $hereprev = "$here\n$prevline\n$line\n\n"; 374 358 375 359 #check the patch for a signoff: 376 - if ($line =~ /^\s*Signed-off-by:\s/) { 377 - $signoff++; 378 - 379 - } elsif ($line =~ /^\s*signed-off-by:/i) { 360 + if ($line =~ /^\s*signed-off-by:/i) { 380 361 # This is a signoff, if ugly, so do not double report. 381 362 $signoff++; 382 363 if (!($line =~ /^\s*Signed-off-by:/)) { 383 - print "use Signed-off-by:\n"; 364 + print "Signed-off-by: is the preferred form\n"; 384 365 print "$herecurr"; 385 366 $clean = 0; 386 367 } ··· 402 389 next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); 403 390 404 391 #trailing whitespace 405 - if ($line=~/^\+.*\S\s+$/) { 392 + if ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) { 406 393 my $herevet = "$here\n" . cat_vet($line) . "\n\n"; 407 394 print "trailing whitespace\n"; 408 395 print "$herevet"; ··· 538 525 } 539 526 540 527 # * goes on variable not on type 541 - if ($line =~ m{[A-Za-z\d_]+(\*+) [A-Za-z\d_]+}) { 542 - print "\"foo$1 bar\" should be \"foo $1bar\"\n"; 543 - print "$herecurr"; 544 - $clean = 0; 545 - } 546 - if ($line =~ m{$Type (\*) [A-Za-z\d_]+} || 547 - $line =~ m{[A-Za-z\d_]+ (\*\*+) [A-Za-z\d_]+}) { 548 - print "\"foo $1 bar\" should be \"foo $1bar\"\n"; 549 - print "$herecurr"; 550 - $clean = 0; 551 - } 552 - if ($line =~ m{\([A-Za-z\d_\s]+[A-Za-z\d_](\*+)\)}) { 528 + if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) { 553 529 print "\"(foo$1)\" should be \"(foo $1)\"\n"; 554 530 print "$herecurr"; 555 531 $clean = 0; 556 - } 557 - if ($line =~ m{\([A-Za-z\d_\s]+[A-Za-z\d_]\s+(\*+)\s+\)}) { 532 + 533 + } elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) { 558 534 print "\"(foo $1 )\" should be \"(foo $1)\"\n"; 535 + print "$herecurr"; 536 + $clean = 0; 537 + 538 + } elsif ($line =~ m{$NonptrType(\*+)(?:\s+const)?\s+[A-Za-z\d_]+}) { 539 + print "\"foo$1 bar\" should be \"foo $1bar\"\n"; 540 + print "$herecurr"; 541 + $clean = 0; 542 + 543 + } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+const)\s+[A-Za-z\d_]+}) { 544 + print "\"foo $1 bar\" should be \"foo $1bar\"\n"; 559 545 print "$herecurr"; 560 546 $clean = 0; 561 547 } ··· 593 581 594 582 # function brace can't be on same line, except for #defines of do while, 595 583 # or if closed on same line 596 - if (($line=~/[A-Za-z\d_]+\**\s+\**[A-Za-z\d_]+\(.*\).* {/) and 584 + if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).* {/) and 597 585 !($line=~/\#define.*do\s{/) and !($line=~/}/)) { 598 586 print "braces following function declarations go on the next line\n"; 599 587 print "$herecurr"; ··· 636 624 my $ca = substr($opline, $off - 1, 1); 637 625 my $cc = ''; 638 626 if (length($opline) >= ($off + length($elements[$n + 1]))) { 639 - $cc = substr($opline, $off + length($elements[$n + 1]), 1); 627 + $cc = substr($opline, $off + length($elements[$n + 1])); 640 628 } 641 629 642 630 my $ctx = "${a}x${c}"; ··· 648 636 649 637 ##print "<$s1:$op:$s2> <$elements[$n]:$elements[$n + 1]:$elements[$n + 2]>\n"; 650 638 651 - # We need ; as an operator. // is a comment. 652 - if ($op eq ';' or $op eq '//') { 639 + # ; should have either the end of line or a space or \ after it 640 + if ($op eq ';') { 641 + if ($ctx !~ /.x[WE]/ && $cc !~ /^\\/) { 642 + print "need space after that '$op' $at\n"; 643 + print "$hereptr"; 644 + $clean = 0; 645 + } 646 + 647 + # // is a comment 648 + } elsif ($op eq '//') { 653 649 654 650 # -> should have no spaces 655 651 } elsif ($op eq '->') { ··· 669 649 670 650 # , must have a space on the right. 671 651 } elsif ($op eq ',') { 672 - if ($ctx !~ /.xW|.xE/ && $cc ne '}') { 652 + if ($ctx !~ /.xW|.xE/ && $cc !~ /^}/) { 673 653 print "need space after that '$op' $at\n"; 674 654 print "$hereptr"; 675 655 $clean = 0; ··· 690 670 691 671 # unary ++ and unary -- are allowed no space on one side. 692 672 } elsif ($op eq '++' or $op eq '--') { 693 - if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOB]/) { 673 + if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) { 694 674 print "need space one side of that '$op' $at\n"; 695 675 print "$hereptr"; 696 676 $clean = 0; 697 677 } 698 - if ($ctx =~ /Wx./ && $cc eq ';') { 678 + if ($ctx =~ /Wx./ && $cc =~ /^;/) { 699 679 print "no space before that '$op' $at\n"; 700 680 print "$hereptr"; 701 681 $clean = 0; ··· 727 707 # 728 708 } elsif ($op eq '*') { 729 709 if ($ca eq '*') { 730 - if ($cc =~ /\s/) { 710 + if ($cc =~ /^\s(?!\s*const)/) { 731 711 print "no space after that '$op' $at\n"; 732 712 print "$hereptr"; 733 713 $clean = 0; ··· 823 803 824 804 # if/while/etc brace do not go on next line, unless defining a do while loop, 825 805 # or if that brace on the next line is for something else 826 - if ($prevline=~/\b(if|while|for|switch)\s*\(/) { 806 + if ($prevline=~/\b(?:(if|while|for|switch)\s*\(|do\b|else\b)/) { 827 807 my @opened = $prevline=~/\(/g; 828 808 my @closed = $prevline=~/\)/g; 829 809 my $nr_line = $linenr; ··· 843 823 @closed = $prevline=~/\)/g; 844 824 } 845 825 846 - if (($prevline=~/\b(if|while|for|switch)\s*\(.*\)\s*$/) and ($next_line=~/{/) and 847 - !($next_line=~/\b(if|while|for|switch)/) and !($next_line=~/\#define.*do.*while/)) { 826 + if (($prevline=~/\b(?:(if|while|for|switch)\s*\(.*\)|do|else)\s*$/) and ($next_line=~/{/) and 827 + !($next_line=~/\b(?:if|while|for|switch|do|else)\b/) and !($next_line=~/\#define.*do.*while/)) { 848 828 print "That { should be on the previous line\n"; 849 829 print "$here\n$display_segment\n$next_line\n\n"; 850 830 $clean = 0; 851 831 } 832 + } 833 + 834 + # if and else should not have general statements after it 835 + if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/ && 836 + $1 !~ /^\s*(?:\sif|{|$)/) { 837 + print "trailing statements should be on next line\n"; 838 + print "$herecurr"; 839 + $clean = 0; 852 840 } 853 841 854 842 # multi-statement macros should be enclosed in a do while loop, grab the ··· 869 841 # Grab the first statement, if that is the entire macro 870 842 # its ok. This may start either on the #define line 871 843 # or the one below. 872 - my $ctx1 = join('', ctx_statement($linenr - 1, $realcnt + 1)); 873 - my $ctx2 = join('', ctx_statement($linenr, $realcnt)); 844 + my $ln = $linenr; 845 + my $cnt = $realcnt; 874 846 875 - if ($ctx1 =~ /\\$/ && $ctx2 =~ /\\$/) { 876 - print "Macros with multiple statements should be enclosed in a do - while loop\n"; 847 + # If the macro starts on the define line start there. 848 + if ($prevline !~ m{^.#\s*define\s*$Ident(?:\([^\)]*\))?\s*\\\s*$}) { 849 + $ln--; 850 + $cnt++; 851 + } 852 + my $ctx = join('', ctx_statement($ln, $cnt)); 853 + 854 + if ($ctx =~ /\\$/) { 855 + if ($ctx =~ /;/) { 856 + print "Macros with multiple statements should be enclosed in a do - while loop\n"; 857 + } else { 858 + print "Macros with complex values should be enclosed in parenthesis\n"; 859 + } 877 860 print "$hereprev"; 878 861 $clean = 0; 879 862 }