aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/Makefile.modpost6
-rwxr-xr-xscripts/checkpatch.pl750
-rwxr-xr-xscripts/kernel-doc4
-rw-r--r--scripts/mod/file2alias.c61
-rw-r--r--scripts/mod/modpost.c5
-rw-r--r--scripts/mod/modpost.h1
6 files changed, 529 insertions, 298 deletions
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index cfc004e04417..2d20640854b7 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -58,6 +58,9 @@ modules := $(patsubst %.o,%.ko, $(wildcard $(__modules:.ko=.o)))
58# Stop after building .o files if NOFINAL is set. Makes compile tests quicker 58# Stop after building .o files if NOFINAL is set. Makes compile tests quicker
59_modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules)) 59_modpost: $(if $(KBUILD_MODPOST_NOFINAL), $(modules:.ko:.o),$(modules))
60 60
61ifneq ($(KBUILD_BUILDHOST),$(ARCH))
62 cross_build := 1
63endif
61 64
62# Step 2), invoke modpost 65# Step 2), invoke modpost
63# Includes step 3,4 66# Includes step 3,4
@@ -70,7 +73,8 @@ modpost = scripts/mod/modpost \
70 $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \ 73 $(if $(CONFIG_DEBUG_SECTION_MISMATCH),,-S) \
71 $(if $(CONFIG_MARKERS),-K $(kernelmarkersfile)) \ 74 $(if $(CONFIG_MARKERS),-K $(kernelmarkersfile)) \
72 $(if $(CONFIG_MARKERS),-M $(markersfile)) \ 75 $(if $(CONFIG_MARKERS),-M $(markersfile)) \
73 $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) 76 $(if $(KBUILD_EXTMOD)$(KBUILD_MODPOST_WARN),-w) \
77 $(if $(cross_build),-c)
74 78
75quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules 79quiet_cmd_modpost = MODPOST $(words $(filter-out vmlinux FORCE, $^)) modules
76 cmd_modpost = $(modpost) -s 80 cmd_modpost = $(modpost) -s
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2086a856400a..58a94947d655 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.14'; 12my $V = '0.16';
13 13
14use Getopt::Long qw(:config no_auto_abbrev); 14use Getopt::Long qw(:config no_auto_abbrev);
15 15
@@ -18,6 +18,7 @@ my $tree = 1;
18my $chk_signoff = 1; 18my $chk_signoff = 1;
19my $chk_patch = 1; 19my $chk_patch = 1;
20my $tst_type = 0; 20my $tst_type = 0;
21my $tst_only;
21my $emacs = 0; 22my $emacs = 0;
22my $terse = 0; 23my $terse = 0;
23my $file = 0; 24my $file = 0;
@@ -44,6 +45,7 @@ GetOptions(
44 45
45 'debug=s' => \%debug, 46 'debug=s' => \%debug,
46 'test-type!' => \$tst_type, 47 'test-type!' => \$tst_type,
48 'test-only=s' => \$tst_only,
47) or exit; 49) or exit;
48 50
49my $exit = 0; 51my $exit = 0;
@@ -105,8 +107,7 @@ our $Sparse = qr{
105 __iomem| 107 __iomem|
106 __must_check| 108 __must_check|
107 __init_refok| 109 __init_refok|
108 __kprobes| 110 __kprobes
109 fastcall
110 }x; 111 }x;
111our $Attribute = qr{ 112our $Attribute = qr{
112 const| 113 const|
@@ -158,7 +159,10 @@ sub build_types {
158 \b 159 \b
159 (?:const\s+)? 160 (?:const\s+)?
160 (?:unsigned\s+)? 161 (?:unsigned\s+)?
161 $all 162 (?:
163 $all|
164 (?:typeof|__typeof__)\s*\(\s*\**\s*$Ident\s*\)
165 )
162 (?:\s+$Sparse|\s+const)* 166 (?:\s+$Sparse|\s+const)*
163 \b 167 \b
164 }x; 168 }x;
@@ -261,17 +265,7 @@ sub expand_tabs {
261 return $res; 265 return $res;
262} 266}
263sub copy_spacing { 267sub copy_spacing {
264 my ($str) = @_; 268 (my $res = shift) =~ tr/\t/ /c;
265
266 my $res = '';
267 for my $c (split(//, $str)) {
268 if ($c eq "\t") {
269 $res .= $c;
270 } else {
271 $res .= ' ';
272 }
273 }
274
275 return $res; 269 return $res;
276} 270}
277 271
@@ -288,53 +282,76 @@ sub line_stats {
288 return (length($line), length($white)); 282 return (length($line), length($white));
289} 283}
290 284
285my $sanitise_quote = '';
286
287sub sanitise_line_reset {
288 my ($in_comment) = @_;
289
290 if ($in_comment) {
291 $sanitise_quote = '*/';
292 } else {
293 $sanitise_quote = '';
294 }
295}
291sub sanitise_line { 296sub sanitise_line {
292 my ($line) = @_; 297 my ($line) = @_;
293 298
294 my $res = ''; 299 my $res = '';
295 my $l = ''; 300 my $l = '';
296 301
297 my $quote = '';
298 my $qlen = 0; 302 my $qlen = 0;
303 my $off = 0;
304 my $c;
299 305
300 foreach my $c (split(//, $line)) { 306 # Always copy over the diff marker.
301 # The second backslash of a pair is not a "quote". 307 $res = substr($line, 0, 1);
302 if ($l eq "\\" && $c eq "\\") { 308
303 $c = 'X'; 309 for ($off = 1; $off < length($line); $off++) {
304 } 310 $c = substr($line, $off, 1);
305 if ($l ne "\\" && ($c eq "'" || $c eq '"')) { 311
306 if ($quote eq '') { 312 # Comments we are wacking completly including the begin
307 $quote = $c; 313 # and end, all to $;.
308 $res .= $c; 314 if ($sanitise_quote eq '' && substr($line, $off, 2) eq '/*') {
309 $l = $c; 315 $sanitise_quote = '*/';
310 $qlen = 0; 316
311 next; 317 substr($res, $off, 2, "$;$;");
312 } elsif ($quote eq $c) { 318 $off++;
313 $quote = ''; 319 next;
314 }
315 } 320 }
316 if ($quote eq "'" && $qlen > 1) { 321 if (substr($line, $off, 2) eq $sanitise_quote) {
317 $quote = ''; 322 $sanitise_quote = '';
323 substr($res, $off, 2, "$;$;");
324 $off++;
325 next;
318 } 326 }
319 if ($quote && $c ne "\t") { 327
320 $res .= "X"; 328 # A \ in a string means ignore the next character.
321 $qlen++; 329 if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&
322 } else { 330 $c eq "\\") {
323 $res .= $c; 331 substr($res, $off, 2, 'XX');
332 $off++;
333 next;
324 } 334 }
335 # Regular quotes.
336 if ($c eq "'" || $c eq '"') {
337 if ($sanitise_quote eq '') {
338 $sanitise_quote = $c;
325 339
326 $l = $c; 340 substr($res, $off, 1, $c);
327 } 341 next;
342 } elsif ($sanitise_quote eq $c) {
343 $sanitise_quote = '';
344 }
345 }
328 346
329 # Clear out the comments. 347 #print "SQ:$sanitise_quote\n";
330 while ($res =~ m@(/\*.*?\*/)@g) { 348 if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {
331 substr($res, $-[1], $+[1] - $-[1]) = $; x ($+[1] - $-[1]); 349 substr($res, $off, 1, $;);
332 } 350 } elsif ($off != 0 && $sanitise_quote && $c ne "\t") {
333 if ($res =~ m@(/\*.*)@) { 351 substr($res, $off, 1, 'X');
334 substr($res, $-[1], $+[1] - $-[1]) = $; x ($+[1] - $-[1]); 352 } else {
335 } 353 substr($res, $off, 1, $c);
336 if ($res =~ m@^.(.*\*/)@) { 354 }
337 substr($res, $-[1], $+[1] - $-[1]) = $; x ($+[1] - $-[1]);
338 } 355 }
339 356
340 # The pathname on a #include may be surrounded by '<' and '>'. 357 # The pathname on a #include may be surrounded by '<' and '>'.
@@ -357,17 +374,19 @@ sub ctx_statement_block {
357 my $blk = ''; 374 my $blk = '';
358 my $soff = $off; 375 my $soff = $off;
359 my $coff = $off - 1; 376 my $coff = $off - 1;
377 my $coff_set = 0;
360 378
361 my $loff = 0; 379 my $loff = 0;
362 380
363 my $type = ''; 381 my $type = '';
364 my $level = 0; 382 my $level = 0;
383 my $p;
365 my $c; 384 my $c;
366 my $len = 0; 385 my $len = 0;
367 386
368 my $remainder; 387 my $remainder;
369 while (1) { 388 while (1) {
370 #warn "CSB: blk<$blk>\n"; 389 #warn "CSB: blk<$blk> remain<$remain>\n";
371 # If we are about to drop off the end, pull in more 390 # If we are about to drop off the end, pull in more
372 # context. 391 # context.
373 if ($off >= $len) { 392 if ($off >= $len) {
@@ -386,10 +405,11 @@ sub ctx_statement_block {
386 last; 405 last;
387 } 406 }
388 } 407 }
408 $p = $c;
389 $c = substr($blk, $off, 1); 409 $c = substr($blk, $off, 1);
390 $remainder = substr($blk, $off); 410 $remainder = substr($blk, $off);
391 411
392 #warn "CSB: c<$c> type<$type> level<$level>\n"; 412 #warn "CSB: c<$c> type<$type> level<$level> remainder<$remainder> coff_set<$coff_set>\n";
393 # Statement ends at the ';' or a close '}' at the 413 # Statement ends at the ';' or a close '}' at the
394 # outermost level. 414 # outermost level.
395 if ($level == 0 && $c eq ';') { 415 if ($level == 0 && $c eq ';') {
@@ -397,9 +417,14 @@ sub ctx_statement_block {
397 } 417 }
398 418
399 # An else is really a conditional as long as its not else if 419 # An else is really a conditional as long as its not else if
400 if ($level == 0 && $remainder =~ /(\s+else)(?:\s|{)/ && 420 if ($level == 0 && $coff_set == 0 &&
401 $remainder !~ /\s+else\s+if\b/) { 421 (!defined($p) || $p =~ /(?:\s|\}|\+)/) &&
402 $coff = $off + length($1); 422 $remainder =~ /^(else)(?:\s|{)/ &&
423 $remainder !~ /^else\s+if\b/) {
424 $coff = $off + length($1) - 1;
425 $coff_set = 1;
426 #warn "CSB: mark coff<$coff> soff<$soff> 1<$1>\n";
427 #warn "[" . substr($blk, $soff, $coff - $soff + 1) . "]\n";
403 } 428 }
404 429
405 if (($type eq '' || $type eq '(') && $c eq '(') { 430 if (($type eq '' || $type eq '(') && $c eq '(') {
@@ -412,6 +437,8 @@ sub ctx_statement_block {
412 437
413 if ($level == 0 && $coff < $soff) { 438 if ($level == 0 && $coff < $soff) {
414 $coff = $off; 439 $coff = $off;
440 $coff_set = 1;
441 #warn "CSB: mark coff<$coff>\n";
415 } 442 }
416 } 443 }
417 if (($type eq '' || $type eq '{') && $c eq '{') { 444 if (($type eq '' || $type eq '{') && $c eq '{') {
@@ -439,27 +466,79 @@ sub ctx_statement_block {
439 #warn "STATEMENT<$statement>\n"; 466 #warn "STATEMENT<$statement>\n";
440 #warn "CONDITION<$condition>\n"; 467 #warn "CONDITION<$condition>\n";
441 468
442 #print "off<$off> loff<$loff>\n"; 469 #print "coff<$coff> soff<$off> loff<$loff>\n";
443 470
444 return ($statement, $condition, 471 return ($statement, $condition,
445 $line, $remain + 1, $off - $loff + 1, $level); 472 $line, $remain + 1, $off - $loff + 1, $level);
446} 473}
447 474
475sub statement_lines {
476 my ($stmt) = @_;
477
478 # Strip the diff line prefixes and rip blank lines at start and end.
479 $stmt =~ s/(^|\n)./$1/g;
480 $stmt =~ s/^\s*//;
481 $stmt =~ s/\s*$//;
482
483 my @stmt_lines = ($stmt =~ /\n/g);
484
485 return $#stmt_lines + 2;
486}
487
488sub statement_rawlines {
489 my ($stmt) = @_;
490
491 my @stmt_lines = ($stmt =~ /\n/g);
492
493 return $#stmt_lines + 2;
494}
495
496sub statement_block_size {
497 my ($stmt) = @_;
498
499 $stmt =~ s/(^|\n)./$1/g;
500 $stmt =~ s/^\s*{//;
501 $stmt =~ s/}\s*$//;
502 $stmt =~ s/^\s*//;
503 $stmt =~ s/\s*$//;
504
505 my @stmt_lines = ($stmt =~ /\n/g);
506 my @stmt_statements = ($stmt =~ /;/g);
507
508 my $stmt_lines = $#stmt_lines + 2;
509 my $stmt_statements = $#stmt_statements + 1;
510
511 if ($stmt_lines > $stmt_statements) {
512 return $stmt_lines;
513 } else {
514 return $stmt_statements;
515 }
516}
517
448sub ctx_statement_full { 518sub ctx_statement_full {
449 my ($linenr, $remain, $off) = @_; 519 my ($linenr, $remain, $off) = @_;
450 my ($statement, $condition, $level); 520 my ($statement, $condition, $level);
451 521
452 my (@chunks); 522 my (@chunks);
453 523
524 # Grab the first conditional/block pair.
454 ($statement, $condition, $linenr, $remain, $off, $level) = 525 ($statement, $condition, $linenr, $remain, $off, $level) =
455 ctx_statement_block($linenr, $remain, $off); 526 ctx_statement_block($linenr, $remain, $off);
456 #print "F: c<$condition> s<$statement>\n"; 527 #print "F: c<$condition> s<$statement> remain<$remain>\n";
528 push(@chunks, [ $condition, $statement ]);
529 if (!($remain > 0 && $condition =~ /^\s*(?:\n[+-])?\s*(?:if|else|do)\b/s)) {
530 return ($level, $linenr, @chunks);
531 }
532
533 # Pull in the following conditional/block pairs and see if they
534 # could continue the statement.
457 for (;;) { 535 for (;;) {
458 push(@chunks, [ $condition, $statement ]);
459 last if (!($remain > 0 && $condition =~ /^.\s*(?:if|else|do)/));
460 ($statement, $condition, $linenr, $remain, $off, $level) = 536 ($statement, $condition, $linenr, $remain, $off, $level) =
461 ctx_statement_block($linenr, $remain, $off); 537 ctx_statement_block($linenr, $remain, $off);
462 #print "C: c<$condition> s<$statement>\n"; 538 #print "C: c<$condition> s<$statement> remain<$remain>\n";
539 last if (!($remain > 0 && $condition =~ /^(?:\s*\n[+-])*\s*(?:else|do)\b/s));
540 #print "C: push\n";
541 push(@chunks, [ $condition, $statement ]);
463 } 542 }
464 543
465 return ($level, $linenr, @chunks); 544 return ($level, $linenr, @chunks);
@@ -593,13 +672,13 @@ sub cat_vet {
593} 672}
594 673
595my $av_preprocessor = 0; 674my $av_preprocessor = 0;
596my $av_paren = 0; 675my $av_pending;
597my @av_paren_type; 676my @av_paren_type;
598 677
599sub annotate_reset { 678sub annotate_reset {
600 $av_preprocessor = 0; 679 $av_preprocessor = 0;
601 $av_paren = 0; 680 $av_pending = '_';
602 @av_paren_type = (); 681 @av_paren_type = ('E');
603} 682}
604 683
605sub annotate_values { 684sub annotate_values {
@@ -611,12 +690,14 @@ sub annotate_values {
611 print "$stream\n" if ($dbg_values > 1); 690 print "$stream\n" if ($dbg_values > 1);
612 691
613 while (length($cur)) { 692 while (length($cur)) {
614 print " <$type> " if ($dbg_values > 1); 693 @av_paren_type = ('E') if ($#av_paren_type < 0);
694 print " <" . join('', @av_paren_type) .
695 "> <$type> " if ($dbg_values > 1);
615 if ($cur =~ /^(\s+)/o) { 696 if ($cur =~ /^(\s+)/o) {
616 print "WS($1)\n" if ($dbg_values > 1); 697 print "WS($1)\n" if ($dbg_values > 1);
617 if ($1 =~ /\n/ && $av_preprocessor) { 698 if ($1 =~ /\n/ && $av_preprocessor) {
699 $type = pop(@av_paren_type);
618 $av_preprocessor = 0; 700 $av_preprocessor = 0;
619 $type = 'N';
620 } 701 }
621 702
622 } elsif ($cur =~ /^($Type)/) { 703 } elsif ($cur =~ /^($Type)/) {
@@ -626,11 +707,33 @@ sub annotate_values {
626 } elsif ($cur =~ /^(#\s*define\s*$Ident)(\(?)/o) { 707 } elsif ($cur =~ /^(#\s*define\s*$Ident)(\(?)/o) {
627 print "DEFINE($1)\n" if ($dbg_values > 1); 708 print "DEFINE($1)\n" if ($dbg_values > 1);
628 $av_preprocessor = 1; 709 $av_preprocessor = 1;
629 $av_paren_type[$av_paren] = 'N'; 710 $av_pending = 'N';
630 711
631 } elsif ($cur =~ /^(#\s*(?:ifdef|ifndef|if|else|elif|endif))/o) { 712 } elsif ($cur =~ /^(#\s*(?:ifdef|ifndef|if))/o) {
632 print "PRE($1)\n" if ($dbg_values > 1); 713 print "PRE_START($1)\n" if ($dbg_values > 1);
633 $av_preprocessor = 1; 714 $av_preprocessor = 1;
715
716 push(@av_paren_type, $type);
717 push(@av_paren_type, $type);
718 $type = 'N';
719
720 } elsif ($cur =~ /^(#\s*(?:else|elif))/o) {
721 print "PRE_RESTART($1)\n" if ($dbg_values > 1);
722 $av_preprocessor = 1;
723
724 push(@av_paren_type, $av_paren_type[$#av_paren_type]);
725
726 $type = 'N';
727
728 } elsif ($cur =~ /^(#\s*(?:endif))/o) {
729 print "PRE_END($1)\n" if ($dbg_values > 1);
730
731 $av_preprocessor = 1;
732
733 # Assume all arms of the conditional end as this
734 # one does, and continue as if the #endif was not here.
735 pop(@av_paren_type);
736 push(@av_paren_type, $type);
634 $type = 'N'; 737 $type = 'N';
635 738
636 } elsif ($cur =~ /^(\\\n)/o) { 739 } elsif ($cur =~ /^(\\\n)/o) {
@@ -639,13 +742,13 @@ sub annotate_values {
639 } elsif ($cur =~ /^(sizeof)\s*(\()?/o) { 742 } elsif ($cur =~ /^(sizeof)\s*(\()?/o) {
640 print "SIZEOF($1)\n" if ($dbg_values > 1); 743 print "SIZEOF($1)\n" if ($dbg_values > 1);
641 if (defined $2) { 744 if (defined $2) {
642 $av_paren_type[$av_paren] = 'V'; 745 $av_pending = 'V';
643 } 746 }
644 $type = 'N'; 747 $type = 'N';
645 748
646 } elsif ($cur =~ /^(if|while|typeof|__typeof__|for)\b/o) { 749 } elsif ($cur =~ /^(if|while|typeof|__typeof__|for)\b/o) {
647 print "COND($1)\n" if ($dbg_values > 1); 750 print "COND($1)\n" if ($dbg_values > 1);
648 $av_paren_type[$av_paren] = 'N'; 751 $av_pending = 'N';
649 $type = 'N'; 752 $type = 'N';
650 753
651 } elsif ($cur =~/^(return|case|else)/o) { 754 } elsif ($cur =~/^(return|case|else)/o) {
@@ -654,14 +757,14 @@ sub annotate_values {
654 757
655 } elsif ($cur =~ /^(\()/o) { 758 } elsif ($cur =~ /^(\()/o) {
656 print "PAREN('$1')\n" if ($dbg_values > 1); 759 print "PAREN('$1')\n" if ($dbg_values > 1);
657 $av_paren++; 760 push(@av_paren_type, $av_pending);
761 $av_pending = '_';
658 $type = 'N'; 762 $type = 'N';
659 763
660 } elsif ($cur =~ /^(\))/o) { 764 } elsif ($cur =~ /^(\))/o) {
661 $av_paren-- if ($av_paren > 0); 765 my $new_type = pop(@av_paren_type);
662 if (defined $av_paren_type[$av_paren]) { 766 if ($new_type ne '_') {
663 $type = $av_paren_type[$av_paren]; 767 $type = $new_type;
664 undef $av_paren_type[$av_paren];
665 print "PAREN('$1') -> $type\n" 768 print "PAREN('$1') -> $type\n"
666 if ($dbg_values > 1); 769 if ($dbg_values > 1);
667 } else { 770 } else {
@@ -670,7 +773,7 @@ sub annotate_values {
670 773
671 } elsif ($cur =~ /^($Ident)\(/o) { 774 } elsif ($cur =~ /^($Ident)\(/o) {
672 print "FUNC($1)\n" if ($dbg_values > 1); 775 print "FUNC($1)\n" if ($dbg_values > 1);
673 $av_paren_type[$av_paren] = 'V'; 776 $av_pending = 'V';
674 777
675 } elsif ($cur =~ /^($Ident|$Constant)/o) { 778 } elsif ($cur =~ /^($Ident|$Constant)/o) {
676 print "IDENT($1)\n" if ($dbg_values > 1); 779 print "IDENT($1)\n" if ($dbg_values > 1);
@@ -680,11 +783,11 @@ sub annotate_values {
680 print "ASSIGN($1)\n" if ($dbg_values > 1); 783 print "ASSIGN($1)\n" if ($dbg_values > 1);
681 $type = 'N'; 784 $type = 'N';
682 785
683 } elsif ($cur =~/^(;)/) { 786 } elsif ($cur =~/^(;|{|})/) {
684 print "END($1)\n" if ($dbg_values > 1); 787 print "END($1)\n" if ($dbg_values > 1);
685 $type = 'E'; 788 $type = 'E';
686 789
687 } elsif ($cur =~ /^(;|{|}|\?|:|\[)/o) { 790 } elsif ($cur =~ /^(;|\?|:|\[)/o) {
688 print "CLOSE($1)\n" if ($dbg_values > 1); 791 print "CLOSE($1)\n" if ($dbg_values > 1);
689 $type = 'N'; 792 $type = 'N';
690 793
@@ -724,28 +827,34 @@ sub possible {
724my $prefix = ''; 827my $prefix = '';
725 828
726sub report { 829sub report {
830 if (defined $tst_only && $_[0] !~ /\Q$tst_only\E/) {
831 return 0;
832 }
727 my $line = $prefix . $_[0]; 833 my $line = $prefix . $_[0];
728 834
729 $line = (split('\n', $line))[0] . "\n" if ($terse); 835 $line = (split('\n', $line))[0] . "\n" if ($terse);
730 836
731 push(our @report, $line); 837 push(our @report, $line);
838
839 return 1;
732} 840}
733sub report_dump { 841sub report_dump {
734 our @report; 842 our @report;
735} 843}
736sub ERROR { 844sub ERROR {
737 report("ERROR: $_[0]\n"); 845 if (report("ERROR: $_[0]\n")) {
738 our $clean = 0; 846 our $clean = 0;
739 our $cnt_error++; 847 our $cnt_error++;
848 }
740} 849}
741sub WARN { 850sub WARN {
742 report("WARNING: $_[0]\n"); 851 if (report("WARNING: $_[0]\n")) {
743 our $clean = 0; 852 our $clean = 0;
744 our $cnt_warn++; 853 our $cnt_warn++;
854 }
745} 855}
746sub CHK { 856sub CHK {
747 if ($check) { 857 if ($check && report("CHECK: $_[0]\n")) {
748 report("CHECK: $_[0]\n");
749 our $clean = 0; 858 our $clean = 0;
750 our $cnt_chk++; 859 our $cnt_chk++;
751 } 860 }
@@ -787,30 +896,76 @@ sub process {
787 my $prev_values = 'E'; 896 my $prev_values = 'E';
788 897
789 # suppression flags 898 # suppression flags
790 my $suppress_ifbraces = 0; 899 my %suppress_ifbraces;
791 900
792 # Pre-scan the patch sanitizing the lines. 901 # Pre-scan the patch sanitizing the lines.
793 # Pre-scan the patch looking for any __setup documentation. 902 # Pre-scan the patch looking for any __setup documentation.
794 # 903 #
795 my @setup_docs = (); 904 my @setup_docs = ();
796 my $setup_docs = 0; 905 my $setup_docs = 0;
906
907 sanitise_line_reset();
797 my $line; 908 my $line;
798 foreach my $rawline (@rawlines) { 909 foreach my $rawline (@rawlines) {
799 # Standardise the strings and chars within the input to 910 $linenr++;
800 # simplify matching. 911 $line = $rawline;
801 $line = sanitise_line($rawline);
802 push(@lines, $line);
803
804 ##print "==>$rawline\n";
805 ##print "-->$line\n";
806 912
807 if ($line=~/^\+\+\+\s+(\S+)/) { 913 if ($rawline=~/^\+\+\+\s+(\S+)/) {
808 $setup_docs = 0; 914 $setup_docs = 0;
809 if ($1 =~ m@Documentation/kernel-parameters.txt$@) { 915 if ($1 =~ m@Documentation/kernel-parameters.txt$@) {
810 $setup_docs = 1; 916 $setup_docs = 1;
811 } 917 }
812 next; 918 #next;
919 }
920 if ($rawline=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
921 $realline=$1-1;
922 if (defined $2) {
923 $realcnt=$3+1;
924 } else {
925 $realcnt=1+1;
926 }
927
928 # Guestimate if this is a continuing comment. Run
929 # the context looking for a comment "edge". If this
930 # edge is a close comment then we must be in a comment
931 # at context start.
932 my $edge;
933 for (my $ln = $linenr; $ln < ($linenr + $realcnt); $ln++) {
934 next if ($line =~ /^-/);
935 ($edge) = ($rawlines[$ln - 1] =~ m@(/\*|\*/)@);
936 last if (defined $edge);
937 }
938 if (defined $edge && $edge eq '*/') {
939 $in_comment = 1;
940 }
941
942 # Guestimate if this is a continuing comment. If this
943 # is the start of a diff block and this line starts
944 # ' *' then it is very likely a comment.
945 if (!defined $edge &&
946 $rawlines[$linenr] =~ m@^.\s* \*(?:\s|$)@)
947 {
948 $in_comment = 1;
949 }
950
951 ##print "COMMENT:$in_comment edge<$edge> $rawline\n";
952 sanitise_line_reset($in_comment);
953
954 } elsif ($realcnt) {
955 # Standardise the strings and chars within the input to
956 # simplify matching.
957 $line = sanitise_line($rawline);
813 } 958 }
959 push(@lines, $line);
960
961 if ($realcnt > 1) {
962 $realcnt-- if ($line =~ /^(?:\+| |$)/);
963 } else {
964 $realcnt = 0;
965 }
966
967 #print "==>$rawline\n";
968 #print "-->$line\n";
814 969
815 if ($setup_docs && $line =~ /^\+/) { 970 if ($setup_docs && $line =~ /^\+/) {
816 push(@setup_docs, $line); 971 push(@setup_docs, $line);
@@ -819,23 +974,17 @@ sub process {
819 974
820 $prefix = ''; 975 $prefix = '';
821 976
977 $realcnt = 0;
978 $linenr = 0;
822 foreach my $line (@lines) { 979 foreach my $line (@lines) {
823 $linenr++; 980 $linenr++;
824 981
825 my $rawline = $rawlines[$linenr - 1]; 982 my $rawline = $rawlines[$linenr - 1];
826 983
827#extract the filename as it passes
828 if ($line=~/^\+\+\+\s+(\S+)/) {
829 $realfile=$1;
830 $realfile =~ s@^[^/]*/@@;
831 $in_comment = 0;
832 next;
833 }
834#extract the line range in the file after the patch is applied 984#extract the line range in the file after the patch is applied
835 if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { 985 if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
836 $is_patch = 1; 986 $is_patch = 1;
837 $first_line = $linenr + 1; 987 $first_line = $linenr + 1;
838 $in_comment = 0;
839 $realline=$1-1; 988 $realline=$1-1;
840 if (defined $2) { 989 if (defined $2) {
841 $realcnt=$3+1; 990 $realcnt=$3+1;
@@ -845,50 +994,16 @@ sub process {
845 annotate_reset(); 994 annotate_reset();
846 $prev_values = 'E'; 995 $prev_values = 'E';
847 996
848 $suppress_ifbraces = $linenr - 1; 997 %suppress_ifbraces = ();
849 next; 998 next;
850 }
851 999
852# track the line number as we move through the hunk, note that 1000# track the line number as we move through the hunk, note that
853# new versions of GNU diff omit the leading space on completely 1001# new versions of GNU diff omit the leading space on completely
854# blank context lines so we need to count that too. 1002# blank context lines so we need to count that too.
855 if ($line =~ /^( |\+|$)/) { 1003 } elsif ($line =~ /^( |\+|$)/) {
856 $realline++; 1004 $realline++;
857 $realcnt-- if ($realcnt != 0); 1005 $realcnt-- if ($realcnt != 0);
858 1006
859 # Guestimate if this is a continuing comment. Run
860 # the context looking for a comment "edge". If this
861 # edge is a close comment then we must be in a comment
862 # at context start.
863 if ($linenr == $first_line) {
864 my $edge;
865 for (my $ln = $first_line; $ln < ($linenr + $realcnt); $ln++) {
866 ($edge) = ($rawlines[$ln - 1] =~ m@(/\*|\*/)@);
867 last if (defined $edge);
868 }
869 if (defined $edge && $edge eq '*/') {
870 $in_comment = 1;
871 }
872 }
873
874 # Guestimate if this is a continuing comment. If this
875 # is the start of a diff block and this line starts
876 # ' *' then it is very likely a comment.
877 if ($linenr == $first_line and $rawline =~ m@^.\s* \*(?:\s|$)@) {
878 $in_comment = 1;
879 }
880
881 # Find the last comment edge on _this_ line.
882 $comment_edge = 0;
883 while (($rawline =~ m@(/\*|\*/)@g)) {
884 if ($1 eq '/*') {
885 $in_comment = 1;
886 } else {
887 $in_comment = 0;
888 }
889 $comment_edge = 1;
890 }
891
892 # Measure the line length and indent. 1007 # Measure the line length and indent.
893 ($length, $indent) = line_stats($rawline); 1008 ($length, $indent) = line_stats($rawline);
894 1009
@@ -897,23 +1012,36 @@ sub process {
897 ($previndent, $stashindent) = ($stashindent, $indent); 1012 ($previndent, $stashindent) = ($stashindent, $indent);
898 ($prevrawline, $stashrawline) = ($stashrawline, $rawline); 1013 ($prevrawline, $stashrawline) = ($stashrawline, $rawline);
899 1014
900 #warn "ic<$in_comment> ce<$comment_edge> line<$line>\n"; 1015 #warn "line<$line>\n";
901 1016
902 } elsif ($realcnt == 1) { 1017 } elsif ($realcnt == 1) {
903 $realcnt--; 1018 $realcnt--;
904 } 1019 }
905 1020
906#make up the handle for any error we report on this line 1021#make up the handle for any error we report on this line
1022 $prefix = "$filename:$realline: " if ($emacs && $file);
1023 $prefix = "$filename:$linenr: " if ($emacs && !$file);
1024
907 $here = "#$linenr: " if (!$file); 1025 $here = "#$linenr: " if (!$file);
908 $here = "#$realline: " if ($file); 1026 $here = "#$realline: " if ($file);
1027
1028 # extract the filename as it passes
1029 if ($line=~/^\+\+\+\s+(\S+)/) {
1030 $realfile = $1;
1031 $realfile =~ s@^[^/]*/@@;
1032
1033 if ($realfile =~ m@include/asm/@) {
1034 ERROR("do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
1035 }
1036 next;
1037 }
1038
909 $here .= "FILE: $realfile:$realline:" if ($realcnt != 0); 1039 $here .= "FILE: $realfile:$realline:" if ($realcnt != 0);
910 1040
911 my $hereline = "$here\n$rawline\n"; 1041 my $hereline = "$here\n$rawline\n";
912 my $herecurr = "$here\n$rawline\n"; 1042 my $herecurr = "$here\n$rawline\n";
913 my $hereprev = "$here\n$prevrawline\n$rawline\n"; 1043 my $hereprev = "$here\n$prevrawline\n$rawline\n";
914 1044
915 $prefix = "$filename:$realline: " if ($emacs && $file);
916 $prefix = "$filename:$linenr: " if ($emacs && !$file);
917 $cnt_lines++ if ($realcnt != 0); 1045 $cnt_lines++ if ($realcnt != 0);
918 1046
919#check the patch for a signoff: 1047#check the patch for a signoff:
@@ -925,7 +1053,7 @@ sub process {
925 $herecurr); 1053 $herecurr);
926 } 1054 }
927 if ($line =~ /^\s*signed-off-by:\S/i) { 1055 if ($line =~ /^\s*signed-off-by:\S/i) {
928 WARN("need space after Signed-off-by:\n" . 1056 WARN("space required after Signed-off-by:\n" .
929 $herecurr); 1057 $herecurr);
930 } 1058 }
931 } 1059 }
@@ -988,52 +1116,50 @@ sub process {
988 } 1116 }
989 1117
990# check for RCS/CVS revision markers 1118# check for RCS/CVS revision markers
991 if ($rawline =~ /\$(Revision|Log|Id)(?:\$|)/) { 1119 if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
992 WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr); 1120 WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr);
993 } 1121 }
994 1122
995# The rest of our checks refer specifically to C style
996# only apply those _outside_ comments. Only skip
997# lines in the middle of comments.
998 next if (!$comment_edge && $in_comment);
999
1000# Check for potential 'bare' types 1123# Check for potential 'bare' types
1001 if ($realcnt) { 1124 if ($realcnt) {
1125 my ($s, $c) = ctx_statement_block($linenr, $realcnt, 0);
1126 $s =~ s/\n./ /g;
1127 $s =~ s/{.*$//;
1128
1002 # Ignore goto labels. 1129 # Ignore goto labels.
1003 if ($line =~ /$Ident:\*$/) { 1130 if ($s =~ /$Ident:\*$/) {
1004 1131
1005 # Ignore functions being called 1132 # Ignore functions being called
1006 } elsif ($line =~ /^.\s*$Ident\s*\(/) { 1133 } elsif ($s =~ /^.\s*$Ident\s*\(/) {
1007 1134
1008 # definitions in global scope can only start with types 1135 # definitions in global scope can only start with types
1009 } elsif ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) { 1136 } elsif ($s =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?($Ident)\b/) {
1010 possible($1, $line); 1137 possible($1, $s);
1011 1138
1012 # declarations always start with types 1139 # declarations always start with types
1013 } elsif ($prev_values eq 'E' && $line =~ /^.\s*(?:$Storage\s+)?(?:const\s+)?($Ident)\b(:?\s+$Sparse)?\s*\**\s*$Ident\s*(?:;|=|,)/) { 1140 } elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:const\s+)?($Ident)\b(:?\s+$Sparse)?\s*\**\s*$Ident\s*(?:;|=|,)/) {
1014 possible($1); 1141 possible($1, $s);
1015 } 1142 }
1016 1143
1017 # any (foo ... *) is a pointer cast, and foo is a type 1144 # any (foo ... *) is a pointer cast, and foo is a type
1018 while ($line =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/g) { 1145 while ($s =~ /\(($Ident)(?:\s+$Sparse)*\s*\*+\s*\)/g) {
1019 possible($1, $line); 1146 possible($1, $s);
1020 } 1147 }
1021 1148
1022 # Check for any sort of function declaration. 1149 # Check for any sort of function declaration.
1023 # int foo(something bar, other baz); 1150 # int foo(something bar, other baz);
1024 # void (*store_gdt)(x86_descr_ptr *); 1151 # void (*store_gdt)(x86_descr_ptr *);
1025 if ($prev_values eq 'E' && $line =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) { 1152 if ($prev_values eq 'E' && $s =~ /^(.(?:typedef\s*)?(?:(?:$Storage|$Inline)\s*)*\s*$Type\s*(?:\b$Ident|\(\*\s*$Ident\))\s*)\(/) {
1026 my ($name_len) = length($1); 1153 my ($name_len) = length($1);
1027 my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, $name_len);
1028 my $ctx = join("\n", @ctx);
1029 1154
1030 $ctx =~ s/\n.//; 1155 my $ctx = $s;
1031 substr($ctx, 0, $name_len + 1) = ''; 1156 substr($ctx, 0, $name_len + 1, '');
1032 $ctx =~ s/\)[^\)]*$//; 1157 $ctx =~ s/\)[^\)]*$//;
1158
1033 for my $arg (split(/\s*,\s*/, $ctx)) { 1159 for my $arg (split(/\s*,\s*/, $ctx)) {
1034 if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/ || $arg =~ /^($Ident)$/) { 1160 if ($arg =~ /^(?:const\s+)?($Ident)(?:\s+$Sparse)*\s*\**\s*(:?\b$Ident)?$/ || $arg =~ /^($Ident)$/) {
1035 1161
1036 possible($1, $line); 1162 possible($1, $s);
1037 } 1163 }
1038 } 1164 }
1039 } 1165 }
@@ -1068,27 +1194,33 @@ sub process {
1068 1194
1069# if/while/etc brace do not go on next line, unless defining a do while loop, 1195# if/while/etc brace do not go on next line, unless defining a do while loop,
1070# or if that brace on the next line is for something else 1196# or if that brace on the next line is for something else
1071 if ($line =~ /\b(?:(if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.#/) { 1197 if ($line =~ /(.*)\b((?:if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.#/) {
1198 my $pre_ctx = "$1$2";
1199
1072 my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0); 1200 my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0);
1073 my $ctx_ln = $linenr + $#ctx + 1; 1201 my $ctx_ln = $linenr + $#ctx + 1;
1074 my $ctx_cnt = $realcnt - $#ctx - 1; 1202 my $ctx_cnt = $realcnt - $#ctx - 1;
1075 my $ctx = join("\n", @ctx); 1203 my $ctx = join("\n", @ctx);
1076 1204
1205 ##warn "realcnt<$realcnt> ctx_cnt<$ctx_cnt>\n";
1206
1077 # Skip over any removed lines in the context following statement. 1207 # Skip over any removed lines in the context following statement.
1078 while ($ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^-/) { 1208 while (defined($lines[$ctx_ln - 1]) && $lines[$ctx_ln - 1] =~ /^-/) {
1079 $ctx_ln++; 1209 $ctx_ln++;
1080 $ctx_cnt--;
1081 } 1210 }
1082 ##warn "line<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>"; 1211 ##warn "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
1083 1212
1084 if ($ctx !~ /{\s*/ && $ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { 1213 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
1085 ERROR("That open brace { should be on the previous line\n" . 1214 ERROR("that open brace { should be on the previous line\n" .
1086 "$here\n$ctx\n$lines[$ctx_ln - 1]"); 1215 "$here\n$ctx\n$lines[$ctx_ln - 1]");
1087 } 1216 }
1088 if ($level == 0 && $ctx =~ /\)\s*\;\s*$/ && defined $lines[$ctx_ln - 1]) { 1217 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
1218 $ctx =~ /\)\s*\;\s*$/ &&
1219 defined $lines[$ctx_ln - 1])
1220 {
1089 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); 1221 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
1090 if ($nindent > $indent) { 1222 if ($nindent > $indent) {
1091 WARN("Trailing semicolon indicates no statements, indent implies otherwise\n" . 1223 WARN("trailing semicolon indicates no statements, indent implies otherwise\n" .
1092 "$here\n$ctx\n$lines[$ctx_ln - 1]"); 1224 "$here\n$ctx\n$lines[$ctx_ln - 1]");
1093 } 1225 }
1094 } 1226 }
@@ -1100,8 +1232,8 @@ sub process {
1100 $curr_values = $prev_values . $curr_values; 1232 $curr_values = $prev_values . $curr_values;
1101 if ($dbg_values) { 1233 if ($dbg_values) {
1102 my $outline = $opline; $outline =~ s/\t/ /g; 1234 my $outline = $opline; $outline =~ s/\t/ /g;
1103 warn "--> .$outline\n"; 1235 print "$linenr > .$outline\n";
1104 warn "--> $curr_values\n"; 1236 print "$linenr > $curr_values\n";
1105 } 1237 }
1106 $prev_values = substr($curr_values, -1); 1238 $prev_values = substr($curr_values, -1);
1107 1239
@@ -1117,7 +1249,7 @@ sub process {
1117# check for initialisation to aggregates open brace on the next line 1249# check for initialisation to aggregates open brace on the next line
1118 if ($prevline =~ /$Declare\s*$Ident\s*=\s*$/ && 1250 if ($prevline =~ /$Declare\s*$Ident\s*=\s*$/ &&
1119 $line =~ /^.\s*{/) { 1251 $line =~ /^.\s*{/) {
1120 ERROR("That open brace { should be on the previous line\n" . $hereprev); 1252 ERROR("that open brace { should be on the previous line\n" . $hereprev);
1121 } 1253 }
1122 1254
1123# 1255#
@@ -1148,7 +1280,9 @@ sub process {
1148 if (($prevline !~ /^}/) && 1280 if (($prevline !~ /^}/) &&
1149 ($prevline !~ /^\+}/) && 1281 ($prevline !~ /^\+}/) &&
1150 ($prevline !~ /^ }/) && 1282 ($prevline !~ /^ }/) &&
1151 ($prevline !~ /\b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=)/)) { 1283 ($prevline !~ /^.DECLARE_$Ident\(\Q$name\E\)/) &&
1284 ($prevline !~ /^.LIST_HEAD\(\Q$name\E\)/) &&
1285 ($prevline !~ /\b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=|\[)/)) {
1152 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); 1286 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
1153 } 1287 }
1154 } 1288 }
@@ -1240,22 +1374,31 @@ sub process {
1240# check for spaces between functions and their parentheses. 1374# check for spaces between functions and their parentheses.
1241 while ($line =~ /($Ident)\s+\(/g) { 1375 while ($line =~ /($Ident)\s+\(/g) {
1242 my $name = $1; 1376 my $name = $1;
1243 my $ctx = substr($line, 0, $-[1]); 1377 my $ctx_before = substr($line, 0, $-[1]);
1378 my $ctx = "$ctx_before$name";
1244 1379
1245 # Ignore those directives where spaces _are_ permitted. 1380 # Ignore those directives where spaces _are_ permitted.
1246 if ($name =~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright|case|__asm__)$/) { 1381 if ($name =~ /^(?:
1382 if|for|while|switch|return|case|
1383 volatile|__volatile__|
1384 __attribute__|format|__extension__|
1385 asm|__asm__)$/x)
1386 {
1247 1387
1248 # cpp #define statements have non-optional spaces, ie 1388 # cpp #define statements have non-optional spaces, ie
1249 # if there is a space between the name and the open 1389 # if there is a space between the name and the open
1250 # parenthesis it is simply not a parameter group. 1390 # parenthesis it is simply not a parameter group.
1251 } elsif ($ctx =~ /^.\#\s*define\s*$/) { 1391 } elsif ($ctx_before =~ /^.\#\s*define\s*$/) {
1392
1393 # cpp #elif statement condition may start with a (
1394 } elsif ($ctx =~ /^.\#\s*elif\s*$/) {
1252 1395
1253 # If this whole things ends with a type its most 1396 # If this whole things ends with a type its most
1254 # likely a typedef for a function. 1397 # likely a typedef for a function.
1255 } elsif ("$ctx$name" =~ /$Type$/) { 1398 } elsif ($ctx =~ /$Type$/) {
1256 1399
1257 } else { 1400 } else {
1258 WARN("no space between function name and open parenthesis '('\n" . $herecurr); 1401 WARN("space prohibited between function name and open parenthesis '('\n" . $herecurr);
1259 } 1402 }
1260 } 1403 }
1261# Check operator spacing. 1404# Check operator spacing.
@@ -1266,7 +1409,7 @@ sub process {
1266 =>|->|<<|>>|<|>|=|!|~| 1409 =>|->|<<|>>|<|>|=|!|~|
1267 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|% 1410 &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/|%
1268 }x; 1411 }x;
1269 my @elements = split(/($;+|$ops|;)/, $opline); 1412 my @elements = split(/($ops|;)/, $opline);
1270 my $off = 0; 1413 my $off = 0;
1271 1414
1272 my $blank = copy_spacing($opline); 1415 my $blank = copy_spacing($opline);
@@ -1274,12 +1417,21 @@ sub process {
1274 for (my $n = 0; $n < $#elements; $n += 2) { 1417 for (my $n = 0; $n < $#elements; $n += 2) {
1275 $off += length($elements[$n]); 1418 $off += length($elements[$n]);
1276 1419
1420 # Pick up the preceeding and succeeding characters.
1421 my $ca = substr($opline, 0, $off);
1422 my $cc = '';
1423 if (length($opline) >= ($off + length($elements[$n + 1]))) {
1424 $cc = substr($opline, $off + length($elements[$n + 1]));
1425 }
1426 my $cb = "$ca$;$cc";
1427
1277 my $a = ''; 1428 my $a = '';
1278 $a = 'V' if ($elements[$n] ne ''); 1429 $a = 'V' if ($elements[$n] ne '');
1279 $a = 'W' if ($elements[$n] =~ /\s$/); 1430 $a = 'W' if ($elements[$n] =~ /\s$/);
1431 $a = 'C' if ($elements[$n] =~ /$;$/);
1280 $a = 'B' if ($elements[$n] =~ /(\[|\()$/); 1432 $a = 'B' if ($elements[$n] =~ /(\[|\()$/);
1281 $a = 'O' if ($elements[$n] eq ''); 1433 $a = 'O' if ($elements[$n] eq '');
1282 $a = 'E' if ($elements[$n] eq '' && $n == 0); 1434 $a = 'E' if ($ca =~ /^\s*$/);
1283 1435
1284 my $op = $elements[$n + 1]; 1436 my $op = $elements[$n + 1];
1285 1437
@@ -1287,6 +1439,7 @@ sub process {
1287 if (defined $elements[$n + 2]) { 1439 if (defined $elements[$n + 2]) {
1288 $c = 'V' if ($elements[$n + 2] ne ''); 1440 $c = 'V' if ($elements[$n + 2] ne '');
1289 $c = 'W' if ($elements[$n + 2] =~ /^\s/); 1441 $c = 'W' if ($elements[$n + 2] =~ /^\s/);
1442 $c = 'C' if ($elements[$n + 2] =~ /^$;/);
1290 $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/); 1443 $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
1291 $c = 'O' if ($elements[$n + 2] eq ''); 1444 $c = 'O' if ($elements[$n + 2] eq '');
1292 $c = 'E' if ($elements[$n + 2] =~ /\s*\\$/); 1445 $c = 'E' if ($elements[$n + 2] =~ /\s*\\$/);
@@ -1294,14 +1447,6 @@ sub process {
1294 $c = 'E'; 1447 $c = 'E';
1295 } 1448 }
1296 1449
1297 # Pick up the preceeding and succeeding characters.
1298 my $ca = substr($opline, 0, $off);
1299 my $cc = '';
1300 if (length($opline) >= ($off + length($elements[$n + 1]))) {
1301 $cc = substr($opline, $off + length($elements[$n + 1]));
1302 }
1303 my $cb = "$ca$;$cc";
1304
1305 my $ctx = "${a}x${c}"; 1450 my $ctx = "${a}x${c}";
1306 1451
1307 my $at = "(ctx:$ctx)"; 1452 my $at = "(ctx:$ctx)";
@@ -1330,14 +1475,14 @@ sub process {
1330 if ($op_type ne 'V' && 1475 if ($op_type ne 'V' &&
1331 $ca =~ /\s$/ && $cc =~ /^\s*,/) { 1476 $ca =~ /\s$/ && $cc =~ /^\s*,/) {
1332 1477
1333 # Ignore comments 1478# # Ignore comments
1334 } elsif ($op =~ /^$;+$/) { 1479# } elsif ($op =~ /^$;+$/) {
1335 1480
1336 # ; should have either the end of line or a space or \ after it 1481 # ; should have either the end of line or a space or \ after it
1337 } elsif ($op eq ';') { 1482 } elsif ($op eq ';') {
1338 if ($ctx !~ /.x[WEB]/ && $cc !~ /^\\/ && 1483 if ($ctx !~ /.x[WEBC]/ &&
1339 $cc !~ /^;/) { 1484 $cc !~ /^\\/ && $cc !~ /^;/) {
1340 ERROR("need space after that '$op' $at\n" . $hereptr); 1485 ERROR("space required after that '$op' $at\n" . $hereptr);
1341 } 1486 }
1342 1487
1343 # // is a comment 1488 # // is a comment
@@ -1346,13 +1491,13 @@ sub process {
1346 # -> should have no spaces 1491 # -> should have no spaces
1347 } elsif ($op eq '->') { 1492 } elsif ($op eq '->') {
1348 if ($ctx =~ /Wx.|.xW/) { 1493 if ($ctx =~ /Wx.|.xW/) {
1349 ERROR("no spaces around that '$op' $at\n" . $hereptr); 1494 ERROR("spaces prohibited around that '$op' $at\n" . $hereptr);
1350 } 1495 }
1351 1496
1352 # , must have a space on the right. 1497 # , must have a space on the right.
1353 } elsif ($op eq ',') { 1498 } elsif ($op eq ',') {
1354 if ($ctx !~ /.xW|.xE/ && $cc !~ /^}/) { 1499 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
1355 ERROR("need space after that '$op' $at\n" . $hereptr); 1500 ERROR("space required after that '$op' $at\n" . $hereptr);
1356 } 1501 }
1357 1502
1358 # '*' as part of a type definition -- reported already. 1503 # '*' as part of a type definition -- reported already.
@@ -1364,21 +1509,26 @@ sub process {
1364 # unary operator, or a cast 1509 # unary operator, or a cast
1365 } elsif ($op eq '!' || $op eq '~' || 1510 } elsif ($op eq '!' || $op eq '~' ||
1366 ($is_unary && ($op eq '*' || $op eq '-' || $op eq '&'))) { 1511 ($is_unary && ($op eq '*' || $op eq '-' || $op eq '&'))) {
1367 if ($ctx !~ /[WEB]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { 1512 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
1368 ERROR("need space before that '$op' $at\n" . $hereptr); 1513 ERROR("space required before that '$op' $at\n" . $hereptr);
1369 } 1514 }
1370 if ($ctx =~ /.xW/) { 1515 if ($ctx =~ /.xW/) {
1371 ERROR("no space after that '$op' $at\n" . $hereptr); 1516 ERROR("space prohibited after that '$op' $at\n" . $hereptr);
1372 } 1517 }
1373 1518
1374 # unary ++ and unary -- are allowed no space on one side. 1519 # unary ++ and unary -- are allowed no space on one side.
1375 } elsif ($op eq '++' or $op eq '--') { 1520 } elsif ($op eq '++' or $op eq '--') {
1376 if ($ctx !~ /[WOB]x[^W]/ && $ctx !~ /[^W]x[WOBE]/) { 1521 if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
1377 ERROR("need space one side of that '$op' $at\n" . $hereptr); 1522 ERROR("space required one side of that '$op' $at\n" . $hereptr);
1378 } 1523 }
1379 if ($ctx =~ /WxB/ || ($ctx =~ /Wx./ && $cc =~ /^;/)) { 1524 if ($ctx =~ /Wx[BE]/ ||
1380 ERROR("no space before that '$op' $at\n" . $hereptr); 1525 ($ctx =~ /Wx./ && $cc =~ /^;/)) {
1526 ERROR("space prohibited before that '$op' $at\n" . $hereptr);
1381 } 1527 }
1528 if ($ctx =~ /ExW/) {
1529 ERROR("space prohibited after that '$op' $at\n" . $hereptr);
1530 }
1531
1382 1532
1383 # << and >> may either have or not have spaces both sides 1533 # << and >> may either have or not have spaces both sides
1384 } elsif ($op eq '<<' or $op eq '>>' or 1534 } elsif ($op eq '<<' or $op eq '>>' or
@@ -1387,17 +1537,17 @@ sub process {
1387 $op eq '*' or $op eq '/' or 1537 $op eq '*' or $op eq '/' or
1388 $op eq '%') 1538 $op eq '%')
1389 { 1539 {
1390 if ($ctx !~ /VxV|WxW|VxE|WxE|VxO/) { 1540 if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
1391 ERROR("need consistent spacing around '$op' $at\n" . 1541 ERROR("need consistent spacing around '$op' $at\n" .
1392 $hereptr); 1542 $hereptr);
1393 } 1543 }
1394 1544
1395 # All the others need spaces both sides. 1545 # All the others need spaces both sides.
1396 } elsif ($ctx !~ /[EW]x[WE]/) { 1546 } elsif ($ctx !~ /[EWC]x[CWE]/) {
1397 # Ignore email addresses <foo@bar> 1547 # Ignore email addresses <foo@bar>
1398 if (!($op eq '<' && $cb =~ /$;\S+\@\S+>/) && 1548 if (!($op eq '<' && $cb =~ /$;\S+\@\S+>/) &&
1399 !($op eq '>' && $cb =~ /<\S+\@\S+$;/)) { 1549 !($op eq '>' && $cb =~ /<\S+\@\S+$;/)) {
1400 ERROR("need spaces around that '$op' $at\n" . $hereptr); 1550 ERROR("spaces required around that '$op' $at\n" . $hereptr);
1401 } 1551 }
1402 } 1552 }
1403 $off += length($elements[$n + 1]); 1553 $off += length($elements[$n + 1]);
@@ -1427,31 +1577,31 @@ sub process {
1427#need space before brace following if, while, etc 1577#need space before brace following if, while, etc
1428 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || 1578 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) ||
1429 $line =~ /do{/) { 1579 $line =~ /do{/) {
1430 ERROR("need a space before the open brace '{'\n" . $herecurr); 1580 ERROR("space required before the open brace '{'\n" . $herecurr);
1431 } 1581 }
1432 1582
1433# closing brace should have a space following it when it has anything 1583# closing brace should have a space following it when it has anything
1434# on the line 1584# on the line
1435 if ($line =~ /}(?!(?:,|;|\)))\S/) { 1585 if ($line =~ /}(?!(?:,|;|\)))\S/) {
1436 ERROR("need a space after that close brace '}'\n" . $herecurr); 1586 ERROR("space required after that close brace '}'\n" . $herecurr);
1437 } 1587 }
1438 1588
1439# check spacing on square brackets 1589# check spacing on square brackets
1440 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) { 1590 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
1441 ERROR("no space after that open square bracket '['\n" . $herecurr); 1591 ERROR("space prohibited after that open square bracket '['\n" . $herecurr);
1442 } 1592 }
1443 if ($line =~ /\s\]/) { 1593 if ($line =~ /\s\]/) {
1444 ERROR("no space before that close square bracket ']'\n" . $herecurr); 1594 ERROR("space prohibited before that close square bracket ']'\n" . $herecurr);
1445 } 1595 }
1446 1596
1447# check spacing on paretheses 1597# check spacing on paretheses
1448 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ && 1598 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
1449 $line !~ /for\s*\(\s+;/) { 1599 $line !~ /for\s*\(\s+;/) {
1450 ERROR("no space after that open parenthesis '('\n" . $herecurr); 1600 ERROR("space prohibited after that open parenthesis '('\n" . $herecurr);
1451 } 1601 }
1452 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ && 1602 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
1453 $line !~ /for\s*\(.*;\s+\)/) { 1603 $line !~ /for\s*\(.*;\s+\)/) {
1454 ERROR("no space before that close parenthesis ')'\n" . $herecurr); 1604 ERROR("space prohibited before that close parenthesis ')'\n" . $herecurr);
1455 } 1605 }
1456 1606
1457#goto labels aren't indented, allow a single space however 1607#goto labels aren't indented, allow a single space however
@@ -1462,7 +1612,7 @@ sub process {
1462 1612
1463# Need a space before open parenthesis after if, while etc 1613# Need a space before open parenthesis after if, while etc
1464 if ($line=~/\b(if|while|for|switch)\(/) { 1614 if ($line=~/\b(if|while|for|switch)\(/) {
1465 ERROR("need a space before the open parenthesis '('\n" . $herecurr); 1615 ERROR("space required before the open parenthesis '('\n" . $herecurr);
1466 } 1616 }
1467 1617
1468# Check for illegal assignment in if conditional. 1618# Check for illegal assignment in if conditional.
@@ -1475,10 +1625,12 @@ sub process {
1475 1625
1476 # Find out what is on the end of the line after the 1626 # Find out what is on the end of the line after the
1477 # conditional. 1627 # conditional.
1478 substr($s, 0, length($c)) = ''; 1628 substr($s, 0, length($c), '');
1479 $s =~ s/\n.*//g; 1629 $s =~ s/\n.*//g;
1480 $s =~ s/$;//g; # Remove any comments 1630 $s =~ s/$;//g; # Remove any comments
1481 if (length($c) && $s !~ /^\s*({|;|)\s*\\*\s*$/) { 1631 if (length($c) && $s !~ /^\s*({|;|)\s*\\*\s*$/ &&
1632 $c !~ /^.\#\s*if/)
1633 {
1482 ERROR("trailing statements should be on next line\n" . $herecurr); 1634 ERROR("trailing statements should be on next line\n" . $herecurr);
1483 } 1635 }
1484 } 1636 }
@@ -1520,7 +1672,7 @@ sub process {
1520 1672
1521 # Find out what is on the end of the line after the 1673 # Find out what is on the end of the line after the
1522 # conditional. 1674 # conditional.
1523 substr($s, 0, length($c)) = ''; 1675 substr($s, 0, length($c), '');
1524 $s =~ s/\n.*//g; 1676 $s =~ s/\n.*//g;
1525 1677
1526 if ($s =~ /^\s*;/) { 1678 if ($s =~ /^\s*;/) {
@@ -1544,14 +1696,14 @@ sub process {
1544 if ($tree && $rawline =~ m{^.\#\s*include\s*\<asm\/(.*)\.h\>}) { 1696 if ($tree && $rawline =~ m{^.\#\s*include\s*\<asm\/(.*)\.h\>}) {
1545 my $checkfile = "$root/include/linux/$1.h"; 1697 my $checkfile = "$root/include/linux/$1.h";
1546 if (-f $checkfile && $1 ne 'irq.h') { 1698 if (-f $checkfile && $1 ne 'irq.h') {
1547 CHK("Use #include <linux/$1.h> instead of <asm/$1.h>\n" . 1699 WARN("Use #include <linux/$1.h> instead of <asm/$1.h>\n" .
1548 $herecurr); 1700 $herecurr);
1549 } 1701 }
1550 } 1702 }
1551 1703
1552# multi-statement macros should be enclosed in a do while loop, grab the 1704# multi-statement macros should be enclosed in a do while loop, grab the
1553# first statement and ensure its the whole macro if its not enclosed 1705# first statement and ensure its the whole macro if its not enclosed
1554# in a known goot container 1706# in a known good container
1555 if ($prevline =~ /\#define.*\\/ && 1707 if ($prevline =~ /\#define.*\\/ &&
1556 $prevline !~/(?:do\s+{|\(\{|\{)/ && 1708 $prevline !~/(?:do\s+{|\(\{|\{)/ &&
1557 $line !~ /(?:do\s+{|\(\{|\{)/ && 1709 $line !~ /(?:do\s+{|\(\{|\{)/ &&
@@ -1599,84 +1751,103 @@ sub process {
1599# check for redundant bracing round if etc 1751# check for redundant bracing round if etc
1600 if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) { 1752 if ($line =~ /(^.*)\bif\b/ && $1 !~ /else\s*$/) {
1601 my ($level, $endln, @chunks) = 1753 my ($level, $endln, @chunks) =
1602 ctx_statement_full($linenr, $realcnt, 0); 1754 ctx_statement_full($linenr, $realcnt, 1);
1603 #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n"; 1755 #print "chunks<$#chunks> linenr<$linenr> endln<$endln> level<$level>\n";
1604 if ($#chunks > 1 && $level == 0) { 1756 #print "APW: <<$chunks[1][0]>><<$chunks[1][1]>>\n";
1757 if ($#chunks > 0 && $level == 0) {
1605 my $allowed = 0; 1758 my $allowed = 0;
1606 my $seen = 0; 1759 my $seen = 0;
1760 my $herectx = $here . "\n";
1761 my $ln = $linenr - 1;
1607 for my $chunk (@chunks) { 1762 for my $chunk (@chunks) {
1608 my ($cond, $block) = @{$chunk}; 1763 my ($cond, $block) = @{$chunk};
1609 1764
1610 substr($block, 0, length($cond)) = ''; 1765 # If the condition carries leading newlines, then count those as offsets.
1766 my ($whitespace) = ($cond =~ /^((?:\s*\n[+-])*\s*)/s);
1767 my $offset = statement_rawlines($whitespace) - 1;
1611 1768
1612 $seen++ if ($block =~ /^\s*{/); 1769 #print "COND<$cond> whitespace<$whitespace> offset<$offset>\n";
1613 1770
1614 $block =~ s/(^|\n)./$1/g; 1771 # We have looked at and allowed this specific line.
1615 $block =~ s/^\s*{//; 1772 $suppress_ifbraces{$ln + $offset} = 1;
1616 $block =~ s/}\s*$//;
1617 $block =~ s/^\s*//;
1618 $block =~ s/\s*$//;
1619 1773
1620 my @lines = ($block =~ /\n/g); 1774 $herectx .= "$rawlines[$ln + $offset]\n[...]\n";
1621 my @statements = ($block =~ /;/g); 1775 $ln += statement_rawlines($block) - 1;
1622 1776
1623 #print "cond<$cond> block<$block> lines<" . scalar(@lines) . "> statements<" . scalar(@statements) . "> seen<$seen> allowed<$allowed>\n"; 1777 substr($block, 0, length($cond), '');
1624 if (scalar(@lines) != 0) { 1778
1779 $seen++ if ($block =~ /^\s*{/);
1780
1781 #print "cond<$cond> block<$block> allowed<$allowed>\n";
1782 if (statement_lines($cond) > 1) {
1783 #print "APW: ALLOWED: cond<$cond>\n";
1625 $allowed = 1; 1784 $allowed = 1;
1626 } 1785 }
1627 if ($block =~/\b(?:if|for|while)\b/) { 1786 if ($block =~/\b(?:if|for|while)\b/) {
1787 #print "APW: ALLOWED: block<$block>\n";
1628 $allowed = 1; 1788 $allowed = 1;
1629 } 1789 }
1630 if (scalar(@statements) > 1) { 1790 if (statement_block_size($block) > 1) {
1791 #print "APW: ALLOWED: lines block<$block>\n";
1631 $allowed = 1; 1792 $allowed = 1;
1632 } 1793 }
1633 } 1794 }
1634 if ($seen && !$allowed) { 1795 if ($seen && !$allowed) {
1635 WARN("braces {} are not necessary for any arm of this statement\n" . $herecurr); 1796 WARN("braces {} are not necessary for any arm of this statement\n" . $herectx);
1636 $suppress_ifbraces = $endln;
1637 } 1797 }
1638 } 1798 }
1639 } 1799 }
1640 if ($linenr > $suppress_ifbraces && 1800 if (!defined $suppress_ifbraces{$linenr - 1} &&
1641 $line =~ /\b(if|while|for|else)\b/) { 1801 $line =~ /\b(if|while|for|else)\b/) {
1642 # Locate the end of the opening statement. 1802 my $allowed = 0;
1643 my @control = ctx_statement($linenr, $realcnt, 0); 1803
1644 my $nr = $linenr + (scalar(@control) - 1); 1804 # Check the pre-context.
1645 my $cnt = $realcnt - (scalar(@control) - 1); 1805 if (substr($line, 0, $-[0]) =~ /(\}\s*)$/) {
1646 1806 #print "APW: ALLOWED: pre<$1>\n";
1647 my $off = $realcnt - $cnt; 1807 $allowed = 1;
1648 #print "$off: line<$line>end<" . $lines[$nr - 1] . ">\n"; 1808 }
1649 1809
1650 # If this is is a braced statement group check it 1810 my ($level, $endln, @chunks) =
1651 if ($lines[$nr - 1] =~ /{\s*$/) { 1811 ctx_statement_full($linenr, $realcnt, $-[0]);
1652 my ($lvl, @block) = ctx_block_level($nr, $cnt); 1812
1653 1813 # Check the condition.
1654 my $stmt = join("\n", @block); 1814 my ($cond, $block) = @{$chunks[0]};
1655 # Drop the diff line leader. 1815 #print "CHECKING<$linenr> cond<$cond> block<$block>\n";
1656 $stmt =~ s/\n./\n/g; 1816 if (defined $cond) {
1657 # Drop the code outside the block. 1817 substr($block, 0, length($cond), '');
1658 $stmt =~ s/(^[^{]*){\s*//; 1818 }
1659 my $before = $1; 1819 if (statement_lines($cond) > 1) {
1660 $stmt =~ s/\s*}([^}]*$)//; 1820 #print "APW: ALLOWED: cond<$cond>\n";
1661 my $after = $1; 1821 $allowed = 1;
1662 1822 }
1663 #print "block<" . join(' ', @block) . "><" . scalar(@block) . ">\n"; 1823 if ($block =~/\b(?:if|for|while)\b/) {
1664 #print "before<$before> stmt<$stmt> after<$after>\n\n"; 1824 #print "APW: ALLOWED: block<$block>\n";
1665 1825 $allowed = 1;
1666 # Count the newlines, if there is only one 1826 }
1667 # then the block should not have {}'s. 1827 if (statement_block_size($block) > 1) {
1668 my @lines = ($stmt =~ /\n/g); 1828 #print "APW: ALLOWED: lines block<$block>\n";
1669 my @statements = ($stmt =~ /;/g); 1829 $allowed = 1;
1670 #print "lines<" . scalar(@lines) . ">\n"; 1830 }
1671 #print "statements<" . scalar(@statements) . ">\n"; 1831 # Check the post-context.
1672 if ($lvl == 0 && scalar(@lines) == 0 && 1832 if (defined $chunks[1]) {
1673 scalar(@statements) < 2 && 1833 my ($cond, $block) = @{$chunks[1]};
1674 $stmt !~ /{/ && $stmt !~ /\bif\b/ && 1834 if (defined $cond) {
1675 $before !~ /}/ && $after !~ /{/) { 1835 substr($block, 0, length($cond), '');
1676 my $herectx = "$here\n" . join("\n", @control, @block[1 .. $#block]) . "\n";
1677 shift(@block);
1678 WARN("braces {} are not necessary for single statement blocks\n" . $herectx);
1679 } 1836 }
1837 if ($block =~ /^\s*\{/) {
1838 #print "APW: ALLOWED: chunk-1 block<$block>\n";
1839 $allowed = 1;
1840 }
1841 }
1842 if ($level == 0 && $block =~ /^\s*\{/ && !$allowed) {
1843 my $herectx = $here . "\n";;
1844 my $end = $linenr + statement_rawlines($block) - 1;
1845
1846 for (my $ln = $linenr - 1; $ln < $end; $ln++) {
1847 $herectx .= $rawlines[$ln] . "\n";;
1848 }
1849
1850 WARN("braces {} are not necessary for single statement blocks\n" . $herectx);
1680 } 1851 }
1681 } 1852 }
1682 1853
@@ -1784,6 +1955,28 @@ sub process {
1784 if ($line =~ /__FUNCTION__/) { 1955 if ($line =~ /__FUNCTION__/) {
1785 WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr); 1956 WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr);
1786 } 1957 }
1958
1959# check for semaphores used as mutexes
1960 if ($line =~ /\b(DECLARE_MUTEX|init_MUTEX)\s*\(/) {
1961 WARN("mutexes are preferred for single holder semaphores\n" . $herecurr);
1962 }
1963# check for semaphores used as mutexes
1964 if ($line =~ /\binit_MUTEX_LOCKED\s*\(/) {
1965 WARN("consider using a completion\n" . $herecurr);
1966 }
1967# recommend strict_strto* over simple_strto*
1968 if ($line =~ /\bsimple_(strto.*?)\s*\(/) {
1969 WARN("consider using strict_$1 in preference to simple_$1\n" . $herecurr);
1970 }
1971
1972# use of NR_CPUS is usually wrong
1973# ignore definitions of NR_CPUS and usage to define arrays as likely right
1974 if ($line =~ /\bNR_CPUS\b/ &&
1975 $line !~ /^.#\s*define\s+NR_CPUS\s+/ &&
1976 $line !~ /^.\s*$Declare\s.*\[[^\]]*NR_CPUS[^\]]*\]/)
1977 {
1978 WARN("usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
1979 }
1787 } 1980 }
1788 1981
1789 # If we have no input at all, then there is nothing to report on 1982 # If we have no input at all, then there is nothing to report on
@@ -1828,15 +2021,6 @@ sub process {
1828 print "are false positives report them to the maintainer, see\n"; 2021 print "are false positives report them to the maintainer, see\n";
1829 print "CHECKPATCH in MAINTAINERS.\n"; 2022 print "CHECKPATCH in MAINTAINERS.\n";
1830 } 2023 }
1831 print <<EOL if ($file == 1 && $quiet == 0);
1832
1833WARNING: Using --file mode. Please do not send patches to linux-kernel
1834that change whole existing files if you did not significantly change most
1835of the the file for other reasons anyways or just wrote the file newly
1836from scratch. Pure code style patches have a significant cost in a
1837quickly changing code base like Linux because they cause rejects
1838with other changes.
1839EOL
1840 2024
1841 return $clean; 2025 return $clean;
1842} 2026}
diff --git a/scripts/kernel-doc b/scripts/kernel-doc
index 74c2f9db2aac..263d04ab2d94 100755
--- a/scripts/kernel-doc
+++ b/scripts/kernel-doc
@@ -247,6 +247,10 @@ my ($function, %function_table,%parametertypes,$declaration_purpose);
247my ($type,$declaration_name,$return_type); 247my ($type,$declaration_name,$return_type);
248my ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map); 248my ($newsection,$newcontents,$prototype,$filelist, $brcount, %source_map);
249 249
250if (defined($ENV{'KBUILD_VERBOSE'})) {
251 $verbose = "$ENV{'KBUILD_VERBOSE'}";
252}
253
250# Generated docbook code is inserted in a template at a point where 254# Generated docbook code is inserted in a template at a point where
251# docbook v3.1 requires a non-zero sequence of RefEntry's; see: 255# docbook v3.1 requires a non-zero sequence of RefEntry's; see:
252# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html 256# http://www.oasis-open.org/docbook/documentation/reference/html/refentry.html
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
index 9ddf944cce29..769b69db89c1 100644
--- a/scripts/mod/file2alias.c
+++ b/scripts/mod/file2alias.c
@@ -51,11 +51,13 @@ do { \
51 sprintf(str + strlen(str), "*"); \ 51 sprintf(str + strlen(str), "*"); \
52} while(0) 52} while(0)
53 53
54unsigned int cross_build = 0;
54/** 55/**
55 * Check that sizeof(device_id type) are consistent with size of section 56 * Check that sizeof(device_id type) are consistent with size of section
56 * in .o file. If in-consistent then userspace and kernel does not agree 57 * in .o file. If in-consistent then userspace and kernel does not agree
57 * on actual size which is a bug. 58 * on actual size which is a bug.
58 * Also verify that the final entry in the table is all zeros. 59 * Also verify that the final entry in the table is all zeros.
60 * Ignore both checks if build host differ from target host and size differs.
59 **/ 61 **/
60static void device_id_check(const char *modname, const char *device_id, 62static void device_id_check(const char *modname, const char *device_id,
61 unsigned long size, unsigned long id_size, 63 unsigned long size, unsigned long id_size,
@@ -64,6 +66,8 @@ static void device_id_check(const char *modname, const char *device_id,
64 int i; 66 int i;
65 67
66 if (size % id_size || size < id_size) { 68 if (size % id_size || size < id_size) {
69 if (cross_build != 0)
70 return;
67 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo " 71 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
68 "of the size of section __mod_%s_device_table=%lu.\n" 72 "of the size of section __mod_%s_device_table=%lu.\n"
69 "Fix definition of struct %s_device_id " 73 "Fix definition of struct %s_device_id "
@@ -324,19 +328,52 @@ static int do_pnp_entry(const char *filename,
324 return 1; 328 return 1;
325} 329}
326 330
327/* looks like: "pnp:cCdD..." */ 331/* looks like: "pnp:dD" for every device of the card */
328static int do_pnp_card_entry(const char *filename, 332static void do_pnp_card_entries(void *symval, unsigned long size,
329 struct pnp_card_device_id *id, char *alias) 333 struct module *mod)
330{ 334{
331 int i; 335 const unsigned long id_size = sizeof(struct pnp_card_device_id);
336 const unsigned int count = (size / id_size)-1;
337 const struct pnp_card_device_id *cards = symval;
338 unsigned int i;
332 339
333 sprintf(alias, "pnp:c%s", id->id); 340 device_id_check(mod->name, "pnp", size, id_size, symval);
334 for (i = 0; i < PNP_MAX_DEVICES; i++) { 341
335 if (! *id->devs[i].id) 342 for (i = 0; i < count; i++) {
336 break; 343 unsigned int j;
337 sprintf(alias + strlen(alias), "d%s", id->devs[i].id); 344 const struct pnp_card_device_id *card = &cards[i];
345
346 for (j = 0; j < PNP_MAX_DEVICES; j++) {
347 const char *id = (char *)card->devs[j].id;
348 int i2, j2;
349 int dup = 0;
350
351 if (!id[0])
352 break;
353
354 /* find duplicate, already added value */
355 for (i2 = 0; i2 < i && !dup; i2++) {
356 const struct pnp_card_device_id *card2 = &cards[i2];
357
358 for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) {
359 const char *id2 = (char *)card2->devs[j2].id;
360
361 if (!id2[0])
362 break;
363
364 if (!strcmp(id, id2)) {
365 dup = 1;
366 break;
367 }
368 }
369 }
370
371 /* add an individual alias for every device entry */
372 if (!dup)
373 buf_printf(&mod->dev_table_buf,
374 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
375 }
338 } 376 }
339 return 1;
340} 377}
341 378
342/* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */ 379/* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */
@@ -630,9 +667,7 @@ void handle_moddevtable(struct module *mod, struct elf_info *info,
630 sizeof(struct pnp_device_id), "pnp", 667 sizeof(struct pnp_device_id), "pnp",
631 do_pnp_entry, mod); 668 do_pnp_entry, mod);
632 else if (sym_is(symname, "__mod_pnp_card_device_table")) 669 else if (sym_is(symname, "__mod_pnp_card_device_table"))
633 do_table(symval, sym->st_size, 670 do_pnp_card_entries(symval, sym->st_size, mod);
634 sizeof(struct pnp_card_device_id), "pnp_card",
635 do_pnp_card_entry, mod);
636 else if (sym_is(symname, "__mod_pcmcia_device_table")) 671 else if (sym_is(symname, "__mod_pcmcia_device_table"))
637 do_table(symval, sym->st_size, 672 do_table(symval, sym->st_size,
638 sizeof(struct pcmcia_device_id), "pcmcia", 673 sizeof(struct pcmcia_device_id), "pcmcia",
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 695b5d657cf5..110cf243fa4e 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -2026,7 +2026,7 @@ int main(int argc, char **argv)
2026 int opt; 2026 int opt;
2027 int err; 2027 int err;
2028 2028
2029 while ((opt = getopt(argc, argv, "i:I:msSo:awM:K:")) != -1) { 2029 while ((opt = getopt(argc, argv, "i:I:cmsSo:awM:K:")) != -1) {
2030 switch (opt) { 2030 switch (opt) {
2031 case 'i': 2031 case 'i':
2032 kernel_read = optarg; 2032 kernel_read = optarg;
@@ -2035,6 +2035,9 @@ int main(int argc, char **argv)
2035 module_read = optarg; 2035 module_read = optarg;
2036 external_module = 1; 2036 external_module = 1;
2037 break; 2037 break;
2038 case 'c':
2039 cross_build = 1;
2040 break;
2038 case 'm': 2041 case 'm':
2039 modversions = 1; 2042 modversions = 1;
2040 break; 2043 break;
diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
index 565c5872407e..09f58e33d227 100644
--- a/scripts/mod/modpost.h
+++ b/scripts/mod/modpost.h
@@ -135,6 +135,7 @@ struct elf_info {
135}; 135};
136 136
137/* file2alias.c */ 137/* file2alias.c */
138extern unsigned int cross_build;
138void handle_moddevtable(struct module *mod, struct elf_info *info, 139void handle_moddevtable(struct module *mod, struct elf_info *info,
139 Elf_Sym *sym, const char *symname); 140 Elf_Sym *sym, const char *symname);
140void add_moddevtable(struct buffer *buf, struct module *mod); 141void add_moddevtable(struct buffer *buf, struct module *mod);