diff options
author | Andy Whitcroft <apw@shadowen.org> | 2007-10-17 02:29:38 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2007-10-17 11:42:56 -0400 |
commit | 9c0ca6f9a0a0820da25b64259ea475751f1dd306 (patch) | |
tree | 5d21f0beec8fc1f738dc6a3d6e7e03e24ba514d2 /scripts | |
parent | 2e8ecb9db0bcc19e1cc8bb51e9252fe6a86a9863 (diff) |
update checkpatch.pl to version 0.10
This version brings a number of new checks, and a number of bug
fixes. Of note:
- better categorisation and space checks for dual use unary/binary
operators
- warn on deprecated use of {SPIN,RW}_LOCK_UNLOCKED
- check if/for/while with trailing ';' for hanging statements
- detect DOS line endings
- detect redundant casts for kalloc()
Andy Whitcroft (18):
Version: 0.10
asmlinkage is also a storage type
pull out inline specifiers
allow only some operators before a unary operator
parenthesised values may span line ends
add additional attribute matching
handle sparse annotations within pointer type space checks
support alternative function definition syntax for typedefs
check if/for/while with trailing ';' for hanging statements
fix output format for case checks
deprecate SPIN_LOCK_UNLOCKED and RW_LOCK_UNLOCKED
allow complex macros with bracketing braces
detect and report DOS line endings
fastcall is a valid function attribute
bracket spacing is ok for 'for'
categorise operators into unary/binary/definitions
add heuristic to pick up on unannotated types
remove spurious warnings from cat_vet
Dave Jones (1):
Make checkpatch warn about pointless casting of kalloc returns.
Signed-off-by: Andy Whitcroft <apw@shadowen.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 254 |
1 files changed, 196 insertions, 58 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index dae7d30dca0f..59ad83caa210 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -9,7 +9,7 @@ use strict; | |||
9 | my $P = $0; | 9 | my $P = $0; |
10 | $P =~ s@.*/@@g; | 10 | $P =~ s@.*/@@g; |
11 | 11 | ||
12 | my $V = '0.09'; | 12 | my $V = '0.10'; |
13 | 13 | ||
14 | use Getopt::Long qw(:config no_auto_abbrev); | 14 | use Getopt::Long qw(:config no_auto_abbrev); |
15 | 15 | ||
@@ -212,6 +212,11 @@ sub ctx_block_level { | |||
212 | 212 | ||
213 | return ctx_block_get($linenr, $remain, 0, '{', '}', 0); | 213 | return ctx_block_get($linenr, $remain, 0, '{', '}', 0); |
214 | } | 214 | } |
215 | sub ctx_statement_level { | ||
216 | my ($linenr, $remain, $off) = @_; | ||
217 | |||
218 | return ctx_block_get($linenr, $remain, 0, '(', ')', $off); | ||
219 | } | ||
215 | 220 | ||
216 | sub ctx_locate_comment { | 221 | sub ctx_locate_comment { |
217 | my ($first_line, $end_line) = @_; | 222 | my ($first_line, $end_line) = @_; |
@@ -255,13 +260,42 @@ sub ctx_has_comment { | |||
255 | return ($cmt ne ''); | 260 | return ($cmt ne ''); |
256 | } | 261 | } |
257 | 262 | ||
263 | sub ctx_expr_before { | ||
264 | my ($line) = @_; | ||
265 | |||
266 | ##print "CHECK<$line>\n"; | ||
267 | |||
268 | my $pos = length($line) - 1; | ||
269 | my $count = 0; | ||
270 | my $c; | ||
271 | |||
272 | for (; $pos >= 0; $pos--) { | ||
273 | $c = substr($line, $pos, 1); | ||
274 | ##print "CHECK: c<$c> count<$count>\n"; | ||
275 | if ($c eq ')') { | ||
276 | $count++; | ||
277 | } elsif ($c eq '(') { | ||
278 | last if (--$count == 0); | ||
279 | } | ||
280 | } | ||
281 | |||
282 | ##print "CHECK: result<" . substr($line, 0, $pos) . ">\n"; | ||
283 | |||
284 | return substr($line, 0, $pos); | ||
285 | } | ||
286 | |||
258 | sub cat_vet { | 287 | sub cat_vet { |
259 | my ($vet) = @_; | 288 | my ($vet) = @_; |
289 | my ($res, $coded); | ||
260 | 290 | ||
261 | $vet =~ s/\t/^I/; | 291 | $res = ''; |
262 | $vet =~ s/$/\$/; | 292 | while ($vet =~ /([^[:cntrl:]]*)([[:cntrl:]])/g) { |
293 | $coded = sprintf("^%c", unpack('C', $2) + 64); | ||
294 | $res .= $1 . $coded; | ||
295 | } | ||
296 | $res =~ s/$/\$/; | ||
263 | 297 | ||
264 | return $vet; | 298 | return $res; |
265 | } | 299 | } |
266 | 300 | ||
267 | my @report = (); | 301 | my @report = (); |
@@ -310,8 +344,17 @@ sub process { | |||
310 | my $first_line = 0; | 344 | my $first_line = 0; |
311 | 345 | ||
312 | my $Ident = qr{[A-Za-z\d_]+}; | 346 | my $Ident = qr{[A-Za-z\d_]+}; |
313 | my $Storage = qr{extern|static}; | 347 | my $Storage = qr{extern|static|asmlinkage}; |
314 | my $Sparse = qr{__user|__kernel|__force|__iomem|__must_check|__init_refok}; | 348 | my $Sparse = qr{ |
349 | __user| | ||
350 | __kernel| | ||
351 | __force| | ||
352 | __iomem| | ||
353 | __must_check| | ||
354 | __init_refok| | ||
355 | fastcall | ||
356 | }x; | ||
357 | my $Inline = qr{inline|__always_inline|noinline}; | ||
315 | my $NonptrType = qr{ | 358 | my $NonptrType = qr{ |
316 | \b | 359 | \b |
317 | (?:const\s+)? | 360 | (?:const\s+)? |
@@ -345,11 +388,18 @@ sub process { | |||
345 | (?:\s+$Sparse)* | 388 | (?:\s+$Sparse)* |
346 | }x; | 389 | }x; |
347 | my $Declare = qr{(?:$Storage\s+)?$Type}; | 390 | my $Declare = qr{(?:$Storage\s+)?$Type}; |
348 | my $Attribute = qr{const|__read_mostly|__init|__initdata|__meminit}; | 391 | my $Attribute = qr{ |
349 | 392 | const| | |
393 | __read_mostly| | ||
394 | __(?:mem|cpu|dev|)(?:initdata|init) | ||
395 | }x; | ||
350 | my $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; | 396 | my $Member = qr{->$Ident|\.$Ident|\[[^]]*\]}; |
351 | my $Lval = qr{$Ident(?:$Member)*}; | 397 | my $Lval = qr{$Ident(?:$Member)*}; |
352 | 398 | ||
399 | # Possible bare types. | ||
400 | my @bare = (); | ||
401 | my $Bare = $NonptrType; | ||
402 | |||
353 | # Pre-scan the patch looking for any __setup documentation. | 403 | # Pre-scan the patch looking for any __setup documentation. |
354 | my @setup_docs = (); | 404 | my @setup_docs = (); |
355 | my $setup_docs = 0; | 405 | my $setup_docs = 0; |
@@ -477,7 +527,11 @@ sub process { | |||
477 | next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); | 527 | next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); |
478 | 528 | ||
479 | #trailing whitespace | 529 | #trailing whitespace |
480 | if ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) { | 530 | if ($line =~ /^\+.*\015/) { |
531 | my $herevet = "$here\n" . cat_vet($line) . "\n"; | ||
532 | ERROR("DOS line endings\n" . $herevet); | ||
533 | |||
534 | } elsif ($line =~ /^\+.*\S\s+$/ || $line =~ /^\+\s+$/) { | ||
481 | my $herevet = "$here\n" . cat_vet($line) . "\n"; | 535 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
482 | ERROR("trailing whitespace\n" . $herevet); | 536 | ERROR("trailing whitespace\n" . $herevet); |
483 | } | 537 | } |
@@ -509,6 +563,30 @@ sub process { | |||
509 | # Standardise the strings and chars within the input to simplify matching. | 563 | # Standardise the strings and chars within the input to simplify matching. |
510 | $line = sanitise_line($line); | 564 | $line = sanitise_line($line); |
511 | 565 | ||
566 | # Check for potential 'bare' types | ||
567 | if ($realcnt && | ||
568 | $line !~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?$Type\b/ && | ||
569 | $line !~ /$Ident:\s*$/ && | ||
570 | $line !~ /^.\s*$Ident\s*\(/ && | ||
571 | ($line =~ /^.(?:$Storage\s+)?(?:$Inline\s+)?($Ident)\b/ || | ||
572 | $line =~ /^.\s*(?:$Storage\s+)?($Ident)\b\s*\**\s*$Ident\s*(?:;|=)/)) { | ||
573 | my $possible = $1; | ||
574 | if ($possible !~ /^(?:$Storage|$Type|DEFINE_\S+)$/ && | ||
575 | $possible ne 'goto' && $possible ne 'return' && | ||
576 | $possible ne 'struct' && $possible ne 'enum' && | ||
577 | $possible ne 'case' && $possible ne 'else' && | ||
578 | $possible ne 'typedef') { | ||
579 | #print "POSSIBLE<$possible>\n"; | ||
580 | push(@bare, $possible); | ||
581 | my $bare = join("|", @bare); | ||
582 | $Bare = qr{ | ||
583 | \b(?:$bare)\b | ||
584 | (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)? | ||
585 | (?:\s+$Sparse)* | ||
586 | }x; | ||
587 | } | ||
588 | } | ||
589 | |||
512 | # | 590 | # |
513 | # Checks which may be anchored in the context. | 591 | # Checks which may be anchored in the context. |
514 | # | 592 | # |
@@ -531,18 +609,19 @@ sub process { | |||
531 | } | 609 | } |
532 | } | 610 | } |
533 | if ($err ne '') { | 611 | if ($err ne '') { |
534 | ERROR("switch and case should be at the same indent\n$hereline\n$err\n"); | 612 | ERROR("switch and case should be at the same indent\n$hereline$err"); |
535 | } | 613 | } |
536 | } | 614 | } |
537 | 615 | ||
538 | # if/while/etc brace do not go on next line, unless defining a do while loop, | 616 | # if/while/etc brace do not go on next line, unless defining a do while loop, |
539 | # or if that brace on the next line is for something else | 617 | # or if that brace on the next line is for something else |
540 | if ($line =~ /\b(?:(if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.#/) { | 618 | if ($line =~ /\b(?:(if|while|for|switch)\s*\(|do\b|else\b)/ && $line !~ /^.#/) { |
541 | my @ctx = ctx_statement($linenr, $realcnt, 0); | 619 | my ($level, @ctx) = ctx_statement_level($linenr, $realcnt, 0); |
542 | my $ctx_ln = $linenr + $#ctx + 1; | 620 | my $ctx_ln = $linenr + $#ctx + 1; |
543 | my $ctx_cnt = $realcnt - $#ctx - 1; | 621 | my $ctx_cnt = $realcnt - $#ctx - 1; |
544 | my $ctx = join("\n", @ctx); | 622 | my $ctx = join("\n", @ctx); |
545 | 623 | ||
624 | # Skip over any removed lines in the context following statement. | ||
546 | while ($ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^-/) { | 625 | while ($ctx_cnt > 0 && $lines[$ctx_ln - 1] =~ /^-/) { |
547 | $ctx_ln++; | 626 | $ctx_ln++; |
548 | $ctx_cnt--; | 627 | $ctx_cnt--; |
@@ -553,6 +632,13 @@ sub process { | |||
553 | ERROR("That open brace { should be on the previous line\n" . | 632 | ERROR("That open brace { should be on the previous line\n" . |
554 | "$here\n$ctx\n$lines[$ctx_ln - 1]"); | 633 | "$here\n$ctx\n$lines[$ctx_ln - 1]"); |
555 | } | 634 | } |
635 | if ($level == 0 && $ctx =~ /\)\s*\;\s*$/ && defined $lines[$ctx_ln - 1]) { | ||
636 | my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); | ||
637 | if ($nindent > $indent) { | ||
638 | WARN("Trailing semicolon indicates no statements, indent implies otherwise\n" . | ||
639 | "$here\n$ctx\n$lines[$ctx_ln - 1]"); | ||
640 | } | ||
641 | } | ||
556 | } | 642 | } |
557 | 643 | ||
558 | #ignore lines not being added | 644 | #ignore lines not being added |
@@ -619,7 +705,7 @@ sub process { | |||
619 | # check for new typedefs, only function parameters and sparse annotations | 705 | # check for new typedefs, only function parameters and sparse annotations |
620 | # make sense. | 706 | # make sense. |
621 | if ($line =~ /\btypedef\s/ && | 707 | if ($line =~ /\btypedef\s/ && |
622 | $line !~ /\btypedef\s+$Type\s+\(\s*\*$Ident\s*\)\s*\(/ && | 708 | $line !~ /\btypedef\s+$Type\s+\(\s*\*?$Ident\s*\)\s*\(/ && |
623 | $line !~ /\b__bitwise(?:__|)\b/) { | 709 | $line !~ /\b__bitwise(?:__|)\b/) { |
624 | WARN("do not add new typedefs\n" . $herecurr); | 710 | WARN("do not add new typedefs\n" . $herecurr); |
625 | } | 711 | } |
@@ -633,11 +719,11 @@ sub process { | |||
633 | ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" . | 719 | ERROR("\"(foo $1 )\" should be \"(foo $1)\"\n" . |
634 | $herecurr); | 720 | $herecurr); |
635 | 721 | ||
636 | } elsif ($line =~ m{$NonptrType(\*+)(?:\s+$Attribute)?\s+[A-Za-z\d_]+}) { | 722 | } elsif ($line =~ m{$NonptrType(\*+)(?:\s+(?:$Attribute|$Sparse))?\s+[A-Za-z\d_]+}) { |
637 | ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" . | 723 | ERROR("\"foo$1 bar\" should be \"foo $1bar\"\n" . |
638 | $herecurr); | 724 | $herecurr); |
639 | 725 | ||
640 | } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+$Attribute)\s+[A-Za-z\d_]+}) { | 726 | } elsif ($line =~ m{$NonptrType\s+(\*+)(?!\s+(?:$Attribute|$Sparse))\s+[A-Za-z\d_]+}) { |
641 | ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" . | 727 | ERROR("\"foo $1 bar\" should be \"foo $1bar\"\n" . |
642 | $herecurr); | 728 | $herecurr); |
643 | } | 729 | } |
@@ -693,7 +779,13 @@ sub process { | |||
693 | $opline = expand_tabs($opline); | 779 | $opline = expand_tabs($opline); |
694 | $opline =~ s/^./ /; | 780 | $opline =~ s/^./ /; |
695 | if (!($line=~/\#\s*include/)) { | 781 | if (!($line=~/\#\s*include/)) { |
696 | my @elements = split(/(<<=|>>=|<=|>=|==|!=|\+=|-=|\*=|\/=|%=|\^=|\|=|&=|=>|->|<<|>>|<|>|=|!|~|&&|\|\||,|\^|\+\+|--|;|&|\||\+|-|\*|\/\/|\/)/, $opline); | 782 | my $ops = qr{ |
783 | <<=|>>=|<=|>=|==|!=| | ||
784 | \+=|-=|\*=|\/=|%=|\^=|\|=|&=| | ||
785 | =>|->|<<|>>|<|>|=|!|~| | ||
786 | &&|\|\||,|\^|\+\+|--|&|\||\+|-|\*|\/ | ||
787 | }x; | ||
788 | my @elements = split(/($ops|;)/, $opline); | ||
697 | my $off = 0; | 789 | my $off = 0; |
698 | for (my $n = 0; $n < $#elements; $n += 2) { | 790 | for (my $n = 0; $n < $#elements; $n += 2) { |
699 | $off += length($elements[$n]); | 791 | $off += length($elements[$n]); |
@@ -733,7 +825,60 @@ sub process { | |||
733 | my $ptr = (" " x $off) . "^"; | 825 | my $ptr = (" " x $off) . "^"; |
734 | my $hereptr = "$hereline$ptr\n"; | 826 | my $hereptr = "$hereline$ptr\n"; |
735 | 827 | ||
736 | ##print "<$s1:$op:$s2> <$elements[$n]:$elements[$n + 1]:$elements[$n + 2]>\n"; | 828 | # Classify operators into binary, unary, or |
829 | # definitions (* only) where they have more | ||
830 | # than one mode. | ||
831 | my $unary_ctx = $prevline . $ca; | ||
832 | $unary_ctx =~ s/^./ /; | ||
833 | my $is_unary = 0; | ||
834 | my $Unary = qr{ | ||
835 | (?: | ||
836 | ^|;|,|$ops|\(|\?|:| | ||
837 | \(\s*$Type\s*\)| | ||
838 | $Type| | ||
839 | return|case|else| | ||
840 | \{|\}| | ||
841 | \[| | ||
842 | ^.\#\s*define\s+$Ident\s*(?:\([^\)]*\))?| | ||
843 | ^.\#\s*else| | ||
844 | ^.\#\s*endif| | ||
845 | ^.\#\s*(?:if|ifndef|ifdef)\b.* | ||
846 | )\s*(?:|\\)\s*$ | ||
847 | }x; | ||
848 | my $UnaryFalse = qr{ | ||
849 | sizeof\s*\(\s*$Type\s*\)\s*$ | ||
850 | }x; | ||
851 | my $UnaryDefine = qr{ | ||
852 | (?:$Type|$Bare)\s*| | ||
853 | (?:$Type|$Bare).*,\s*\** | ||
854 | }x; | ||
855 | if ($op eq '-' || $op eq '&' || $op eq '*') { | ||
856 | # An operator is binary if the left hand | ||
857 | # side is a value. Pick out the known | ||
858 | # non-values. | ||
859 | if ($unary_ctx =~ /$Unary$/s && | ||
860 | $unary_ctx !~ /$UnaryFalse$/s) { | ||
861 | $is_unary = 1; | ||
862 | |||
863 | # Special handling for ')' check if this | ||
864 | # brace represents a conditional, if so | ||
865 | # we are unary. | ||
866 | } elsif ($unary_ctx =~ /\)\s*$/) { | ||
867 | my $before = ctx_expr_before($unary_ctx); | ||
868 | if ($before =~ /(?:for|if|while)\s*$/) { | ||
869 | $is_unary = 1; | ||
870 | } | ||
871 | } | ||
872 | |||
873 | # Check for type definition for of '*'. | ||
874 | if ($op eq '*' && $unary_ctx =~ /$UnaryDefine$/) { | ||
875 | $is_unary = 2; | ||
876 | } | ||
877 | } | ||
878 | |||
879 | #if ($op eq '-' || $op eq '&' || $op eq '*') { | ||
880 | # print "UNARY: <$is_unary $a:$op:$c> <$ca:$op:$cc> <$unary_ctx>\n"; | ||
881 | #} | ||
737 | 882 | ||
738 | # ; should have either the end of line or a space or \ after it | 883 | # ; should have either the end of line or a space or \ after it |
739 | if ($op eq ';') { | 884 | if ($op eq ';') { |
@@ -757,9 +902,16 @@ sub process { | |||
757 | ERROR("need space after that '$op' $at\n" . $hereptr); | 902 | ERROR("need space after that '$op' $at\n" . $hereptr); |
758 | } | 903 | } |
759 | 904 | ||
760 | # unary ! and unary ~ are allowed no space on the right | 905 | # '*' as part of a type definition -- reported already. |
761 | } elsif ($op eq '!' or $op eq '~') { | 906 | } elsif ($op eq '*' && $is_unary == 2) { |
762 | if ($ctx !~ /[WOEB]x./) { | 907 | #warn "'*' is part of type\n"; |
908 | |||
909 | # unary operators should have a space before and | ||
910 | # none after. May be left adjacent to another | ||
911 | # unary operator, or a cast | ||
912 | } elsif ($op eq '!' || $op eq '~' || | ||
913 | ($is_unary && ($op eq '*' || $op eq '-' || $op eq '&'))) { | ||
914 | if ($ctx !~ /[WEB]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { | ||
763 | ERROR("need space before that '$op' $at\n" . $hereptr); | 915 | ERROR("need space before that '$op' $at\n" . $hereptr); |
764 | } | 916 | } |
765 | if ($ctx =~ /.xW/) { | 917 | if ($ctx =~ /.xW/) { |
@@ -775,39 +927,13 @@ sub process { | |||
775 | ERROR("no space before that '$op' $at\n" . $hereptr); | 927 | ERROR("no space before that '$op' $at\n" . $hereptr); |
776 | } | 928 | } |
777 | 929 | ||
778 | # & is both unary and binary | ||
779 | # unary: | ||
780 | # a &b | ||
781 | # binary (consistent spacing): | ||
782 | # a&b OK | ||
783 | # a & b OK | ||
784 | # | ||
785 | # boiling down to: if there is a space on the right then there | ||
786 | # should be one on the left. | ||
787 | # | ||
788 | # - is the same | ||
789 | # | ||
790 | } elsif ($op eq '&' or $op eq '-') { | ||
791 | if ($ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]/) { | ||
792 | ERROR("need space before that '$op' $at\n" . $hereptr); | ||
793 | } | ||
794 | |||
795 | # * is the same as & only adding: | ||
796 | # type: | ||
797 | # (foo *) | ||
798 | # (foo **) | ||
799 | # | ||
800 | } elsif ($op eq '*') { | ||
801 | if ($ca !~ /$Type$/ && $cb !~ /(\*$;|$;\*)/ && | ||
802 | $ctx !~ /VxV|[EW]x[WE]|[EWB]x[VO]|OxV|WxB|BxB/) { | ||
803 | ERROR("need space before that '$op' $at\n" . $hereptr); | ||
804 | } | ||
805 | |||
806 | # << and >> may either have or not have spaces both sides | 930 | # << and >> may either have or not have spaces both sides |
807 | } elsif ($op eq '<<' or $op eq '>>' or $op eq '+' or $op eq '/' or | 931 | } elsif ($op eq '<<' or $op eq '>>' or |
808 | $op eq '^' or $op eq '|') | 932 | $op eq '&' or $op eq '^' or $op eq '|' or |
933 | $op eq '+' or $op eq '-' or | ||
934 | $op eq '*' or $op eq '/') | ||
809 | { | 935 | { |
810 | if ($ctx !~ /VxV|WxW|VxE|WxE/) { | 936 | if ($ctx !~ /VxV|WxW|VxE|WxE|VxO/) { |
811 | ERROR("need consistent spacing around '$op' $at\n" . | 937 | ERROR("need consistent spacing around '$op' $at\n" . |
812 | $hereptr); | 938 | $hereptr); |
813 | } | 939 | } |
@@ -865,10 +991,12 @@ sub process { | |||
865 | } | 991 | } |
866 | 992 | ||
867 | # check spacing on paretheses | 993 | # check spacing on paretheses |
868 | if ($line =~ /\(\s/ && $line !~ /\(\s*$/) { | 994 | if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ && |
995 | $line !~ /for\s*\(\s+;/) { | ||
869 | ERROR("no space after that open parenthesis '('\n" . $herecurr); | 996 | ERROR("no space after that open parenthesis '('\n" . $herecurr); |
870 | } | 997 | } |
871 | if ($line =~ /\s\)/) { | 998 | if ($line =~ /\s\)/ && $line !~ /^.\s*\)/ && |
999 | $line !~ /for\s*\(.*;\s+\)/) { | ||
872 | ERROR("no space before that close parenthesis ')'\n" . $herecurr); | 1000 | ERROR("no space before that close parenthesis ')'\n" . $herecurr); |
873 | } | 1001 | } |
874 | 1002 | ||
@@ -926,10 +1054,10 @@ sub process { | |||
926 | # multi-statement macros should be enclosed in a do while loop, grab the | 1054 | # multi-statement macros should be enclosed in a do while loop, grab the |
927 | # first statement and ensure its the whole macro if its not enclosed | 1055 | # first statement and ensure its the whole macro if its not enclosed |
928 | # in a known goot container | 1056 | # in a known goot container |
929 | if (($prevline=~/\#define.*\\/) and | 1057 | if ($prevline =~ /\#define.*\\/ && |
930 | !($prevline=~/do\s+{/) and !($prevline=~/\(\{/) and | 1058 | $prevline !~/(?:do\s+{|\(\{|\{)/ && |
931 | !($line=~/do.*{/) and !($line=~/\(\{/) and | 1059 | $line !~ /(?:do\s+{|\(\{|\{)/ && |
932 | !($line=~/^.\s*$Declare\s/)) { | 1060 | $line !~ /^.\s*$Declare\s/) { |
933 | # Grab the first statement, if that is the entire macro | 1061 | # Grab the first statement, if that is the entire macro |
934 | # its ok. This may start either on the #define line | 1062 | # its ok. This may start either on the #define line |
935 | # or the one below. | 1063 | # or the one below. |
@@ -1027,6 +1155,11 @@ sub process { | |||
1027 | WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); | 1155 | WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); |
1028 | } | 1156 | } |
1029 | 1157 | ||
1158 | # SPIN_LOCK_UNLOCKED & RW_LOCK_UNLOCKED are deprecated | ||
1159 | if ($line =~ /\b(SPIN_LOCK_UNLOCKED|RW_LOCK_UNLOCKED)/) { | ||
1160 | ERROR("Use of $1 is deprecated: see Documentation/spinlocks.txt\n" . $herecurr); | ||
1161 | } | ||
1162 | |||
1030 | # warn about #if 0 | 1163 | # warn about #if 0 |
1031 | if ($line =~ /^.#\s*if\s+0\b/) { | 1164 | if ($line =~ /^.#\s*if\s+0\b/) { |
1032 | CHK("if this code is redundant consider removing it\n" . | 1165 | CHK("if this code is redundant consider removing it\n" . |
@@ -1073,8 +1206,8 @@ sub process { | |||
1073 | 1206 | ||
1074 | # check the location of the inline attribute, that it is between | 1207 | # check the location of the inline attribute, that it is between |
1075 | # storage class and type. | 1208 | # storage class and type. |
1076 | if ($line =~ /$Type\s+(?:inline|__always_inline|noinline)\b/ || | 1209 | if ($line =~ /\b$Type\s+$Inline\b/ || |
1077 | $line =~ /\b(?:inline|__always_inline|noinline)\s+$Storage/) { | 1210 | $line =~ /\b$Inline\s+$Storage\b/) { |
1078 | ERROR("inline keyword should sit between storage class and type\n" . $herecurr); | 1211 | ERROR("inline keyword should sit between storage class and type\n" . $herecurr); |
1079 | } | 1212 | } |
1080 | 1213 | ||
@@ -1091,6 +1224,11 @@ sub process { | |||
1091 | CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr); | 1224 | CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr); |
1092 | } | 1225 | } |
1093 | } | 1226 | } |
1227 | |||
1228 | # check for pointless casting of kmalloc return | ||
1229 | if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) { | ||
1230 | WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); | ||
1231 | } | ||
1094 | } | 1232 | } |
1095 | 1233 | ||
1096 | if ($chk_patch && !$is_patch) { | 1234 | if ($chk_patch && !$is_patch) { |