Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

update checkpatch.pl to version 0.09

This version brings a number of new checks, and a number of bug
fixes. Of note:

- checks for spacing on round and square bracket combinations
- loosening of the single statement brace checks, to allow
them when they contain comments or where other blocks in a
compound statement have them.
- parks the multple declaration support
- allows architecture defines in architecture specific headers

Andy Whitcroft (21):
Version: 0.09
loosen single statement brace checks
fix up multiple declaration to avoid function arguments
add some function space parenthesis check exceptions
handle EXPORT_'s with parentheses in their names
clean up some warnings in multi-line macro bracketing support
park the multiple declaration checks
make block brace checks count comments as a statement
__volatile__ and __extension__ are not functions
allow architecture specific defined within architecture includes
check spacing on square brackets
check spacing on parentheses
ensure we apply checks to the part before start comment
check #ifdef conditional spacing
handle __init_refok and __must_check
add noinline to inline checks
prevent email addresses from tripping spacing checks
handle typed initialiser spacing
handle line contination as end of line
add bool to the type matcher
refine EXPORT_SYMBOL checks to handle pointers

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>

authored by

Andy Whitcroft and committed by
Linus Torvalds
22f2a2ef a44648b0

+71 -31
+71 -31
scripts/checkpatch.pl
··· 9 9 my $P = $0; 10 10 $P =~ s@.*/@@g; 11 11 12 - my $V = '0.08'; 12 + my $V = '0.09'; 13 13 14 14 use Getopt::Long qw(:config no_auto_abbrev); 15 15 ··· 311 311 312 312 my $Ident = qr{[A-Za-z\d_]+}; 313 313 my $Storage = qr{extern|static}; 314 - my $Sparse = qr{__user|__kernel|__force|__iomem}; 314 + my $Sparse = qr{__user|__kernel|__force|__iomem|__must_check|__init_refok}; 315 315 my $NonptrType = qr{ 316 316 \b 317 317 (?:const\s+)? ··· 325 325 unsigned| 326 326 float| 327 327 double| 328 + bool| 328 329 long\s+int| 329 330 long\s+long| 330 331 long\s+long\s+int| ··· 341 340 }x; 342 341 my $Type = qr{ 343 342 \b$NonptrType\b 344 - (?:\s*\*+\s*const|\s*\*+)? 343 + (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)? 344 + (?:\s+$Sparse)* 345 345 }x; 346 346 my $Declare = qr{(?:$Storage\s+)?$Type}; 347 347 my $Attribute = qr{const|__read_mostly|__init|__initdata|__meminit}; ··· 496 494 ERROR("use tabs not spaces\n" . $herevet); 497 495 } 498 496 499 - # 500 - # The rest of our checks refer specifically to C style 501 - # only apply those _outside_ comments. 502 - # 503 - next if ($in_comment); 504 - 505 497 # Remove comments from the line before processing. 506 - $line =~ s@/\*.*\*/@@g; 507 - $line =~ s@/\*.*@@; 508 - $line =~ s@.*\*/@@; 498 + my $comment_edge = ($line =~ s@/\*.*\*/@@g) + 499 + ($line =~ s@/\*.*@@) + 500 + ($line =~ s@^(.).*\*/@$1@); 501 + 502 + # The rest of our checks refer specifically to C style 503 + # only apply those _outside_ comments. Only skip 504 + # lines in the middle of comments. 505 + next if (!$comment_edge && $in_comment); 509 506 510 507 # Standardise the strings and chars within the input to simplify matching. 511 508 $line = sanitise_line($line); ··· 600 599 if (($prevline !~ /^}/) && 601 600 ($prevline !~ /^\+}/) && 602 601 ($prevline !~ /^ }/) && 603 - ($prevline !~ /\s$name(?:\s+$Attribute)?\s*(?:;|=)/)) { 602 + ($prevline !~ /\b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=)/)) { 604 603 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); 605 604 } 606 605 } ··· 681 680 682 681 # check for spaces between functions and their parentheses. 683 682 if ($line =~ /($Ident)\s+\(/ && 684 - $1 !~ /^(?:if|for|while|switch|return|volatile)$/ && 683 + $1 !~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright)$/ && 685 684 $line !~ /$Type\s+\(/ && $line !~ /^.\#\s*define\b/) { 686 - ERROR("no space between function name and open parenthesis '('\n" . $herecurr); 685 + WARN("no space between function name and open parenthesis '('\n" . $herecurr); 687 686 } 688 687 # Check operator spacing. 689 688 # Note we expand the line with the leading + as the real ··· 713 712 $c = 'W' if ($elements[$n + 2] =~ /^\s/); 714 713 $c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/); 715 714 $c = 'O' if ($elements[$n + 2] eq ''); 715 + $c = 'E' if ($elements[$n + 2] =~ /\s*\\$/); 716 716 } else { 717 717 $c = 'E'; 718 718 } ··· 814 812 815 813 # All the others need spaces both sides. 816 814 } elsif ($ctx !~ /[EW]x[WE]/) { 817 - ERROR("need spaces around that '$op' $at\n" . $hereptr); 815 + # Ignore email addresses <foo@bar> 816 + if (!($op eq '<' && $cb =~ /$;\S+\@\S+>/) && 817 + !($op eq '>' && $cb =~ /<\S+\@\S+$;/)) { 818 + ERROR("need spaces around that '$op' $at\n" . $hereptr); 819 + } 818 820 } 819 821 $off += length($elements[$n + 1]); 820 822 } ··· 829 823 WARN("multiple assignments should be avoided\n" . $herecurr); 830 824 } 831 825 832 - # check for multiple declarations, allowing for a function declaration 833 - # continuation. 834 - if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ && 835 - $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) { 836 - WARN("declaring multiple variables together should be avoided\n" . $herecurr); 837 - } 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 + ## 831 + ## # Remove any bracketed sections to ensure we do not 832 + ## # falsly report the parameters of functions. 833 + ## my $ln = $line; 834 + ## while ($ln =~ s/\([^\(\)]*\)//g) { 835 + ## } 836 + ## if ($ln =~ /,/) { 837 + ## WARN("declaring multiple variables together should be avoided\n" . $herecurr); 838 + ## } 839 + ## } 838 840 839 841 #need space before brace following if, while, etc 840 - if ($line =~ /\(.*\){/ || $line =~ /do{/) { 842 + if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || 843 + $line =~ /do{/) { 841 844 ERROR("need a space before the open brace '{'\n" . $herecurr); 842 845 } 843 846 ··· 854 839 # on the line 855 840 if ($line =~ /}(?!(?:,|;|\)))\S/) { 856 841 ERROR("need a space after that close brace '}'\n" . $herecurr); 842 + } 843 + 844 + # check spacing on square brackets 845 + if ($line =~ /\[\s/ && $line !~ /\[\s*$/) { 846 + ERROR("no space after that open square bracket '['\n" . $herecurr); 847 + } 848 + if ($line =~ /\s\]/) { 849 + ERROR("no space before that close square bracket ']'\n" . $herecurr); 850 + } 851 + 852 + # check spacing on paretheses 853 + if ($line =~ /\(\s/ && $line !~ /\(\s*$/) { 854 + ERROR("no space after that open parenthesis '('\n" . $herecurr); 855 + } 856 + if ($line =~ /\s\)/) { 857 + ERROR("no space before that close parenthesis ')'\n" . $herecurr); 857 858 } 858 859 859 860 #goto labels aren't indented, allow a single space however ··· 941 910 # grabbing the statement after the identifier 942 911 $prevline =~ m{^(.#\s*define\s*$Ident(?:\([^\)]*\))?\s*)(.*)\\\s*$}; 943 912 ##print "1<$1> 2<$2>\n"; 944 - if ($2 ne '') { 913 + if (defined $2 && $2 ne '') { 945 914 $off = length($1); 946 915 $ln--; 947 916 $cnt++; ··· 981 950 my ($lvl, @block) = ctx_block_level($nr, $cnt); 982 951 983 952 my $stmt = join(' ', @block); 984 - $stmt =~ s/^[^{]*{//; 985 - $stmt =~ s/}[^}]*$//; 953 + $stmt =~ s/(^[^{]*){//; 954 + my $before = $1; 955 + $stmt =~ s/}([^}]*$)//; 956 + my $after = $1; 986 957 987 958 #print "block<" . join(' ', @block) . "><" . scalar(@block) . ">\n"; 988 959 #print "stmt<$stmt>\n\n"; ··· 996 963 # Also nested if's often require braces to 997 964 # disambiguate the else binding so shhh there. 998 965 my @semi = ($stmt =~ /;/g); 966 + push(@semi, "/**/") if ($stmt =~ m@/\*@); 999 967 ##print "semi<" . scalar(@semi) . ">\n"; 1000 968 if ($lvl == 0 && scalar(@semi) < 2 && 1001 - $stmt !~ /{/ && $stmt !~ /\bif\b/) { 969 + $stmt !~ /{/ && $stmt !~ /\bif\b/ && 970 + $before !~ /}/ && $after !~ /{/) { 1002 971 my $herectx = "$here\n" . join("\n", @control, @block[1 .. $#block]) . "\n"; 1003 972 shift(@block); 1004 - ERROR("braces {} are not necessary for single statement blocks\n" . $herectx); 973 + WARN("braces {} are not necessary for single statement blocks\n" . $herectx); 1005 974 } 1006 975 } 1007 976 } ··· 1048 1013 # $clean = 0; 1049 1014 # } 1050 1015 1016 + # warn about spacing in #ifdefs 1017 + if ($line =~ /^.#\s*(ifdef|ifndef|elif)\s\s+/) { 1018 + ERROR("exactly one space required after that #$1\n" . $herecurr); 1019 + } 1020 + 1051 1021 # check for spinlock_t definitions without a comment. 1052 1022 if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) { 1053 1023 my $which = $1; ··· 1067 1027 } 1068 1028 } 1069 1029 # check of hardware specific defines 1070 - if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@) { 1030 + if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) { 1071 1031 CHK("architecture specific defines should be avoided\n" . $herecurr); 1072 1032 } 1073 1033 1074 1034 # check the location of the inline attribute, that it is between 1075 1035 # storage class and type. 1076 - if ($line =~ /$Type\s+(?:inline|__always_inline)\b/ || 1077 - $line =~ /\b(?:inline|always_inline)\s+$Storage/) { 1036 + if ($line =~ /$Type\s+(?:inline|__always_inline|noinline)\b/ || 1037 + $line =~ /\b(?:inline|__always_inline|noinline)\s+$Storage/) { 1078 1038 ERROR("inline keyword should sit between storage class and type\n" . $herecurr); 1079 1039 } 1080 1040