diff options
| author | Andy Whitcroft <apw@shadowen.org> | 2008-03-04 17:28:20 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-03-04 19:35:09 -0500 |
| commit | cf655043d4ba6fb3e352d6295a6ad5c2361755c4 (patch) | |
| tree | 98fe680d245e4c13cbc14fcbf08e0471d9de6b7b /scripts | |
| parent | b6abdb0e6ca5c2c0a7caa4131da2af0750927e72 (diff) | |
update checkpatch.pl to version 0.15
This version brings a number of minor fixes updating the type detector and
the unary tracker. It also brings a few small fixes for false positives.
It also reverts the --file warning. Of note:
- limit CVS checks to added lines
- improved type detections
- fixes to the unary tracker
Andy Whitcroft (13):
Version: 0.15
EXPORT_SYMBOL checks need to accept array variables
export checks must match DECLARE_foo and LIST_HEAD
possible types: cleanup debugging missing line
values: track values through preprocessor conditional paths
typeof is actually a type
possible types: detect definitions which cross lines
values: include line numbers on value debug information
values: ensure we find correctly record pending brackets
values: simplify the brace history stack
CVS keyword checks should only apply to added lines
loosen spacing for comments
allow braces for single statement blocks with multiline conditionals
Harvey Harrison (1):
checkpatch: remove fastcall
Ingo Molnar (1):
checkpatch.pl: revert wrong --file message
Uwe Kleine-Koenig (1):
fix typo "goot" -> "good"
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Cc: Randy Dunlap <rdunlap@xenotime.net>
Cc: Joel Schopp <jschopp@austin.ibm.com>
Cc: Ingo Molnar <mingo@elte.hu>
Cc: Andi Kleen <ak@suse.de>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/checkpatch.pl | 323 |
1 files changed, 206 insertions, 117 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 2086a856400a..2a7cef9726e4 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -9,7 +9,7 @@ use strict; | |||
| 9 | my $P = $0; | 9 | my $P = $0; |
| 10 | $P =~ s@.*/@@g; | 10 | $P =~ s@.*/@@g; |
| 11 | 11 | ||
| 12 | my $V = '0.14'; | 12 | my $V = '0.15'; |
| 13 | 13 | ||
| 14 | use Getopt::Long qw(:config no_auto_abbrev); | 14 | use Getopt::Long qw(:config no_auto_abbrev); |
| 15 | 15 | ||
| @@ -105,8 +105,7 @@ our $Sparse = qr{ | |||
| 105 | __iomem| | 105 | __iomem| |
| 106 | __must_check| | 106 | __must_check| |
| 107 | __init_refok| | 107 | __init_refok| |
| 108 | __kprobes| | 108 | __kprobes |
| 109 | fastcall | ||
| 110 | }x; | 109 | }x; |
| 111 | our $Attribute = qr{ | 110 | our $Attribute = qr{ |
| 112 | const| | 111 | const| |
| @@ -158,7 +157,10 @@ sub build_types { | |||
| 158 | \b | 157 | \b |
| 159 | (?:const\s+)? | 158 | (?:const\s+)? |
| 160 | (?:unsigned\s+)? | 159 | (?:unsigned\s+)? |
| 161 | $all | 160 | (?: |
| 161 | $all| | ||
| 162 | (?:typeof|__typeof__)\s*\(\s*\**\s*$Ident\s*\) | ||
| 163 | ) | ||
| 162 | (?:\s+$Sparse|\s+const)* | 164 | (?:\s+$Sparse|\s+const)* |
| 163 | \b | 165 | \b |
| 164 | }x; | 166 | }x; |
| @@ -362,6 +364,7 @@ sub ctx_statement_block { | |||
| 362 | 364 | ||
| 363 | my $type = ''; | 365 | my $type = ''; |
| 364 | my $level = 0; | 366 | my $level = 0; |
| 367 | my $p; | ||
| 365 | my $c; | 368 | my $c; |
| 366 | my $len = 0; | 369 | my $len = 0; |
| 367 | 370 | ||
| @@ -386,6 +389,7 @@ sub ctx_statement_block { | |||
| 386 | last; | 389 | last; |
| 387 | } | 390 | } |
| 388 | } | 391 | } |
| 392 | $p = $c; | ||
| 389 | $c = substr($blk, $off, 1); | 393 | $c = substr($blk, $off, 1); |
| 390 | $remainder = substr($blk, $off); | 394 | $remainder = substr($blk, $off); |
| 391 | 395 | ||
| @@ -397,8 +401,9 @@ sub ctx_statement_block { | |||
| 397 | } | 401 | } |
| 398 | 402 | ||
| 399 | # An else is really a conditional as long as its not else if | 403 | # An else is really a conditional as long as its not else if |
| 400 | if ($level == 0 && $remainder =~ /(\s+else)(?:\s|{)/ && | 404 | if ($level == 0 && (!defined($p) || $p =~ /(?:\s|\})/) && |
| 401 | $remainder !~ /\s+else\s+if\b/) { | 405 | $remainder =~ /(else)(?:\s|{)/ && |
| 406 | $remainder !~ /else\s+if\b/) { | ||
| 402 | $coff = $off + length($1); | 407 | $coff = $off + length($1); |
| 403 | } | 408 | } |
| 404 | 409 | ||
| @@ -445,21 +450,73 @@ sub ctx_statement_block { | |||
| 445 | $line, $remain + 1, $off - $loff + 1, $level); | 450 | $line, $remain + 1, $off - $loff + 1, $level); |
| 446 | } | 451 | } |
| 447 | 452 | ||
| 453 | sub statement_lines { | ||
| 454 | my ($stmt) = @_; | ||
| 455 | |||
| 456 | # Strip the diff line prefixes and rip blank lines at start and end. | ||
| 457 | $stmt =~ s/(^|\n)./$1/g; | ||
| 458 | $stmt =~ s/^\s*//; | ||
| 459 | $stmt =~ s/\s*$//; | ||
| 460 | |||
| 461 | my @stmt_lines = ($stmt =~ /\n/g); | ||
| 462 | |||
| 463 | return $#stmt_lines + 2; | ||
| 464 | } | ||
| 465 | |||
| 466 | sub statement_rawlines { | ||
| 467 | my ($stmt) = @_; | ||
| 468 | |||
| 469 | my @stmt_lines = ($stmt =~ /\n/g); | ||
| 470 | |||
| 471 | return $#stmt_lines + 2; | ||
| 472 | } | ||
| 473 | |||
| 474 | sub statement_block_size { | ||
| 475 | my ($stmt) = @_; | ||
| 476 | |||
| 477 | $stmt =~ s/(^|\n)./$1/g; | ||
| 478 | $stmt =~ s/^\s*{//; | ||
| 479 | $stmt =~ s/}\s*$//; | ||
| 480 | $stmt =~ s/^\s*//; | ||
| 481 | $stmt =~ s/\s*$//; | ||
| 482 | |||
| 483 | my @stmt_lines = ($stmt =~ /\n/g); | ||
| 484 | my @stmt_statements = ($stmt =~ /;/g); | ||
| 485 | |||
| 486 | my $stmt_lines = $#stmt_lines + 2; | ||
| 487 | my $stmt_statements = $#stmt_statements + 1; | ||
| 488 | |||
| 489 | if ($stmt_lines > $stmt_statements) { | ||
| 490 | return $stmt_lines; | ||
| 491 | } else { | ||
| 492 | return $stmt_statements; | ||
| 493 | } | ||
| 494 | } | ||
| 495 | |||
| 448 | sub ctx_statement_full { | 496 | sub ctx_statement_full { |
| 449 | my ($linenr, $remain, $off) = @_; | 497 | my ($linenr, $remain, $off) = @_; |
| 450 | my ($statement, $condition, $level); | 498 | my ($statement, $condition, $level); |
| 451 | 499 | ||
| 452 | my (@chunks); | 500 | my (@chunks); |
| 453 | 501 | ||
| 502 | # Grab the first conditional/block pair. | ||
| 454 | ($statement, $condition, $linenr, $remain, $off, $level) = | 503 | ($statement, $condition, $linenr, $remain, $off, $level) = |
| 455 | ctx_statement_block($linenr, $remain, $off); | 504 | ctx_statement_block($linenr, $remain, $off); |
| 456 | #print "F: c<$condition> s<$statement>\n"; | 505 | #print "F: c<$condition> s<$statement>\n"; |
| 506 | push(@chunks, [ $condition, $statement ]); | ||
| 507 | if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) { | ||
| 508 | return ($level, $linenr, @chunks); | ||
| 509 | } | ||
| 510 | |||
| 511 | # Pull in the following conditional/block pairs and see if they | ||
| 512 | # could continue the statement. | ||
| 457 | for (;;) { | 513 | for (;;) { |
| 458 | push(@chunks, [ $condition, $statement ]); | ||
| 459 | last if (!($remain > 0 && $condition =~ /^.\s*(?:if|else|do)/)); | ||
| 460 | ($statement, $condition, $linenr, $remain, $off, $level) = | 514 | ($statement, $condition, $linenr, $remain, $off, $level) = |
| 461 | ctx_statement_block($linenr, $remain, $off); | 515 | ctx_statement_block($linenr, $remain, $off); |
| 462 | #print "C: c<$condition> s<$statement>\n"; | 516 | #print "C: c<$condition> s<$statement> remain<$remain>\n"; |
| 517 | last if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:else|do)\b/s)); | ||
| 518 | #print "C: push\n"; | ||
| 519 | push(@chunks, [ $condition, $statement ]); | ||
| 463 | } | 520 | } |
| 464 | 521 | ||
| 465 | return ($level, $linenr, @chunks); | 522 | return ($level, $linenr, @chunks); |
| @@ -593,13 +650,13 @@ sub cat_vet { | |||
| 593 | } | 650 | } |
| 594 | 651 | ||
| 595 | my $av_preprocessor = 0; | 652 | my $av_preprocessor = 0; |
| 596 | my $av_paren = 0; | 653 | my $av_pending; |
| 597 | my @av_paren_type; | 654 | my @av_paren_type; |
| 598 | 655 | ||
| 599 | sub annotate_reset { | 656 | sub annotate_reset { |
| 600 | $av_preprocessor = 0; | 657 | $av_preprocessor = 0; |
| 601 | $av_paren = 0; | 658 | $av_pending = '_'; |
| 602 | @av_paren_type = (); | 659 | @av_paren_type = ('E'); |
| 603 | } | 660 | } |
| 604 | 661 | ||
| 605 | sub annotate_values { | 662 | sub annotate_values { |
| @@ -611,12 +668,13 @@ sub annotate_values { | |||
| 611 | print "$stream\n" if ($dbg_values > 1); | 668 | print "$stream\n" if ($dbg_values > 1); |
| 612 | 669 | ||
| 613 | while (length($cur)) { | 670 | while (length($cur)) { |
| 614 | print " <$type> " if ($dbg_values > 1); | 671 | print " <" . join('', @av_paren_type) . |
| 672 | "> <$type> " if ($dbg_values > 1); | ||
| 615 | if ($cur =~ /^(\s+)/o) { | 673 | if ($cur =~ /^(\s+)/o) { |
| 616 | print "WS($1)\n" if ($dbg_values > 1); | 674 | print "WS($1)\n" if ($dbg_values > 1); |
| 617 | if ($1 =~ /\n/ && $av_preprocessor) { | 675 | if ($1 =~ /\n/ && $av_preprocessor) { |
| 676 | $type = pop(@av_paren_type); | ||
| 618 | $av_preprocessor = 0; | 677 | $av_preprocessor = 0; |
| 619 | $type = 'N'; | ||
