diff options
| author | David Vrabel <david.vrabel@csr.com> | 2009-01-07 05:45:25 -0500 |
|---|---|---|
| committer | David Vrabel <david.vrabel@csr.com> | 2009-01-07 05:45:25 -0500 |
| commit | a23e66f3b8cfdedec14541e71ef29a754870a20c (patch) | |
| tree | f8ac23572982e92e6f8ae09c4039db627bdf53ee /scripts | |
| parent | 04c470adb01c62bb9bd663cfc4875cf0a4eb01ab (diff) | |
| parent | ede6f5aea054d3fb67c78857f7abdee602302043 (diff) | |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6 into for-upstream
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/checkpatch.pl | 172 | ||||
| -rw-r--r-- | scripts/markup_oops.pl | 162 |
2 files changed, 291 insertions, 43 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index f88bb3e21cda..7bed4ed2c519 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -1,7 +1,8 @@ | |||
| 1 | #!/usr/bin/perl -w | 1 | #!/usr/bin/perl -w |
| 2 | # (c) 2001, Dave Jones. <davej@redhat.com> (the file handling bit) | 2 | # (c) 2001, Dave Jones. <davej@redhat.com> (the file handling bit) |
| 3 | # (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly 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) | 4 | # (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite) |
| 5 | # (c) 2008, Andy Whitcroft <apw@canonical.com> | ||
| 5 | # Licensed under the terms of the GNU GPL License version 2 | 6 | # Licensed under the terms of the GNU GPL License version 2 |
| 6 | 7 | ||
| 7 | use strict; | 8 | use strict; |
| @@ -9,7 +10,7 @@ use strict; | |||
| 9 | my $P = $0; | 10 | my $P = $0; |
| 10 | $P =~ s@.*/@@g; | 11 | $P =~ s@.*/@@g; |
| 11 | 12 | ||
| 12 | my $V = '0.24'; | 13 | my $V = '0.26'; |
| 13 | 14 | ||
| 14 | use Getopt::Long qw(:config no_auto_abbrev); | 15 | use Getopt::Long qw(:config no_auto_abbrev); |
| 15 | 16 | ||
| @@ -68,7 +69,9 @@ my $dbg_possible = 0; | |||
| 68 | my $dbg_type = 0; | 69 | my $dbg_type = 0; |
| 69 | my $dbg_attr = 0; | 70 | my $dbg_attr = 0; |
| 70 | for my $key (keys %debug) { | 71 | for my $key (keys %debug) { |
| 71 | eval "\${dbg_$key} = '$debug{$key}';" | 72 | ## no critic |
| 73 | eval "\${dbg_$key} = '$debug{$key}';"; | ||
| 74 | die "$@" if ($@); | ||
| 72 | } | 75 | } |
| 73 | 76 | ||
| 74 | if ($terse) { | 77 | if ($terse) { |
| @@ -116,7 +119,8 @@ our $Attribute = qr{ | |||
| 116 | __(?:mem|cpu|dev|)(?:initdata|init)| | 119 | __(?:mem|cpu|dev|)(?:initdata|init)| |
| 117 | ____cacheline_aligned| | 120 | ____cacheline_aligned| |
| 118 | ____cacheline_aligned_in_smp| | 121 | ____cacheline_aligned_in_smp| |
| 119 | ____cacheline_internodealigned_in_smp | 122 | ____cacheline_internodealigned_in_smp| |
| 123 | __weak | ||
| 120 | }x; | 124 | }x; |
| 121 | our $Modifier; | 125 | our $Modifier; |
| 122 | our $Inline = qr{inline|__always_inline|noinline}; | 126 | our $Inline = qr{inline|__always_inline|noinline}; |
| @@ -125,6 +129,7 @@ our $Lval = qr{$Ident(?:$Member)*}; | |||
| 125 | 129 | ||
| 126 | our $Constant = qr{(?:[0-9]+|0x[0-9a-fA-F]+)[UL]*}; | 130 | our $Constant = qr{(?:[0-9]+|0x[0-9a-fA-F]+)[UL]*}; |
| 127 | our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)}; | 131 | our $Assignment = qr{(?:\*\=|/=|%=|\+=|-=|<<=|>>=|&=|\^=|\|=|=)}; |
| 132 | our $Compare = qr{<=|>=|==|!=|<|>}; | ||
| 128 | our $Operators = qr{ | 133 | our $Operators = qr{ |
| 129 | <=|>=|==|!=| | 134 | <=|>=|==|!=| |
| 130 | =>|->|<<|>>|<|>|!|~| | 135 | =>|->|<<|>>|<|>|!|~| |
| @@ -190,7 +195,7 @@ sub build_types { | |||
| 190 | }x; | 195 | }x; |
| 191 | $Type = qr{ | 196 | $Type = qr{ |
| 192 | $NonptrType | 197 | $NonptrType |
| 193 | (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)? | 198 | (?:[\s\*]+\s*const|[\s\*]+|(?:\s*\[\s*\])+)? |
| 194 | (?:\s+$Inline|\s+$Modifier)* | 199 | (?:\s+$Inline|\s+$Modifier)* |
| 195 | }x; | 200 | }x; |
| 196 | $Declare = qr{(?:$Storage\s+)?$Type}; | 201 | $Declare = qr{(?:$Storage\s+)?$Type}; |
| @@ -203,9 +208,9 @@ my @dep_includes = (); | |||
| 203 | my @dep_functions = (); | 208 | my @dep_functions = (); |
| 204 | my $removal = "Documentation/feature-removal-schedule.txt"; | 209 | my $removal = "Documentation/feature-removal-schedule.txt"; |
| 205 | if ($tree && -f "$root/$removal") { | 210 | if ($tree && -f "$root/$removal") { |
| 206 | open(REMOVE, "<$root/$removal") || | 211 | open(my $REMOVE, '<', "$root/$removal") || |
| 207 | die "$P: $removal: open failed - $!\n"; | 212 | die "$P: $removal: open failed - $!\n"; |
| 208 | while (<REMOVE>) { | 213 | while (<$REMOVE>) { |
| 209 | if (/^Check:\s+(.*\S)/) { | 214 | if (/^Check:\s+(.*\S)/) { |
| 210 | for my $entry (split(/[, ]+/, $1)) { | 215 | for my $entry (split(/[, ]+/, $1)) { |
| 211 | if ($entry =~ m@include/(.*)@) { | 216 | if ($entry =~ m@include/(.*)@) { |
| @@ -217,17 +222,21 @@ if ($tree && -f "$root/$removal") { | |||
| 217 | } | 222 | } |
| 218 | } | 223 | } |
| 219 | } | 224 | } |
| 225 | close($REMOVE); | ||
| 220 | } | 226 | } |
| 221 | 227 | ||
| 222 | my @rawlines = (); | 228 | my @rawlines = (); |
| 223 | my @lines = (); | 229 | my @lines = (); |
| 224 | my $vname; | 230 | my $vname; |
| 225 | for my $filename (@ARGV) { | 231 | for my $filename (@ARGV) { |
| 232 | my $FILE; | ||
| 226 | if ($file) { | 233 | if ($file) { |
| 227 | open(FILE, "diff -u /dev/null $filename|") || | 234 | open($FILE, '-|', "diff -u /dev/null $filename") || |
| 228 | die "$P: $filename: diff failed - $!\n"; | 235 | die "$P: $filename: diff failed - $!\n"; |
| 236 | } elsif ($filename eq '-') { | ||
| 237 | open($FILE, '<&STDIN'); | ||
| 229 | } else { | 238 | } else { |
| 230 | open(FILE, "<$filename") || | 239 | open($FILE, '<', "$filename") || |
| 231 | die "$P: $filename: open failed - $!\n"; | 240 | die "$P: $filename: open failed - $!\n"; |
| 232 | } | 241 | } |
| 233 | if ($filename eq '-') { | 242 | if ($filename eq '-') { |
| @@ -235,11 +244,11 @@ for my $filename (@ARGV) { | |||
| 235 | } else { | 244 | } else { |
| 236 | $vname = $filename; | 245 | $vname = $filename; |
| 237 | } | 246 | } |
| 238 | while (<FILE>) { | 247 | while (<$FILE>) { |
| 239 | chomp; | 248 | chomp; |
| 240 | push(@rawlines, $_); | 249 | push(@rawlines, $_); |
| 241 | } | 250 | } |
| 242 | close(FILE); | 251 | close($FILE); |
| 243 | if (!process($filename)) { | 252 | if (!process($filename)) { |
| 244 | $exit = 1; | 253 | $exit = 1; |
| 245 | } | 254 | } |
| @@ -366,7 +375,7 @@ sub sanitise_line { | |||
| 366 | } | 375 | } |
| 367 | } | 376 | } |
| 368 | 377 | ||
| 369 | #print "SQ:$sanitise_quote\n"; | 378 | #print "c<$c> SQ<$sanitise_quote>\n"; |
| 370 | if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") { | 379 | if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") { |
| 371 | substr($res, $off, 1, $;); | 380 | substr($res, $off, 1, $;); |
| 372 | } elsif ($off != 0 && $sanitise_quote && $c ne "\t") { | 381 | } elsif ($off != 0 && $sanitise_quote && $c ne "\t") { |
| @@ -402,6 +411,7 @@ sub ctx_statement_block { | |||
| 402 | 411 | ||
| 403 | my $type = ''; | 412 | my $type = ''; |
| 404 | my $level = 0; | 413 | my $level = 0; |
| 414 | my @stack = ([$type, $level]); | ||
| 405 | my $p; | 415 | my $p; |
| 406 | my $c; | 416 | my $c; |
| 407 | my $len = 0; | 417 | my $len = 0; |
| @@ -433,6 +443,16 @@ sub ctx_statement_block { | |||
| 433 | $remainder = substr($blk, $off); | 443 | $remainder = substr($blk, $off); |
| 434 | 444 | ||
| 435 | #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n"; | 445 | #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n"; |
| 446 | |||
| 447 | # Handle nested #if/#else. | ||
| 448 | if ($remainder =~ /^#\s*(?:ifndef|ifdef|if)\s/) { | ||
| 449 | push(@stack, [ $type, $level ]); | ||
| 450 | } elsif ($remainder =~ /^#\s*(?:else|elif)\b/) { | ||
| 451 | ($type, $level) = @{$stack[$#stack - 1]}; | ||
| 452 | } elsif ($remainder =~ /^#\s*endif\b/) { | ||
| 453 | ($type, $level) = @{pop(@stack)}; | ||
| 454 | } | ||
| 455 | |||
| 436 | # Statement ends at the ';' or a close '}' at the | 456 | # Statement ends at the ';' or a close '}' at the |
| 437 | # outermost level. | 457 | # outermost level. |
| 438 | if ($level == 0 && $c eq ';') { | 458 | if ($level == 0 && $c eq ';') { |
| @@ -579,11 +599,22 @@ sub ctx_block_get { | |||
| 579 | my @res = (); | 599 | my @res = (); |
| 580 | 600 | ||
| 581 | my $level = 0; | 601 | my $level = 0; |
| 602 | my @stack = ($level); | ||
| 582 | for ($line = $start; $remain > 0; $line++) { | 603 | for ($line = $start; $remain > 0; $line++) { |
| 583 | next if ($rawlines[$line] =~ /^-/); | 604 | next if ($rawlines[$line] =~ /^-/); |
| 584 | $remain--; | 605 | $remain--; |
| 585 | 606 | ||
| 586 | $blk .= $rawlines[$line]; | 607 | $blk .= $rawlines[$line]; |
| 608 | |||
| 609 | # Handle nested #if/#else. | ||
| 610 | if ($rawlines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) { | ||
| 611 | push(@stack, $level); | ||
| 612 | } elsif ($rawlines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) { | ||
| 613 | $level = $stack[$#stack - 1]; | ||
| 614 | } elsif ($rawlines[$line] =~ /^.\s*#\s*endif\b/) { | ||
| 615 | $level = pop(@stack); | ||
| 616 | } | ||
| 617 | |||
| 587 | foreach my $c (split(//, $rawlines[$line])) { | 618 | foreach my $c (split(//, $rawlines[$line])) { |
| 588 | ##print "C<$c>L<$level><$open$close>O<$off>\n"; | 619 | ##print "C<$c>L<$level><$open$close>O<$off>\n"; |
| 589 | if ($off > 0) { | 620 | if ($off > 0) { |
| @@ -843,11 +874,11 @@ sub annotate_values { | |||
| 843 | $type = 'V'; | 874 | $type = 'V'; |
| 844 | $av_pending = 'V'; | 875 | $av_pending = 'V'; |
| 845 | 876 | ||
| 846 | } elsif ($cur =~ /^($Ident\s*):/) { | 877 | } elsif ($cur =~ /^($Ident\s*):(?:\s*\d+\s*(,|=|;))?/) { |
| 847 | if ($type eq 'E') { | 878 | if (defined $2 && $type eq 'C' || $type eq 'T') { |
| 848 | $av_pend_colon = 'L'; | ||
| 849 | } elsif ($type eq 'T') { | ||
| 850 | $av_pend_colon = 'B'; | 879 | $av_pend_colon = 'B'; |
| 880 | } elsif ($type eq 'E') { | ||
| 881 | $av_pend_colon = 'L'; | ||
| 851 | } | 882 | } |
| 852 | print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1); | 883 | print "IDENT_COLON($1,$type>$av_pend_colon)\n" if ($dbg_values > 1); |
| 853 | $type = 'V'; | 884 | $type = 'V'; |
| @@ -865,6 +896,10 @@ sub annotate_values { | |||
| 865 | $type = 'E'; | 896 | $type = 'E'; |
| 866 | $av_pend_colon = 'O'; | 897 | $av_pend_colon = 'O'; |
| 867 | 898 | ||
| 899 | } elsif ($cur =~/^(,)/) { | ||
| 900 | print "COMMA($1)\n" if ($dbg_values > 1); | ||
| 901 | $type = 'C'; | ||
| 902 | |||
| 868 | } elsif ($cur =~ /^(\?)/o) { | 903 | } elsif ($cur =~ /^(\?)/o) { |
| 869 | print "QUESTION($1)\n" if ($dbg_values > 1); | 904 | print "QUESTION($1)\n" if ($dbg_values > 1); |
| 870 | $type = 'N'; | 905 | $type = 'N'; |
| @@ -880,7 +915,7 @@ sub annotate_values { | |||
| 880 | } | 915 | } |
| 881 | $av_pend_colon = 'O'; | 916 | $av_pend_colon = 'O'; |
| 882 | 917 | ||
| 883 | } elsif ($cur =~ /^(;|\[)/o) { | 918 | } elsif ($cur =~ /^(\[)/o) { |
| 884 | print "CLOSE($1)\n" if ($dbg_values > 1); | 919 | print "CLOSE($1)\n" if ($dbg_values > 1); |
| 885 | $type = 'N'; | 920 | $type = 'N'; |
| 886 | 921 | ||
| @@ -1051,6 +1086,7 @@ sub process { | |||
| 1051 | my $in_comment = 0; | 1086 | my $in_comment = 0; |
| 1052 | my $comment_edge = 0; | 1087 | my $comment_edge = 0; |
| 1053 | my $first_line = 0; | 1088 | my $first_line = 0; |
| 1089 | my $p1_prefix = ''; | ||
| 1054 | 1090 | ||
| 1055 | my $prev_values = 'E'; | 1091 | my $prev_values = 'E'; |
| 1056 | 1092 | ||
| @@ -1097,9 +1133,12 @@ sub process { | |||
| 1097 | $rawlines[$ln - 1] =~ /^-/); | 1133 | $rawlines[$ln - 1] =~ /^-/); |
| 1098 | $cnt--; | 1134 | $cnt--; |
| 1099 | #print "RAW<$rawlines[$ln - 1]>\n"; | 1135 | #print "RAW<$rawlines[$ln - 1]>\n"; |
| 1100 | ($edge) = (defined $rawlines[$ln - 1] && | 1136 | last if (!defined $rawlines[$ln - 1]); |
| 1101 | $rawlines[$ln - 1] =~ m@(/\*|\*/)@); | 1137 | if ($rawlines[$ln - 1] =~ m@(/\*|\*/)@ && |
| 1102 | last if (defined $edge); | 1138 | $rawlines[$ln - 1] !~ m@"[^"]*(?:/\*|\*/)[^"]*"@) { |
| 1139 | ($edge) = $1; | ||
| 1140 | last; | ||
| 1141 | } | ||
| 1103 | } | 1142 | } |
| 1104 | if (defined $edge && $edge eq '*/') { | 1143 | if (defined $edge && $edge eq '*/') { |
| 1105 | $in_comment = 1; | 1144 | $in_comment = 1; |
| @@ -1109,7 +1148,7 @@ sub process { | |||
| 1109 | # is the start of a diff block and this line starts | 1148 | # is the start of a diff block and this line starts |
| 1110 | # ' *' then it is very likely a comment. | 1149 | # ' *' then it is very likely a comment. |
| 1111 | if (!defined $edge && | 1150 | if (!defined $edge && |
| 1112 | $rawlines[$linenr] =~ m@^.\s* \*(?:\s|$)@) | 1151 | $rawlines[$linenr] =~ m@^.\s*(?:\*\*+| \*)(?:\s|$)@) |
| 1113 | { | 1152 | { |
| 1114 | $in_comment = 1; | 1153 | $in_comment = 1; |
| 1115 | } | 1154 | } |
| @@ -1196,7 +1235,12 @@ sub process { | |||
| 1196 | # extract the filename as it passes | 1235 | # extract the filename as it passes |
| 1197 | if ($line=~/^\+\+\+\s+(\S+)/) { | 1236 | if ($line=~/^\+\+\+\s+(\S+)/) { |
| 1198 | $realfile = $1; | 1237 | $realfile = $1; |
| 1199 | $realfile =~ s@^[^/]*/@@; | 1238 | $realfile =~ s@^([^/]*)/@@; |
| 1239 | |||
| 1240 | $p1_prefix = $1; | ||
| 1241 | if ($tree && $p1_prefix ne '' && -e "$root/$p1_prefix") { | ||
| 1242 | WARN("patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n"); | ||
| 1243 | } | ||
| 1200 | 1244 | ||
| 1201 | if ($realfile =~ m@^include/asm/@) { | 1245 | if ($realfile =~ m@^include/asm/@) { |
| 1202 | ERROR("do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n"); | 1246 | ERROR("do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n"); |
| @@ -1336,7 +1380,7 @@ sub process { | |||
| 1336 | } | 1380 | } |
| 1337 | 1381 | ||
| 1338 | # any (foo ... *) is a pointer cast, and foo is a type | 1382 | # any (foo ... *) is a pointer cast, and foo is a type |
| 1339 | while ($s =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/sg) { | 1383 | while ($s =~ /\(($Ident)(?:\s+$Sparse)*[\s\*]+\s*\)/sg) { |
| 1340 | possible($1, "C:" . $s); | 1384 | possible($1, "C:" . $s); |
| 1341 | } | 1385 | } |
| 1342 | 1386 | ||
| @@ -1594,7 +1638,7 @@ sub process { | |||
| 1594 | $herecurr); | 1638 | $herecurr); |
| 1595 | } | 1639 | } |
| 1596 | # check for static initialisers. | 1640 | # check for static initialisers. |
| 1597 | if ($line =~ /\s*static\s.*=\s*(0|NULL|false)\s*;/) { | 1641 | if ($line =~ /\bstatic\s.*=\s*(0|NULL|false)\s*;/) { |
| 1598 | ERROR("do not initialise statics to 0 or NULL\n" . | 1642 | ERROR("do not initialise statics to 0 or NULL\n" . |
| 1599 | $herecurr); | 1643 | $herecurr); |
| 1600 | } | 1644 | } |
| @@ -1602,7 +1646,7 @@ sub process { | |||
| 1602 | # check for new typedefs, only function parameters and sparse annotations | 1646 | # check for new typedefs, only function parameters and sparse annotations |
| 1603 | # make sense. | 1647 | # make sense. |
| 1604 | if ($line =~ /\btypedef\s/ && | 1648 | if ($line =~ /\btypedef\s/ && |
| 1605 | $line !~ /\btypedef\s+$Type\s+\(\s*\*?$Ident\s*\)\s*\(/ && | 1649 | $line !~ /\btypedef\s+$Type\s*\(\s*\*?$Ident\s*\)\s*\(/ && |
| 1606 | $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && | 1650 | $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && |
| 1607 | $line !~ /\b$typeTypedefs\b/ && | 1651 | $line !~ /\b$typeTypedefs\b/ && |
| 1608 | $line !~ /\b__bitwise(?:__|)\b/) { | 1652 | $line !~ /\b__bitwise(?:__|)\b/) { |
| @@ -1610,21 +1654,39 @@ sub process { | |||
| 1610 | } | 1654 | } |
| 1611 | 1655 | ||
| 1612 | # * goes on variable not on type | 1656 | # * goes on variable not on type |
| 1613 | if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) { | 1657 | # (char*[ const]) |
| 1614 | ERROR("\"(foo$1)\" should be \"(foo $1)\"\n" . | 1658 | if ($line =~ m{\($NonptrType(\s*\*[\s\*]*(?:$Modifier\s*)*)\)}) { |
| 1615 | $herecurr); | 1659 | my ($from, $to) = ($1, $1); |
| 1616 | 1660 | ||
| 1617 | } elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) { | 1661 | # Should start with a space. |
| 1618 | ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" . | 1662 | $to =~ s/^(\S)/ $1/; |
| 1619 | $herecurr); | 1663 | # Should not end with a space. |
| 1664 | $to =~ s/\s+$//; | ||
| 1665 | # '*'s should not have spaces between. | ||
| 1666 | while ($to =~ s/(.)\s\*/$1\*/) { | ||
| 1667 | } | ||
| 1620 | 1668 | ||
| 1621 | } elsif ($line =~ m{\b$NonptrType(\*+)(?:\s+(?:$Attribute|$Sparse))?\s+[A-Za-z\d_]+}) { | 1669 | #print "from<$from> to<$to>\n"; |
| 1622 | ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" . | 1670 | if ($from ne $to) { |
| 1623 | $herecurr); | 1671 | ERROR("\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr); |
| 1672 | } | ||
| 1673 | } elsif ($line =~ m{\b$NonptrType(\s*\*[\s\*]*(?:$Modifier\s*)?)($Ident)}) { | ||
| 1674 | my ($from, $to, $ident) = ($1, $1, $2); | ||
| 1624 | 1675 | ||
| 1625 | } elsif ($line =~ m{\b$NonptrType\s+(\*+)(?!\s+(?:$Attribute|$Sparse))\s+[A-Za-z\d_]+}) { | 1676 | # Should start with a space. |
| 1626 | ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" . | 1677 | $to =~ s/^(\S)/ $1/; |
| 1627 | $herecurr); | 1678 | # Should not end with a space. |
| 1679 | $to =~ s/\s+$//; | ||
| 1680 | # '*'s should not have spaces between. | ||
| 1681 | while ($to =~ s/(.)\s\*/$1\*/) { | ||
| 1682 | } | ||
| 1683 | # Modifiers should have spaces. | ||
| 1684 | $to =~ s/(\b$Modifier$)/$1 /; | ||
| 1685 | |||
| 1686 | #print "from<$from> to<$to>\n"; | ||
| 1687 | if ($from ne $to) { | ||
| 1688 | ERROR("\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr); | ||
| 1689 | } | ||
| 1628 | } | 1690 | } |
| 1629 | 1691 | ||
| 1630 | # # no BUG() or BUG_ON() | 1692 | # # no BUG() or BUG_ON() |
| @@ -1759,7 +1821,7 @@ sub process { | |||
| 1759 | $c = 'C' if ($elements[$n + 2] =~ /^$;/); | 1821 | $c = 'C' if ($elements[$n + 2] =~ /^$;/); |
| 1760 | $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/); | 1822 | $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/); |
| 1761 | $c = 'O' if ($elements[$n + 2] eq ''); | 1823 | $c = 'O' if ($elements[$n + 2] eq ''); |
| 1762 | $c = 'E' if ($elements[$n + 2] =~ /\s*\\$/); | 1824 | $c = 'E' if ($elements[$n + 2] =~ /^\s*\\$/); |
| 1763 | } else { | 1825 | } else { |
| 1764 | $c = 'E'; | 1826 | $c = 'E'; |
| 1765 | } | 1827 | } |
| @@ -1950,9 +2012,9 @@ sub process { | |||
| 1950 | my $spacing = $1; | 2012 | my $spacing = $1; |
| 1951 | my $value = $2; | 2013 | my $value = $2; |
| 1952 | 2014 | ||
| 1953 | # Flatten any parentheses and braces | 2015 | # Flatten any parentheses |
| 1954 | $value =~ s/\)\(/\) \(/g; | 2016 | $value =~ s/\)\(/\) \(/g; |
| 1955 | while ($value =~ s/\([^\(\)]*\)/1/) { | 2017 | while ($value !~ /(?:$Ident|-?$Constant)\s*$Compare\s*(?:$Ident|-?$Constant)/ && $value =~ s/\([^\(\)]*\)/1/) { |
| 1956 | } | 2018 | } |
| 1957 | 2019 | ||
| 1958 | if ($value =~ /^(?:$Ident|-?$Constant)$/) { | 2020 | if ($value =~ /^(?:$Ident|-?$Constant)$/) { |
| @@ -1992,7 +2054,7 @@ sub process { | |||
| 1992 | $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) { | 2054 | $line =~ /\b(?:if|while|for)\s*\(/ && $line !~ /^.\s*#/) { |
| 1993 | my ($s, $c) = ($stat, $cond); | 2055 | my ($s, $c) = ($stat, $cond); |
| 1994 | 2056 | ||
| 1995 | if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/) { | 2057 | if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) { |
| 1996 | ERROR("do not use assignment in if condition\n" . $herecurr); | 2058 | ERROR("do not use assignment in if condition\n" . $herecurr); |
| 1997 | } | 2059 | } |
| 1998 | 2060 | ||
| @@ -2167,9 +2229,10 @@ sub process { | |||
| 2167 | MODULE_PARAM_DESC| | 2229 | MODULE_PARAM_DESC| |
| 2168 | DECLARE_PER_CPU| | 2230 | DECLARE_PER_CPU| |
| 2169 | DEFINE_PER_CPU| | 2231 | DEFINE_PER_CPU| |
| 2170 | __typeof__\( | 2232 | __typeof__\(| |
| 2233 | \.$Ident\s*=\s* | ||
| 2171 | }x; | 2234 | }x; |
| 2172 | #print "REST<$rest>\n"; | 2235 | #print "REST<$rest> dstat<$dstat>\n"; |
| 2173 | if ($rest ne '') { | 2236 | if ($rest ne '') { |
| 2174 | if ($rest !~ /while\s*\(/ && | 2237 | if ($rest !~ /while\s*\(/ && |
| 2175 | $dstat !~ /$exceptions/) | 2238 | $dstat !~ /$exceptions/) |
| @@ -2189,6 +2252,15 @@ sub process { | |||
| 2189 | } | 2252 | } |
| 2190 | } | 2253 | } |
| 2191 | 2254 | ||
| 2255 | # make sure symbols are always wrapped with VMLINUX_SYMBOL() ... | ||
| 2256 | # all assignments may have only one of the following with an assignment: | ||
| 2257 | # . | ||
| 2258 | # ALIGN(...) | ||
| 2259 | # VMLINUX_SYMBOL(...) | ||
| 2260 | if ($realfile eq 'vmlinux.lds.h' && $line =~ /(?:(?:^|\s)$Ident\s*=|=\s*$Ident(?:\s|$))/) { | ||
| 2261 | WARN("vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr); | ||
| 2262 | } | ||
| 2263 | |||
| 2192 | # check for redundant bracing round if etc | 2264 | # check for redundant bracing round if etc |
| 2193 | if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) { | 2265 | if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) { |
| 2194 | my ($level, $endln, @chunks) = | 2266 | my ($level, $endln, @chunks) = |
| @@ -2443,6 +2515,11 @@ sub process { | |||
| 2443 | if ($line =~ /^.\s*__initcall\s*\(/) { | 2515 | if ($line =~ /^.\s*__initcall\s*\(/) { |
| 2444 | WARN("please use device_initcall() instead of __initcall()\n" . $herecurr); | 2516 | WARN("please use device_initcall() instead of __initcall()\n" . $herecurr); |
| 2445 | } | 2517 | } |
| 2518 | # check for struct file_operations, ensure they are const. | ||
| 2519 | if ($line =~ /\bstruct\s+file_operations\b/ && | ||
| 2520 | $line !~ /\bconst\b/) { | ||
| 2521 | WARN("struct file_operations should normally be const\n" . $herecurr); | ||
| 2522 | } | ||
| 2446 | 2523 | ||
| 2447 | # use of NR_CPUS is usually wrong | 2524 | # use of NR_CPUS is usually wrong |
| 2448 | # ignore definitions of NR_CPUS and usage to define arrays as likely right | 2525 | # ignore definitions of NR_CPUS and usage to define arrays as likely right |
| @@ -2466,6 +2543,15 @@ sub process { | |||
| 2466 | last; | 2543 | last; |
| 2467 | } | 2544 | } |
| 2468 | } | 2545 | } |
| 2546 | |||
| 2547 | # whine mightly about in_atomic | ||
| 2548 | if ($line =~ /\bin_atomic\s*\(/) { | ||
| 2549 | if ($realfile =~ m@^drivers/@) { | ||
| 2550 | ERROR("do not use in_atomic in drivers\n" . $herecurr); | ||
| 2551 | } else { | ||
| 2552 | WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr); | ||
| 2553 | } | ||
| 2554 | } | ||
| 2469 | } | 2555 | } |
| 2470 | 2556 | ||
| 2471 | # If we have no input at all, then there is nothing to report on | 2557 | # If we have no input at all, then there is nothing to report on |
diff --git a/scripts/markup_oops.pl b/scripts/markup_oops.pl new file mode 100644 index 000000000000..700a7a654a3f --- /dev/null +++ b/scripts/markup_oops.pl | |||
| @@ -0,0 +1,162 @@ | |||
| 1 | #!/usr/bin/perl -w | ||
| 2 | |||
| 3 | # Copyright 2008, Intel Corporation | ||
| 4 | # | ||
| 5 | # This file is part of the Linux kernel | ||
| 6 | # | ||
| 7 | # This program file is free software; you can redistribute it and/or modify it | ||
| 8 | # under the terms of the GNU General Public License as published by the | ||
| 9 | # Free Software Foundation; version 2 of the License. | ||
| 10 | # | ||
| 11 | # Authors: | ||
| 12 | # Arjan van de Ven <arjan@linux.intel.com> | ||
| 13 | |||
| 14 | |||
| 15 | my $vmlinux_name = $ARGV[0]; | ||
| 16 | |||
| 17 | # | ||
| 18 | # Step 1: Parse the oops to find the EIP value | ||
| 19 | # | ||
| 20 | |||
| 21 | my $target = "0"; | ||
| 22 | while (<STDIN>) { | ||
| 23 | if ($_ =~ /EIP: 0060:\[\<([a-z0-9]+)\>\]/) { | ||
| 24 | $target = $1; | ||
| 25 | } | ||
| 26 | } | ||
| 27 | |||
| 28 | if ($target =~ /^f8/) { | ||
| 29 | print "This script does not work on modules ... \n"; | ||
| 30 | exit; | ||
| 31 | } | ||
| 32 | |||
| 33 | if ($target eq "0") { | ||
| 34 | print "No oops found!\n"; | ||
| 35 | print "Usage: \n"; | ||
| 36 | print " dmesg | perl scripts/markup_oops.pl vmlinux\n"; | ||
| 37 | exit; | ||
| 38 | } | ||
| 39 | |||
| 40 | my $counter = 0; | ||
| 41 | my $state = 0; | ||
| 42 | my $center = 0; | ||
| 43 | my @lines; | ||
| 44 | |||
| 45 | sub InRange { | ||
| 46 | my ($address, $target) = @_; | ||
| 47 | my $ad = "0x".$address; | ||
| 48 | my $ta = "0x".$target; | ||
| 49 | my $delta = hex($ad) - hex($ta); | ||
| 50 | |||
| 51 | if (($delta > -4096) && ($delta < 4096)) { | ||
| 52 | return 1; | ||
| 53 | } | ||
| 54 | return 0; | ||
| 55 | } | ||
| 56 | |||
| 57 | |||
| 58 | |||
| 59 | # first, parse the input into the lines array, but to keep size down, | ||
| 60 | # we only do this for 4Kb around the sweet spot | ||
| 61 | |||
| 62 | my $filename; | ||
| 63 | |||
| 64 | open(FILE, "objdump -dS $vmlinux_name |") || die "Cannot start objdump"; | ||
| 65 | |||
| 66 | while (<FILE>) { | ||
| 67 | my $line = $_; | ||
| 68 | chomp($line); | ||
| 69 | if ($state == 0) { | ||
| 70 | if ($line =~ /^([a-f0-9]+)\:/) { | ||
| 71 | if (InRange($1, $target)) { | ||
| 72 | $state = 1; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } else { | ||
| 76 | if ($line =~ /^([a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9]+)\:/) { | ||
| 77 | my $val = $1; | ||
| 78 | if (!InRange($val, $target)) { | ||
| 79 | last; | ||
| 80 | } | ||
| 81 | if ($val eq $target) { | ||
| 82 | $center = $counter; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | $lines[$counter] = $line; | ||
| 86 | |||
| 87 | $counter = $counter + 1; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | |||
| 91 | close(FILE); | ||
| 92 | |||
| 93 | if ($counter == 0) { | ||
| 94 | print "No matching code found \n"; | ||
| 95 | exit; | ||
| 96 | } | ||
| 97 | |||
| 98 | if ($center == 0) { | ||
| 99 | print "No matching code found \n"; | ||
| 100 | exit; | ||
| 101 | } | ||
| 102 | |||
| 103 | my $start; | ||
| 104 | my $finish; | ||
| 105 | my $codelines = 0; | ||
| 106 | my $binarylines = 0; | ||
| 107 | # now we go up and down in the array to find how much we want to print | ||
| 108 | |||
| 109 | $start = $center; | ||
| 110 | |||
| 111 | while ($start > 1) { | ||
| 112 | $start = $start - 1; | ||
| 113 | my $line = $lines[$start]; | ||
| 114 | if ($line =~ /^([a-f0-9]+)\:/) { | ||
| 115 | $binarylines = $binarylines + 1; | ||
| 116 | } else { | ||
| 117 | $codelines = $codelines + 1; | ||
| 118 | } | ||
| 119 | if ($codelines > 10) { | ||
| 120 | last; | ||
| 121 | } | ||
| 122 | if ($binarylines > 20) { | ||
| 123 | last; | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | |||
| 128 | $finish = $center; | ||
| 129 | $codelines = 0; | ||
| 130 | $binarylines = 0; | ||
| 131 | while ($finish < $counter) { | ||
| 132 | $finish = $finish + 1; | ||
| 133 | my $line = $lines[$finish]; | ||
| 134 | if ($line =~ /^([a-f0-9]+)\:/) { | ||
| 135 | $binarylines = $binarylines + 1; | ||
| 136 | } else { | ||
| 137 | $codelines = $codelines + 1; | ||
| 138 | } | ||
| 139 | if ($codelines > 10) { | ||
| 140 | last; | ||
| 141 | } | ||
| 142 | if ($binarylines > 20) { | ||
| 143 | last; | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | |||
| 148 | my $i; | ||
| 149 | |||
| 150 | my $fulltext = ""; | ||
| 151 | $i = $start; | ||
| 152 | while ($i < $finish) { | ||
| 153 | if ($i == $center) { | ||
| 154 | $fulltext = $fulltext . "*$lines[$i] <----- faulting instruction\n"; | ||
| 155 | } else { | ||
| 156 | $fulltext = $fulltext . " $lines[$i]\n"; | ||
| 157 | } | ||
| 158 | $i = $i +1; | ||
| 159 | } | ||
| 160 | |||
| 161 | print $fulltext; | ||
| 162 | |||
