aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl535
-rw-r--r--scripts/decodecode51
-rw-r--r--scripts/kallsyms.c4
-rwxr-xr-xscripts/kernel-doc28
4 files changed, 389 insertions, 229 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 277c32647f36..73751ab6ec0c 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -9,7 +9,7 @@ use strict;
9my $P = $0; 9my $P = $0;
10$P =~ s@.*/@@g; 10$P =~ s@.*/@@g;
11 11
12my $V = '0.06'; 12my $V = '0.08';
13 13
14use Getopt::Long qw(:config no_auto_abbrev); 14use Getopt::Long qw(:config no_auto_abbrev);
15 15
@@ -47,16 +47,14 @@ my $removal = 'Documentation/feature-removal-schedule.txt';
47if ($tree && -f $removal) { 47if ($tree && -f $removal) {
48 open(REMOVE, "<$removal") || die "$P: $removal: open failed - $!\n"; 48 open(REMOVE, "<$removal") || die "$P: $removal: open failed - $!\n";
49 while (<REMOVE>) { 49 while (<REMOVE>) {
50 if (/^Files:\s+(.*\S)/) { 50 if (/^Check:\s+(.*\S)/) {
51 for my $file (split(/[, ]+/, $1)) { 51 for my $entry (split(/[, ]+/, $1)) {
52 if ($file =~ m@include/(.*)@) { 52 if ($entry =~ m@include/(.*)@) {
53 push(@dep_includes, $1); 53 push(@dep_includes, $1);
54 }
55 }
56 54
57 } elsif (/^Funcs:\s+(.*\S)/) { 55 } elsif ($entry !~ m@/@) {
58 for my $func (split(/[, ]+/, $1)) { 56 push(@dep_functions, $entry);
59 push(@dep_functions, $func); 57 }
60 } 58 }
61 } 59 }
62 } 60 }
@@ -153,7 +151,7 @@ sub sanitise_line {
153} 151}
154 152
155sub ctx_block_get { 153sub ctx_block_get {
156 my ($linenr, $remain, $outer, $open, $close) = @_; 154 my ($linenr, $remain, $outer, $open, $close, $off) = @_;
157 my $line; 155 my $line;
158 my $start = $linenr - 1; 156 my $start = $linenr - 1;
159 my $blk = ''; 157 my $blk = '';
@@ -161,38 +159,58 @@ sub ctx_block_get {
161 my @c; 159 my @c;
162 my @res = (); 160 my @res = ();
163 161
162 my $level = 0;
164 for ($line = $start; $remain > 0; $line++) { 163 for ($line = $start; $remain > 0; $line++) {
165 next if ($rawlines[$line] =~ /^-/); 164 next if ($rawlines[$line] =~ /^-/);
166 $remain--; 165 $remain--;
167 166
168 $blk .= $rawlines[$line]; 167 $blk .= $rawlines[$line];
168 foreach my $c (split(//, $rawlines[$line])) {
169 ##print "C<$c>L<$level><$open$close>O<$off>\n";
170 if ($off > 0) {
171 $off--;
172 next;
173 }
169 174
170 @o = ($blk =~ /$open/g); 175 if ($c eq $close && $level > 0) {
171 @c = ($blk =~ /$close/g); 176 $level--;
177 last if ($level == 0);
178 } elsif ($c eq $open) {
179 $level++;
180 }
181 }
172 182
173 if (!$outer || (scalar(@o) - scalar(@c)) == 1) { 183 if (!$outer || $level <= 1) {
174 push(@res, $rawlines[$line]); 184 push(@res, $rawlines[$line]);
175 } 185 }
176 186
177 last if (scalar(@o) == scalar(@c)); 187 last if ($level == 0);
178 } 188 }
179 189
180 return @res; 190 return ($level, @res);
181} 191}
182sub ctx_block_outer { 192sub ctx_block_outer {
183 my ($linenr, $remain) = @_; 193 my ($linenr, $remain) = @_;
184 194
185 return ctx_block_get($linenr, $remain, 1, '\{', '\}'); 195 my ($level, @r) = ctx_block_get($linenr, $remain, 1, '{', '}', 0);
196 return @r;
186} 197}
187sub ctx_block { 198sub ctx_block {
188 my ($linenr, $remain) = @_; 199 my ($linenr, $remain) = @_;
189 200
190 return ctx_block_get($linenr, $remain, 0, '\{', '\}'); 201 my ($level, @r) = ctx_block_get($linenr, $remain, 0, '{', '}', 0);
202 return @r;
191} 203}
192sub ctx_statement { 204sub ctx_statement {
205 my ($linenr, $remain, $off) = @_;
206
207 my ($level, @r) = ctx_block_get($linenr, $remain, 0, '(', ')', $off);
208 return @r;
209}
210sub ctx_block_level {
193 my ($linenr, $remain) = @_; 211 my ($linenr, $remain) = @_;
194 212
195 return ctx_block_get($linenr, $remain, 0, '\(', '\)'); 213 return ctx_block_get($linenr, $remain, 0, '{', '}', 0);
196} 214}
197 215
198sub ctx_locate_comment { 216sub ctx_locate_comment {
@@ -246,6 +264,26 @@ sub cat_vet {
246 return $vet; 264 return $vet;
247} 265}
248 266
267my @report = ();
268sub report {
269 push(@report, $_[0]);
270}
271sub report_dump {
272 @report;
273}
274sub ERROR {
275 report("ERROR: $_[0]\n");
276 our $clean = 0;
277}
278sub WARN {
279 report("WARNING: $_[0]\n");
280 our $clean = 0;
281}
282sub CHK {
283 report("CHECK: $_[0]\n");
284 our $clean = 0;
285}
286
249sub process { 287sub process {
250 my $filename = shift; 288 my $filename = shift;
251 my @lines = @_; 289 my @lines = @_;
@@ -259,7 +297,7 @@ sub process {
259 my $previndent=0; 297 my $previndent=0;
260 my $stashindent=0; 298 my $stashindent=0;
261 299
262 my $clean = 1; 300 our $clean = 1;
263 my $signoff = 0; 301 my $signoff = 0;
264 my $is_patch = 0; 302 my $is_patch = 0;
265 303
@@ -290,8 +328,11 @@ sub process {
290 long\s+int| 328 long\s+int|
291 long\s+long| 329 long\s+long|
292 long\s+long\s+int| 330 long\s+long\s+int|
331 u8|u16|u32|u64|
332 s8|s16|s32|s64|
293 struct\s+$Ident| 333 struct\s+$Ident|
294 union\s+$Ident| 334 union\s+$Ident|
335 enum\s+$Ident|
295 ${Ident}_t 336 ${Ident}_t
296 ) 337 )
297 (?:\s+$Sparse)* 338 (?:\s+$Sparse)*
@@ -302,7 +343,27 @@ sub process {
302 (?:\s*\*+\s*const|\s*\*+)? 343 (?:\s*\*+\s*const|\s*\*+)?
303 }x; 344 }x;
304 my $Declare = qr{(?:$Storage\s+)?$Type}; 345 my $Declare = qr{(?:$Storage\s+)?$Type};
305 my $Attribute = qr{__read_mostly|__init|__initdata}; 346 my $Attribute = qr{const|__read_mostly|__init|__initdata|__meminit};
347
348 my $Member = qr{->$Ident|\.$Ident|\[[^]]*\]};
349 my $Lval = qr{$Ident(?:$Member)*};
350
351 # Pre-scan the patch looking for any __setup documentation.
352 my @setup_docs = ();
353 my $setup_docs = 0;
354 foreach my $line (@lines) {
355 if ($line=~/^\+\+\+\s+(\S+)/) {
356 $setup_docs = 0;
357 if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
358 $setup_docs = 1;
359 }
360 next;
361 }
362
363 if ($setup_docs && $line =~ /^\+/) {
364 push(@setup_docs, $line);
365 }
366 }
306 367
307 foreach my $line (@lines) { 368 foreach my $line (@lines) {
308 $linenr++; 369 $linenr++;
@@ -369,30 +430,42 @@ sub process {
369 $here .= "FILE: $realfile:$realline:" if ($realcnt != 0); 430 $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
370 431
371 my $hereline = "$here\n$line\n"; 432 my $hereline = "$here\n$line\n";
372 my $herecurr = "$here\n$line\n\n"; 433 my $herecurr = "$here\n$line\n";
373 my $hereprev = "$here\n$prevline\n$line\n\n"; 434 my $hereprev = "$here\n$prevline\n$line\n";
374 435
375#check the patch for a signoff: 436#check the patch for a signoff:
376 if ($line =~ /^\s*signed-off-by:/i) { 437 if ($line =~ /^\s*signed-off-by:/i) {
377 # This is a signoff, if ugly, so do not double report. 438 # This is a signoff, if ugly, so do not double report.
378 $signoff++; 439 $signoff++;
379 if (!($line =~ /^\s*Signed-off-by:/)) { 440 if (!($line =~ /^\s*Signed-off-by:/)) {
380 print "Signed-off-by: is the preferred form\n"; 441 WARN("Signed-off-by: is the preferred form\n" .
381 print "$herecurr"; 442 $herecurr);
382 $clean = 0;
383 } 443 }
384 if ($line =~ /^\s*signed-off-by:\S/i) { 444 if ($line =~ /^\s*signed-off-by:\S/i) {
385 print "need space after Signed-off-by:\n"; 445 WARN("need space after Signed-off-by:\n" .
386 print "$herecurr"; 446 $herecurr);
387 $clean = 0;
388 } 447 }
389 } 448 }
390 449
391# Check for wrappage within a valid hunk of the file 450# Check for wrappage within a valid hunk of the file
392 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |$)}) { 451 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |$)}) {
393 print "patch seems to be corrupt (line wrapped?) [$realcnt]\n"; 452 ERROR("patch seems to be corrupt (line wrapped?)\n" .
394 print "$herecurr"; 453 $herecurr);
395 $clean = 0; 454 }
455
456# UTF-8 regex found at http://www.w3.org/International/questions/qa-forms-utf-8.en.php
457 if (($realfile =~ /^$/ || $line =~ /^\+/) &&
458 !($line =~ m/^(
459 [\x09\x0A\x0D\x20-\x7E] # ASCII
460 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
461 | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
462 | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
463 | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
464 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
465 | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
466 | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
467 )*$/x )) {
468 ERROR("Invalid UTF-8\n" . $herecurr);
396 } 469 }
397 470
398#ignore lines being removed 471#ignore lines being removed
@@ -403,16 +476,12 @@ sub process {
403 476
404#trailing whitespace 477#trailing whitespace
405 if ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) { 478 if ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) {
406 my $herevet = "$here\n" . cat_vet($line) . "\n\n"; 479 my $herevet = "$here\n" . cat_vet($line) . "\n";
407 print "trailing whitespace\n"; 480 ERROR("trailing whitespace\n" . $herevet);
408 print "$herevet";
409 $clean = 0;
410 } 481 }
411#80 column limit 482#80 column limit
412 if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) { 483 if ($line =~ /^\+/ && !($prevline=~/\/\*\*/) && $length > 80) {
413 print "line over 80 characters\n"; 484 WARN("line over 80 characters\n" . $herecurr);
414 print "$herecurr";
415 $clean = 0;
416 } 485 }
417 486
418# check we are in a valid source file *.[hc] if not then ignore this hunk 487# check we are in a valid source file *.[hc] if not then ignore this hunk
@@ -421,10 +490,8 @@ sub process {
421# at the beginning of a line any tabs must come first and anything 490# at the beginning of a line any tabs must come first and anything
422# more than 8 must use tabs. 491# more than 8 must use tabs.
423 if ($line=~/^\+\s* \t\s*\S/ or $line=~/^\+\s* \s*/) { 492 if ($line=~/^\+\s* \t\s*\S/ or $line=~/^\+\s* \s*/) {
424 my $herevet = "$here\n" . cat_vet($line) . "\n\n"; 493 my $herevet = "$here\n" . cat_vet($line) . "\n";
425 print "use tabs not spaces\n"; 494 ERROR("use tabs not spaces\n" . $herevet);
426 print "$herevet";
427 $clean = 0;
428 } 495 }
429 496
430 # 497 #
@@ -463,9 +530,27 @@ sub process {
463 } 530 }
464 } 531 }
465 if ($err ne '') { 532 if ($err ne '') {
466 print "switch and case should be at the same indent\n"; 533 ERROR("switch and case should be at the same indent\n$hereline\n$err\n");
467 print "$here\n$line\n$err\n"; 534 }
468 $clean = 0; 535 }
536
537# if/while/etc brace do not go on next line, unless defining a do while loop,
538# or if that brace on the next line is for something else
539 if ($line =~ /\b(?:(if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.#/) {
540 my @ctx = ctx_statement($linenr, $realcnt, 0);
541 my $ctx_ln = $linenr + $#ctx + 1;
542 my $ctx_cnt = $realcnt - $#ctx - 1;
543 my $ctx = join("\n", @ctx);
544
545 while ($ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^-/) {
546 $ctx_ln++;
547 $ctx_cnt--;
548 }
549 ##warn "line<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>";
550
551 if ($ctx !~ /{\s*/ && $ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
552 ERROR("That open brace { should be on the previous line\n" .
553 "$here\n$ctx\n$lines[$ctx_ln - 1]");
469 } 554 }
470 } 555 }
471 556
@@ -474,12 +559,16 @@ sub process {
474 559
475# TEST: allow direct testing of the type matcher. 560# TEST: allow direct testing of the type matcher.
476 if ($tst_type && $line =~ /^.$Declare$/) { 561 if ($tst_type && $line =~ /^.$Declare$/) {
477 print "TEST: is type $Declare\n"; 562 ERROR("TEST: is type $Declare\n" . $herecurr);
478 print "$herecurr";
479 $clean = 0;
480 next; 563 next;
481 } 564 }
482 565
566# check for initialisation to aggregates open brace on the next line
567 if ($prevline =~ /$Declare\s*$Ident\s*=\s*$/ &&
568 $line =~ /^.\s*{/) {
569 ERROR("That open brace { should be on the previous line\n" . $hereprev);
570 }
571
483# 572#
484# Checks which are anchored on the added line. 573# Checks which are anchored on the added line.
485# 574#
@@ -488,9 +577,8 @@ sub process {
488 if ($rawline =~ m{^.#\s*include\s+[<"](.*)[">]}) { 577 if ($rawline =~ m{^.#\s*include\s+[<"](.*)[">]}) {
489 my $path = $1; 578 my $path = $1;
490 if ($path =~ m{//}) { 579 if ($path =~ m{//}) {
491 print "malformed #include filename\n"; 580 ERROR("malformed #include filename\n" .
492 print "$herecurr"; 581 $herecurr);
493 $clean = 0;
494 } 582 }
495 # Sanitise this special form of string. 583 # Sanitise this special form of string.
496 $path = 'X' x length($path); 584 $path = 'X' x length($path);
@@ -499,9 +587,7 @@ sub process {
499 587
500# no C99 // comments 588# no C99 // comments
501 if ($line =~ m{//}) { 589 if ($line =~ m{//}) {
502 print "do not use C99 // comments\n"; 590 ERROR("do not use C99 // comments\n" . $herecurr);
503 print "$herecurr";
504 $clean = 0;
505 } 591 }
506 # Remove C99 comments. 592 # Remove C99 comments.
507 $line =~ s@//.*@@; 593 $line =~ s@//.*@@;
@@ -514,49 +600,45 @@ sub process {
514 ($prevline !~ /^\+}/) && 600 ($prevline !~ /^\+}/) &&
515 ($prevline !~ /^ }/) && 601 ($prevline !~ /^ }/) &&
516 ($prevline !~ /\s$name(?:\s+$Attribute)?\s*(?:;|=)/)) { 602 ($prevline !~ /\s$name(?:\s+$Attribute)?\s*(?:;|=)/)) {
517 print "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n"; 603 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
518 print "$herecurr";
519 $clean = 0;
520 } 604 }
521 } 605 }
522 606
607# check for external initialisers.
608 if ($line =~ /^.$Type\s*$Ident\s*=\s*(0|NULL);/) {
609 ERROR("do not initialise externals to 0 or NULL\n" .
610 $herecurr);
611 }
523# check for static initialisers. 612# check for static initialisers.
524 if ($line=~/\s*static\s.*=\s+(0|NULL);/) { 613 if ($line =~ /\s*static\s.*=\s*(0|NULL);/) {
525 print "do not initialise statics to 0 or NULL\n"; 614 ERROR("do not initialise statics to 0 or NULL\n" .
526 print "$herecurr"; 615 $herecurr);
527 $clean = 0;
528 } 616 }
529 617
530# check for new typedefs, only function parameters and sparse annotations 618# check for new typedefs, only function parameters and sparse annotations
531# make sense. 619# make sense.
532 if ($line =~ /\btypedef\s/ && 620 if ($line =~ /\btypedef\s/ &&
533 $line !~ /\btypedef\s+$Type\s+\(\s*$Ident\s*\)\s*\(/ && 621 $line !~ /\btypedef\s+$Type\s+\(\s*\*$Ident\s*\)\s*\(/ &&
534 $line !~ /\b__bitwise(?:__|)\b/) { 622 $line !~ /\b__bitwise(?:__|)\b/) {
535 print "do not add new typedefs\n"; 623 WARN("do not add new typedefs\n" . $herecurr);
536 print "$herecurr";
537 $clean = 0;
538 } 624 }
539 625
540# * goes on variable not on type 626# * goes on variable not on type
541 if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) { 627 if ($line =~ m{\($NonptrType(\*+)(?:\s+const)?\)}) {
542 print "\"(foo$1)\" should be \"(foo $1)\"\n"; 628 ERROR("\"(foo$1)\" should be \"(foo $1)\"\n" .
543 print "$herecurr"; 629 $herecurr);
544 $clean = 0;
545 630
546 } elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) { 631 } elsif ($line =~ m{\($NonptrType\s+(\*+)(?!\s+const)\s+\)}) {
547 print "\"(foo $1 )\" should be \"(foo $1)\"\n"; 632 ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" .
548 print "$herecurr"; 633 $herecurr);
549 $clean = 0;
550 634
551 } elsif ($line =~ m{$NonptrType(\*+)(?:\s+const)?\s+[A-Za-z\d_]+}) { 635 } elsif ($line =~ m{$NonptrType(\*+)(?:\s+$Attribute)?\s+[A-Za-z\d_]+}) {
552 print "\"foo$1 bar\" should be \"foo $1bar\"\n"; 636 ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" .
553 print "$herecurr"; 637 $herecurr);
554 $clean = 0;
555 638
556 } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+const)\s+[A-Za-z\d_]+}) { 639 } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+$Attribute)\s+[A-Za-z\d_]+}) {
557 print "\"foo $1 bar\" should be \"foo $1bar\"\n"; 640 ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" .
558 print "$herecurr"; 641 $herecurr);
559 $clean = 0;
560 } 642 }
561 643
562# # no BUG() or BUG_ON() 644# # no BUG() or BUG_ON()
@@ -571,7 +653,7 @@ sub process {
571# to try and find and validate the current printk. In summary the current 653# to try and find and validate the current printk. In summary the current
572# printk includes all preceeding printk's which have no newline on the end. 654# printk includes all preceeding printk's which have no newline on the end.
573# we assume the first bad printk is the one to report. 655# we assume the first bad printk is the one to report.
574 if ($line =~ /\bprintk\((?!KERN_)/) { 656 if ($line =~ /\bprintk\((?!KERN_)\s*"/) {
575 my $ok = 0; 657 my $ok = 0;
576 for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) { 658 for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) {
577 #print "CHECK<$lines[$ln - 1]\n"; 659 #print "CHECK<$lines[$ln - 1]\n";
@@ -585,9 +667,7 @@ sub process {
585 } 667 }
586 } 668 }
587 if ($ok == 0) { 669 if ($ok == 0) {
588 print "printk() should include KERN_ facility level\n"; 670 WARN("printk() should include KERN_ facility level\n" . $herecurr);
589 print "$herecurr";
590 $clean = 0;
591 } 671 }
592 } 672 }
593 673
@@ -595,11 +675,15 @@ sub process {
595# or if closed on same line 675# or if closed on same line
596 if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).* {/) and 676 if (($line=~/$Type\s*[A-Za-z\d_]+\(.*\).* {/) and
597 !($line=~/\#define.*do\s{/) and !($line=~/}/)) { 677 !($line=~/\#define.*do\s{/) and !($line=~/}/)) {
598 print "braces following function declarations go on the next line\n"; 678 ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr);
599 print "$herecurr";
600 $clean = 0;
601 } 679 }
602 680
681# check for spaces between functions and their parentheses.
682 if ($line =~ /($Ident)\s+\(/ &&
683 $1 !~ /^(?:if|for|while|switch|return|volatile)$/ &&
684 $line !~ /$Type\s+\(/ && $line !~ /^.\#\s*define\b/) {
685 ERROR("no space between function name and open parenthesis '('\n" . $herecurr);
686 }
603# Check operator spacing. 687# Check operator spacing.
604 # Note we expand the line with the leading + as the real 688 # Note we expand the line with the leading + as the real
605 # line will be displayed with the leading + and the tabs 689 # line will be displayed with the leading + and the tabs
@@ -608,7 +692,7 @@ sub process {
608 $opline = expand_tabs($opline); 692 $opline = expand_tabs($opline);
609 $opline =~ s/^./ /; 693 $opline =~ s/^./ /;
610 if (!($line=~/\#\s*include/)) { 694 if (!($line=~/\#\s*include/)) {
611 my @elements = split(/(<<=|>>=|<=|>=|==|!=|\+=|-=|\*=|\/=|%=|\^=|\|=|&=|->|<<|>>|<|>|=|!|~|&&|\|\||,|\^|\+\+|--|;|&|\||\+|-|\*|\/\/|\/)/, $opline); 695 my @elements = split(/(<<=|>>=|<=|>=|==|!=|\+=|-=|\*=|\/=|%=|\^=|\|=|&=|=>|->|<<|>>|<|>|=|!|~|&&|\|\||,|\^|\+\+|--|;|&|\||\+|-|\*|\/\/|\/)/, $opline);
612 my $off = 0; 696 my $off = 0;
613 for (my $n = 0; $n < $#elements; $n += 2) { 697 for (my $n = 0; $n < $#elements; $n += 2) {
614 $off += length($elements[$n]); 698 $off += length($elements[$n]);
@@ -633,27 +717,27 @@ sub process {
633 } 717 }
634 718
635 # Pick up the preceeding and succeeding characters. 719 # Pick up the preceeding and succeeding characters.
636 my $ca = substr($opline, $off - 1, 1); 720 my $ca = substr($opline, 0, $off);
637 my $cc = ''; 721 my $cc = '';
638 if (length($opline) >= ($off + length($elements[$n + 1]))) { 722 if (length($opline) >= ($off + length($elements[$n + 1]))) {
639 $cc = substr($opline, $off + length($elements[$n + 1])); 723 $cc = substr($opline, $off + length($elements[$n + 1]));
640 } 724 }
725 my $cb = "$ca$;$cc";
641 726
642 my $ctx = "${a}x${c}"; 727 my $ctx = "${a}x${c}";
643 728
644 my $at = "(ctx:$ctx)"; 729 my $at = "(ctx:$ctx)";
645 730
646 my $ptr = (" " x $off) . "^"; 731 my $ptr = (" " x $off) . "^";
647 my $hereptr = "$hereline$ptr\n\n"; 732 my $hereptr = "$hereline$ptr\n";
648 733
649 ##print "<$s1:$op:$s2> <$elements[$n]:$elements[$n + 1]:$elements[$n + 2]>\n"; 734 ##print "<$s1:$op:$s2> <$elements[$n]:$elements[$n + 1]:$elements[$n + 2]>\n";
650 735
651 # ; should have either the end of line or a space or \ after it 736 # ; should have either the end of line or a space or \ after it
652 if ($op eq ';') { 737 if ($op eq ';') {
653 if ($ctx !~ /.x[WE]/ && $cc !~ /^\\/) { 738 if ($ctx !~ /.x[WEB]/ && $cc !~ /^\\/ &&
654 print "need space after that '$op' $at\n"; 739 $cc !~ /^;/) {
655 print "$hereptr"; 740 ERROR("need space after that '$op' $at\n" . $hereptr);
656 $clean = 0;
657 } 741 }
658 742
659 # // is a comment 743 # // is a comment
@@ -662,43 +746,31 @@ sub process {
662 # -> should have no spaces 746 # -> should have no spaces
663 } elsif ($op eq '->') { 747 } elsif ($op eq '->') {
664 if ($ctx =~ /Wx.|.xW/) { 748 if ($ctx =~ /Wx.|.xW/) {
665 print "no spaces around that '$op' $at\n"; 749 ERROR("no spaces around that '$op' $at\n" . $hereptr);
666 print "$hereptr";
667 $clean = 0;
668 } 750 }
669 751
670 # , must have a space on the right. 752 # , must have a space on the right.
671 } elsif ($op eq ',') { 753 } elsif ($op eq ',') {
672 if ($ctx !~ /.xW|.xE/ && $cc !~ /^}/) { 754 if ($ctx !~ /.xW|.xE/ && $cc !~ /^}/) {
673 print "need space after that '$op' $at\n"; 755 ERROR("need space after that '$op' $at\n" . $hereptr);
674 print "$hereptr";
675 $clean = 0;
676 } 756 }
677 757
678 # unary ! and unary ~ are allowed no space on the right 758 # unary ! and unary ~ are allowed no space on the right
679 } elsif ($op eq '!' or $op eq '~') { 759 } elsif ($op eq '!' or $op eq '~') {
680 if ($ctx !~ /[WOEB]x./) { 760 if ($ctx !~ /[WOEB]x./) {
681 print "need space before that '$op' $at\n"; 761 ERROR("need space before that '$op' $at\n" . $hereptr);
682 print "$hereptr";
683 $clean = 0;
684 } 762 }
685 if ($ctx =~ /.xW/) { 763 if ($ctx =~ /.xW/) {
686 print "no space after that '$op' $at\n"; 764 ERROR("no space after that '$op' $at\n" . $hereptr);
687 print "$hereptr";
688 $clean = 0;
689 } 765 }
690 766
691 # unary ++ and unary -- are allowed no space on one side. 767 # unary ++ and unary -- are allowed no space on one side.
692 } elsif ($op eq '++' or $op eq '--') { 768 } elsif ($op eq '++' or $op eq '--') {
693 if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) { 769 if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) {
694 print "need space one side of that '$op' $at\n"; 770 ERROR("need space one side of that '$op' $at\n" . $hereptr);
695 print "$hereptr";
696 $clean = 0;
697 } 771 }
698 if ($ctx =~ /Wx./ && $cc =~ /^;/) { 772 if ($ctx =~ /Wx./ && $cc =~ /^;/) {
699 print "no space before that '$op' $at\n"; 773 ERROR("no space before that '$op' $at\n" . $hereptr);
700 print "$hereptr";
701 $clean = 0;
702 } 774 }
703 775
704 # & is both unary and binary 776 # & is both unary and binary
@@ -715,9 +787,7 @@ sub process {
715 # 787 #
716 } elsif ($op eq '&' or $op eq '-') { 788 } elsif ($op eq '&' or $op eq '-') {
717 if ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]/) { 789 if ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]/) {
718 print "need space before that '$op' $at\n"; 790 ERROR("need space before that '$op' $at\n" . $hereptr);
719 print "$hereptr";
720 $clean = 0;
721 } 791 }
722 792
723 # * is the same as & only adding: 793 # * is the same as & only adding:
@@ -726,16 +796,9 @@ sub process {
726 # (foo **) 796 # (foo **)
727 # 797 #
728 } elsif ($op eq '*') { 798 } elsif ($op eq '*') {
729 if ($ca eq '*') { 799 if ($ca !~ /$Type$/ && $cb !~ /(\*$;|$;\*)/ &&
730 if ($cc =~ /^\s(?!\s*const)/) { 800 $ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]|OxV|WxB|BxB/) {
731 print "no space after that '$op' $at\n"; 801 ERROR("need space before that '$op' $at\n" . $hereptr);
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;
739 } 802 }
740 803
741 # << and >> may either have or not have spaces both sides 804 # << and >> may either have or not have spaces both sides
@@ -743,58 +806,63 @@ sub process {
743 $op eq '^' or $op eq '|') 806 $op eq '^' or $op eq '|')
744 { 807 {
745 if ($ctx !~ /VxV|WxW|VxE|WxE/) { 808 if ($ctx !~ /VxV|WxW|VxE|WxE/) {
746 print "need consistent spacing around '$op' $at\n"; 809 ERROR("need consistent spacing around '$op' $at\n" .
747 print "$hereptr"; 810 $hereptr);
748 $clean = 0;
749 } 811 }
750 812
751 # All the others need spaces both sides. 813 # All the others need spaces both sides.
752 } elsif ($ctx !~ /[EW]x[WE]/) { 814 } elsif ($ctx !~ /[EW]x[WE]/) {
753 print "need spaces around that '$op' $at\n"; 815 ERROR("need spaces around that '$op' $at\n" . $hereptr);
754 print "$hereptr";
755 $clean = 0;
756 } 816 }
757 $off += length($elements[$n + 1]); 817 $off += length($elements[$n + 1]);
758 } 818 }
759 } 819 }
760 820
821# check for multiple assignments
822 if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
823 WARN("multiple assignments should be avoided\n" . $herecurr);
824 }
825
826# check for multiple declarations, allowing for a function declaration
827# continuation.
828 if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
829 $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
830 WARN("declaring multiple variables together should be avoided\n" . $herecurr);
831 }
832
761#need space before brace following if, while, etc 833#need space before brace following if, while, etc
762 if ($line=~/\(.*\){/) { 834 if ($line =~ /\(.*\){/ || $line =~ /do{/) {
763 print "need a space before the brace\n"; 835 ERROR("need a space before the open brace '{'\n" . $herecurr);
764 print "$herecurr"; 836 }
765 $clean = 0; 837
838# closing brace should have a space following it when it has anything
839# on the line
840 if ($line =~ /}(?!(?:,|;|\)))\S/) {
841 ERROR("need a space after that close brace '}'\n" . $herecurr);
766 } 842 }
767 843
768#goto labels aren't indented, allow a single space however 844#goto labels aren't indented, allow a single space however
769 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and 845 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
770 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { 846 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
771 print "labels should not be indented\n"; 847 WARN("labels should not be indented\n" . $herecurr);
772 print "$herecurr";
773 $clean = 0;
774 } 848 }
775 849
776# Need a space before open parenthesis after if, while etc 850# Need a space before open parenthesis after if, while etc
777 if ($line=~/\b(if|while|for|switch)\(/) { 851 if ($line=~/\b(if|while|for|switch)\(/) {
778 print "need a space before the open parenthesis\n"; 852 ERROR("need a space before the open parenthesis '('\n" . $herecurr);
779 print "$herecurr";
780 $clean = 0;
781 } 853 }
782 854
783# Check for illegal assignment in if conditional. 855# Check for illegal assignment in if conditional.
784 if ($line=~/\bif\s*\(.*[^<>!=]=[^=].*\)/) { 856 if ($line=~/\bif\s*\(.*[^<>!=]=[^=].*\)/) {
785 #next if ($line=~/\".*\Q$op\E.*\"/ or $line=~/\'\Q$op\E\'/); 857 #next if ($line=~/\".*\Q$op\E.*\"/ or $line=~/\'\Q$op\E\'/);
786 print "do not use assignment in if condition\n"; 858 ERROR("do not use assignment in if condition\n" . $herecurr);
787 print "$herecurr";
788 $clean = 0;
789 } 859 }
790 860
791 # Check for }<nl>else {, these must be at the same 861 # Check for }<nl>else {, these must be at the same
792 # indent level to be relevant to each other. 862 # indent level to be relevant to each other.
793 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and 863 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
794 $previndent == $indent) { 864 $previndent == $indent) {
795 print "else should follow close brace\n"; 865 ERROR("else should follow close brace '}'\n" . $hereprev);
796 print "$hereprev";
797 $clean = 0;
798 } 866 }
799 867
800#studly caps, commented out until figure out how to distinguish between use of existing and adding new 868#studly caps, commented out until figure out how to distinguish between use of existing and adding new
@@ -806,57 +874,22 @@ sub process {
806 874
807#no spaces allowed after \ in define 875#no spaces allowed after \ in define
808 if ($line=~/\#define.*\\\s$/) { 876 if ($line=~/\#define.*\\\s$/) {
809 print("Whitepspace after \\ makes next lines useless\n"); 877 WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr);
810 print "$herecurr";
811 $clean = 0;
812 } 878 }
813 879
814#warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line) 880#warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
815 if ($tree && $rawline =~ m{^.\#\s*include\s*\<asm\/(.*)\.h\>}) { 881 if ($tree && $rawline =~ m{^.\#\s*include\s*\<asm\/(.*)\.h\>}) {
816 my $checkfile = "include/linux/$1.h"; 882 my $checkfile = "include/linux/$1.h";
817 if (-f $checkfile) { 883 if (-f $checkfile) {
818 print "Use #include <linux/$1.h> instead of <asm/$1.h>\n"; 884 CHK("Use #include <linux/$1.h> instead of <asm/$1.h>\n" .
819 print $herecurr; 885 $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;
851 } 886 }
852 } 887 }
853 888
854# if and else should not have general statements after it 889# if and else should not have general statements after it
855 if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/ && 890 if ($line =~ /^.\s*(?:}\s*)?else\b(.*)/ &&
856 $1 !~ /^\s*(?:\sif|{|$)/) { 891 $1 !~ /^\s*(?:\sif|{|\\|$)/) {
857 print "trailing statements should be on next line\n"; 892 ERROR("trailing statements should be on next line\n" . $herecurr);
858 print "$herecurr";
859 $clean = 0;
860 } 893 }
861 894
862# multi-statement macros should be enclosed in a do while loop, grab the 895# multi-statement macros should be enclosed in a do while loop, grab the
@@ -871,55 +904,106 @@ sub process {
871 # or the one below. 904 # or the one below.
872 my $ln = $linenr; 905 my $ln = $linenr;
873 my $cnt = $realcnt; 906 my $cnt = $realcnt;
907 my $off = 0;
874 908
875 # If the macro starts on the define line start there. 909 # If the macro starts on the define line start
876 if ($prevline !~ m{^.#\s*define\s*$Ident(?:\([^\)]*\))?\s*\\\s*$}) { 910 # grabbing the statement after the identifier
911 $prevline =~ m{^(.#\s*define\s*$Ident(?:\([^\)]*\))?\s*)(.*)\\\s*$};
912 ##print "1<$1> 2<$2>\n";
913 if ($2 ne '') {
914 $off = length($1);
877 $ln--; 915 $ln--;
878 $cnt++; 916 $cnt++;
879 } 917 }
880 my $ctx = join('', ctx_statement($ln, $cnt)); 918 my @ctx = ctx_statement($ln, $cnt, $off);
919 my $ctx_ln = $ln + $#ctx + 1;
920 my $ctx = join("\n", @ctx);
921
922 # Pull in any empty extension lines.
923 while ($ctx =~ /\\$/ &&
924 $lines[$ctx_ln - 1] =~ /^.\s*(?:\\)?$/) {
925 $ctx .= $lines[$ctx_ln - 1];
926 $ctx_ln++;
927 }
881 928
882 if ($ctx =~ /\\$/) { 929 if ($ctx =~ /\\$/) {
883 if ($ctx =~ /;/) { 930 if ($ctx =~ /;/) {
884 print "Macros with multiple statements should be enclosed in a do - while loop\n"; 931 ERROR("Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n");
885 } else { 932 } else {
886 print "Macros with complex values should be enclosed in parenthesis\n"; 933 ERROR("Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n");
934 }
935 }
936 }
937
938# check for redundant bracing round if etc
939 if ($line =~ /\b(if|while|for|else)\b/) {
940 # Locate the end of the opening statement.
941 my @control = ctx_statement($linenr, $realcnt, 0);
942 my $nr = $linenr + (scalar(@control) - 1);
943 my $cnt = $realcnt - (scalar(@control) - 1);
944
945 my $off = $realcnt - $cnt;
946 #print "$off: line<$line>end<" . $lines[$nr - 1] . ">\n";
947
948 # If this is is a braced statement group check it
949 if ($lines[$nr - 1] =~ /{\s*$/) {
950 my ($lvl, @block) = ctx_block_level($nr, $cnt);
951
952 my $stmt = join(' ', @block);
953 $stmt =~ s/^[^{]*{//;
954 $stmt =~ s/}[^}]*$//;
955
956 #print "block<" . join(' ', @block) . "><" . scalar(@block) . ">\n";
957 #print "stmt<$stmt>\n\n";
958
959 # Count the ;'s if there is fewer than two
960 # then there can only be one statement,
961 # if there is a brace inside we cannot
962 # trivially detect if its one statement.
963 # Also nested if's often require braces to
964 # disambiguate the else binding so shhh there.
965 my @semi = ($stmt =~ /;/g);
966 ##print "semi<" . scalar(@semi) . ">\n";
967 if ($lvl == 0 && scalar(@semi) < 2 &&
968 $stmt !~ /{/ && $stmt !~ /\bif\b/) {
969 my $herectx = "$here\n" . join("\n", @control, @block[1 .. $#block]) . "\n";
970 shift(@block);
971 ERROR("braces {} are not necessary for single statement blocks\n" . $herectx);
887 } 972 }
888 print "$hereprev";
889 $clean = 0;
890 } 973 }
891 } 974 }
892 975
893# don't include deprecated include files (uses RAW line) 976# don't include deprecated include files (uses RAW line)
894 for my $inc (@dep_includes) { 977 for my $inc (@dep_includes) {
895 if ($rawline =~ m@\#\s*include\s*\<$inc>@) { 978 if ($rawline =~ m@\#\s*include\s*\<$inc>@) {
896 print "Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n"; 979 ERROR("Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr);
897 print "$herecurr";
898 $clean = 0;
899 } 980 }
900 } 981 }
901 982
902# don't use deprecated functions 983# don't use deprecated functions
903 for my $func (@dep_functions) { 984 for my $func (@dep_functions) {
904 if ($line =~ /\b$func\b/) { 985 if ($line =~ /\b$func\b/) {
905 print "Don't use $func(): see Documentation/feature-removal-schedule.txt\n"; 986 ERROR("Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr);
906 print "$herecurr";
907 $clean = 0;
908 } 987 }
909 } 988 }
910 989
911# no volatiles please 990# no volatiles please
912 if ($line =~ /\bvolatile\b/ && $line !~ /\basm\s+volatile\b/) { 991 if ($line =~ /\bvolatile\b/ && $line !~ /\basm\s+volatile\b/) {
913 print "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n"; 992 WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
914 print "$herecurr";
915 $clean = 0;
916 } 993 }
917 994
918# warn about #if 0 995# warn about #if 0
919 if ($line =~ /^.#\s*if\s+0\b/) { 996 if ($line =~ /^.#\s*if\s+0\b/) {
920 print "#if 0 -- if this code redundant remove it\n"; 997 CHK("if this code is redundant consider removing it\n" .
921 print "$herecurr"; 998 $herecurr);
922 $clean = 0; 999 }
1000
1001# check for needless kfree() checks
1002 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
1003 my $expr = $1;
1004 if ($line =~ /\bkfree\(\Q$expr\E\);/) {
1005 WARN("kfree(NULL) is safe this check is probabally not required\n" . $hereprev);
1006 }
923 } 1007 }
924 1008
925# warn about #ifdefs in C files 1009# warn about #ifdefs in C files
@@ -933,43 +1017,52 @@ sub process {
933 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) { 1017 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) {
934 my $which = $1; 1018 my $which = $1;
935 if (!ctx_has_comment($first_line, $linenr)) { 1019 if (!ctx_has_comment($first_line, $linenr)) {
936 print "$1 definition without comment\n"; 1020 CHK("$1 definition without comment\n" . $herecurr);
937 print "$herecurr";
938 $clean = 0;
939 } 1021 }
940 } 1022 }
941# check for memory barriers without a comment. 1023# check for memory barriers without a comment.
942 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { 1024 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
943 if (!ctx_has_comment($first_line, $linenr)) { 1025 if (!ctx_has_comment($first_line, $linenr)) {
944 print "memory barrier without comment\n"; 1026 CHK("memory barrier without comment\n" . $herecurr);
945 print "$herecurr";
946 $clean = 0;
947 } 1027 }
948 } 1028 }
949# check of hardware specific defines 1029# check of hardware specific defines
950 if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@) { 1030 if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@) {
951 print "architecture specific defines should be avoided\n"; 1031 CHK("architecture specific defines should be avoided\n" . $herecurr);
952 print "$herecurr";
953 $clean = 0;
954 } 1032 }
955 1033
1034# check the location of the inline attribute, that it is between
1035# storage class and type.
956 if ($line =~ /$Type\s+(?:inline|__always_inline)\b/ || 1036 if ($line =~ /$Type\s+(?:inline|__always_inline)\b/ ||
957 $line =~ /\b(?:inline|always_inline)\s+$Storage/) { 1037 $line =~ /\b(?:inline|always_inline)\s+$Storage/) {
958 print "inline keyword should sit between storage class and type\n"; 1038 ERROR("inline keyword should sit between storage class and type\n" . $herecurr);
959 print "$herecurr"; 1039 }
960 $clean = 0; 1040
1041# check for new externs in .c files.
1042 if ($line =~ /^.\s*extern\s/ && ($realfile =~ /\.c$/)) {
1043 WARN("externs should be avoided in .c files\n" . $herecurr);
1044 }
1045
1046# checks for new __setup's
1047 if ($rawline =~ /\b__setup\("([^"]*)"/) {
1048 my $name = $1;
1049
1050 if (!grep(/$name/, @setup_docs)) {
1051 CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
1052 }
961 } 1053 }
962 } 1054 }
963 1055
964 if ($chk_patch && !$is_patch) { 1056 if ($chk_patch && !$is_patch) {
965 $clean = 0; 1057 ERROR("Does not appear to be a unified-diff format patch\n");
966 print "Does not appear to be a unified-diff format patch\n";
967 } 1058 }
968 if ($is_patch && $chk_signoff && $signoff == 0) { 1059 if ($is_patch && $chk_signoff && $signoff == 0) {
969 $clean = 0; 1060 ERROR("Missing Signed-off-by: line(s)\n");
970 print "Missing Signed-off-by: line(s)\n";
971 } 1061 }
972 1062
1063 if ($clean == 0 && ($chk_patch || $is_patch)) {
1064 print report_dump();
1065 }
973 if ($clean == 1 && $quiet == 0) { 1066 if ($clean == 1 && $quiet == 0) {
974 print "Your patch has no obvious style problems and is ready for submission.\n" 1067 print "Your patch has no obvious style problems and is ready for submission.\n"
975 } 1068 }
diff --git a/scripts/decodecode b/scripts/decodecode
new file mode 100644
index 000000000000..1e1a8f620c47
--- /dev/null
+++ b/scripts/decodecode
@@ -0,0 +1,51 @@
1#!/bin/sh
2# Disassemble the Code: line in Linux oopses
3# usage: decodecode < oops.file
4#
5# options: set env. variable AFLAGS=options to pass options to "as";
6# e.g., to decode an i386 oops on an x86_64 system, use:
7# AFLAGS=--32 decodecode < 386.oops
8
9T=`mktemp`
10code=
11
12while read i ; do
13
14case "$i" in
15*Code:*)
16 code=$i
17 ;;
18esac
19
20done
21
22if [ -z "$code" ]; then
23 exit
24fi
25
26echo $code
27code=`echo $code | sed -e 's/.*Code: //'`
28
29marker=`expr index "$code" "\<"`
30if [ $marker -eq 0 ]; then
31 marker=`expr index "$code" "\("`
32fi
33
34if [ $marker -ne 0 ]; then
35 beforemark=`echo "$code" | cut -c-$((${marker} - 1))`
36 echo -n " .byte 0x" > $T.s
37 echo $beforemark | sed -e 's/ /,0x/g' >> $T.s
38 as $AFLAGS -o $T.o $T.s
39 objdump -S $T.o
40 rm $T.o $T.s
41
42# and fix code at-and-after marker
43 code=`echo "$code" | cut -c$((${marker} + 1))-`
44fi
45
46code=`echo $code | sed -e 's/ [<(]/ /;s/[>)] / /;s/ /,0x/g'`
47echo -n " .byte 0x" > $T.s
48echo $code >> $T.s
49as $AFLAGS -o $T.o $T.s
50objdump -S $T.o
51rm $T.o $T.s
diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c
index 8b809b264d18..10b006694e5d 100644
--- a/scripts/kallsyms.c
+++ b/scripts/kallsyms.c
@@ -31,7 +31,7 @@
31#include <string.h> 31#include <string.h>
32#include <ctype.h> 32#include <ctype.h>
33 33
34#define KSYM_NAME_LEN 127 34#define KSYM_NAME_LEN 128
35 35
36 36
37struct sym_entry { 37struct sym_entry {
@@ -254,7 +254,7 @@ static void write_src(void)
254 unsigned int i, k, off; 254 unsigned int i, k, off;
255 unsigned int best_idx[256]; 255 unsigned int best_idx[256];
256 unsigned int *markers; 256 unsigned int *markers;
257 char buf[KSYM_NAME_LEN+1]; 257 char buf[KSYM_NAME_LEN];
258 258
259 printf("#include <asm/types.h>\n"); 259 printf("#include <asm/types.h>\n");
260 printf("#if BITS_PER_LONG == 64\n"); 260 printf("#if BITS_PER_LONG == 64\n");
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index e5bf649e516a..1f5835115cad 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -154,6 +154,7 @@ use strict;
154 154
155my $errors = 0; 155my $errors = 0;
156my $warnings = 0; 156my $warnings = 0;
157my $anon_struct_union = 0;
157 158
158# match expressions used to find embedded type information 159# match expressions used to find embedded type information
159my $type_constant = '\%([-_\w]+)'; 160my $type_constant = '\%([-_\w]+)';
@@ -403,7 +404,11 @@ sub output_highlight {
403 print $lineprefix, $blankline; 404 print $lineprefix, $blankline;
404 } else { 405 } else {
405 $line =~ s/\\\\\\/\&/g; 406 $line =~ s/\\\\\\/\&/g;
406 print $lineprefix, $line; 407 if ($output_mode eq "man" && substr($line, 0, 1) eq ".") {
408 print "\\&$line";
409 } else {
410 print $lineprefix, $line;
411 }
407 } 412 }
408 print "\n"; 413 print "\n";
409 } 414 }
@@ -718,6 +723,7 @@ sub output_struct_xml(%) {
718 # pointer-to-function 723 # pointer-to-function
719 print " $1 $parameter) ($2);\n"; 724 print " $1 $parameter) ($2);\n";
720 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 725 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
726 # bitfield
721 print " $1 $parameter$2;\n"; 727 print " $1 $parameter$2;\n";
722 } else { 728 } else {
723 print " ".$type." ".$parameter.";\n"; 729 print " ".$type." ".$parameter.";\n";
@@ -1260,6 +1266,7 @@ sub output_struct_text(%) {
1260 # pointer-to-function 1266 # pointer-to-function
1261 print "\t$1 $parameter) ($2);\n"; 1267 print "\t$1 $parameter) ($2);\n";
1262 } elsif ($type =~ m/^(.*?)\s*(:.*)/) { 1268 } elsif ($type =~ m/^(.*?)\s*(:.*)/) {
1269 # bitfield
1263 print "\t$1 $parameter$2;\n"; 1270 print "\t$1 $parameter$2;\n";
1264 } else { 1271 } else {
1265 print "\t".$type." ".$parameter.";\n"; 1272 print "\t".$type." ".$parameter.";\n";
@@ -1510,8 +1517,13 @@ sub push_parameter($$$) {
1510 my $param = shift; 1517 my $param = shift;
1511 my $type = shift; 1518 my $type = shift;
1512 my $file = shift; 1519 my $file = shift;
1513 my $anon = 0;
1514 1520
1521 if (($anon_struct_union == 1) && ($type eq "") &&
1522 ($param eq "}")) {
1523 return; # ignore the ending }; from anon. struct/union
1524 }
1525
1526 $anon_struct_union = 0;
1515 my $param_name = $param; 1527 my $param_name = $param;
1516 $param_name =~ s/\[.*//; 1528 $param_name =~ s/\[.*//;
1517 1529
@@ -1530,16 +1542,16 @@ sub push_parameter($$$) {
1530 # handle unnamed (anonymous) union or struct: 1542 # handle unnamed (anonymous) union or struct:
1531 { 1543 {
1532 $type = $param; 1544 $type = $param;
1533 $param = "{unnamed_" . $param. "}"; 1545 $param = "{unnamed_" . $param . "}";
1534 $parameterdescs{$param} = "anonymous\n"; 1546 $parameterdescs{$param} = "anonymous\n";
1535 $anon = 1; 1547 $anon_struct_union = 1;
1536 } 1548 }
1537 1549
1538 # warn if parameter has no description 1550 # warn if parameter has no description
1539 # (but ignore ones starting with # as these are not parameters 1551 # (but ignore ones starting with # as these are not parameters
1540 # but inline preprocessor statements); 1552 # but inline preprocessor statements);
1541 # also ignore unnamed structs/unions; 1553 # also ignore unnamed structs/unions;
1542 if (!$anon) { 1554 if (!$anon_struct_union) {
1543 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) { 1555 if (!defined $parameterdescs{$param_name} && $param_name !~ /^#/) {
1544 1556
1545 $parameterdescs{$param_name} = $undescribed; 1557 $parameterdescs{$param_name} = $undescribed;
@@ -1691,6 +1703,8 @@ sub process_state3_function($$) {
1691 my $x = shift; 1703 my $x = shift;
1692 my $file = shift; 1704 my $file = shift;
1693 1705
1706 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1707
1694 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) { 1708 if ($x =~ m#\s*/\*\s+MACDOC\s*#io || ($x =~ /^#/ && $x !~ /^#define/)) {
1695 # do nothing 1709 # do nothing
1696 } 1710 }
@@ -1713,6 +1727,8 @@ sub process_state3_type($$) {
1713 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's. 1727 $x =~ s@[\r\n]+@ @gos; # strip newlines/cr's.
1714 $x =~ s@^\s+@@gos; # strip leading spaces 1728 $x =~ s@^\s+@@gos; # strip leading spaces
1715 $x =~ s@\s+$@@gos; # strip trailing spaces 1729 $x =~ s@\s+$@@gos; # strip trailing spaces
1730 $x =~ s@\/\/.*$@@gos; # strip C99-style comments to end of line
1731
1716 if ($x =~ /^#/) { 1732 if ($x =~ /^#/) {
1717 # To distinguish preprocessor directive from regular declaration later. 1733 # To distinguish preprocessor directive from regular declaration later.
1718 $x .= ";"; 1734 $x .= ";";
@@ -1796,7 +1812,7 @@ sub process_file($) {
1796 1812
1797 $state = 2; 1813 $state = 2;
1798 if (/-(.*)/) { 1814 if (/-(.*)/) {
1799 # strip leading/trailing/multiple spaces #RDD:T: 1815 # strip leading/trailing/multiple spaces
1800 $descr= $1; 1816 $descr= $1;
1801 $descr =~ s/^\s*//; 1817 $descr =~ s/^\s*//;
1802 $descr =~ s/\s*$//; 1818 $descr =~ s/\s*$//;