aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAndy Whitcroft <apw@shadowen.org>2007-08-10 13:01:03 -0700
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-08-11 15:47:41 -0700
commit22f2a2ef9b468569cb34a7a056e54d56fdac0b9d (patch)
tree1dbebb8b2d3d4246a97b29c43378f2a41e573977 /scripts
parenta44648b057f5331fe6c0e863dc693ed335490e7a (diff)
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>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl102
1 files changed, 71 insertions, 31 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 73751ab6ec0..dae7d30dca0 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -9,7 +9,7 @@ use strict;
my $P = $0;
$P =~ s@.*/@@g;
-my $V = '0.08';
+my $V = '0.09';
use Getopt::Long qw(:config no_auto_abbrev);
@@ -311,7 +311,7 @@ sub process {
my $Ident = qr{[A-Za-z\d_]+};
my $Storage = qr{extern|static};
- my $Sparse = qr{__user|__kernel|__force|__iomem};
+ my $Sparse = qr{__user|__kernel|__force|__iomem|__must_check|__init_refok};
my $NonptrType = qr{
\b
(?:const\s+)?
@@ -325,6 +325,7 @@ sub process {
unsigned|
float|
double|
+ bool|
long\s+int|
long\s+long|
long\s+long\s+int|
@@ -340,7 +341,8 @@ sub process {
}x;
my $Type = qr{
\b$NonptrType\b
- (?:\s*\*+\s*const|\s*\*+)?
+ (?:\s*\*+\s*const|\s*\*+|(?:\s*\[\s*\])+)?
+ (?:\s+$Sparse)*
}x;
my $Declare = qr{(?:$Storage\s+)?$Type};
my $Attribute = qr{const|__read_mostly|__init|__initdata|__meminit};
@@ -494,16 +496,15 @@ sub process {
ERROR("use tabs not spaces\n" . $herevet);
}
- #
- # The rest of our checks refer specifically to C style
- # only apply those _outside_ comments.
- #
- next if ($in_comment);
-
# Remove comments from the line before processing.
- $line =~ s@/\*.*\*/@@g;
- $line =~ s@/\*.*@@;
- $line =~ s@.*\*/@@;
+ my $comment_edge = ($line =~ s@/\*.*\*/@@g) +
+ ($line =~ s@/\*.*@@) +
+ ($line =~ s@^(.).*\*/@$1@);
+
+# The rest of our checks refer specifically to C style
+# only apply those _outside_ comments. Only skip
+# lines in the middle of comments.
+ next if (!$comment_edge && $in_comment);
# Standardise the strings and chars within the input to simplify matching.
$line = sanitise_line($line);
@@ -599,7 +600,7 @@ sub process {
if (($prevline !~ /^}/) &&
($prevline !~ /^\+}/) &&
($prevline !~ /^ }/) &&
- ($prevline !~ /\s$name(?:\s+$Attribute)?\s*(?:;|=)/)) {
+ ($prevline !~ /\b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=)/)) {
WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
}
}
@@ -680,9 +681,9 @@ sub process {
# check for spaces between functions and their parentheses.
if ($line =~ /($Ident)\s+\(/ &&
- $1 !~ /^(?:if|for|while|switch|return|volatile)$/ &&
+ $1 !~ /^(?:if|for|while|switch|return|volatile|__volatile__|__attribute__|format|__extension__|Copyright)$/ &&
$line !~ /$Type\s+\(/ && $line !~ /^.\#\s*define\b/) {
- ERROR("no space between function name and open parenthesis '('\n" . $herecurr);
+ WARN("no space between function name and open parenthesis '('\n" . $herecurr);
}
# Check operator spacing.
# Note we expand the line with the leading + as the real
@@ -712,6 +713,7 @@ sub process {
$c = 'W' if ($elements[$n + 2] =~ /^\s/);
$c = 'B' if ($elements[$n + 2] =~ /^(\)|\]|;)/);
$c = 'O' if ($elements[$n + 2] eq '');
+ $c = 'E' if ($elements[$n + 2] =~ /\s*\\$/);
} else {
$c = 'E';
}
@@ -812,7 +814,11 @@ sub process {
# All the others need spaces both sides.
} elsif ($ctx !~ /[EW]x[WE]/) {
- ERROR("need spaces around that '$op' $at\n" . $hereptr);
+ # Ignore email addresses <foo@bar>
+ if (!($op eq '<' && $cb =~ /$;\S+\@\S+>/) &&
+ !($op eq '>' && $cb =~ /<\S+\@\S+$;/)) {
+ ERROR("need spaces around that '$op' $at\n" . $hereptr);
+ }
}
$off += length($elements[$n + 1]);
}
@@ -823,15 +829,24 @@ sub process {
WARN("multiple assignments should be avoided\n" . $herecurr);
}
-# check for multiple declarations, allowing for a function declaration
-# continuation.
- if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
- $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
- WARN("declaring multiple variables together should be avoided\n" . $herecurr);
- }
+## # check for multiple declarations, allowing for a function declaration
+## # continuation.
+## if ($line =~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Ident.*/ &&
+## $line !~ /^.\s*$Type\s+$Ident(?:\s*=[^,{]*)?\s*,\s*$Type\s*$Ident.*/) {
+##
+## # Remove any bracketed sections to ensure we do not
+## # falsly report the parameters of functions.
+## my $ln = $line;
+## while ($ln =~ s/\([^\(\)]*\)//g) {
+## }
+## if ($ln =~ /,/) {
+## WARN("declaring multiple variables together should be avoided\n" . $herecurr);
+## }
+## }
#need space before brace following if, while, etc
- if ($line =~ /\(.*\){/ || $line =~ /do{/) {
+ if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) ||
+ $line =~ /do{/) {
ERROR("need a space before the open brace '{'\n" . $herecurr);
}
@@ -841,6 +856,22 @@ sub process {
ERROR("need a space after that close brace '}'\n" . $herecurr);
}
+# check spacing on square brackets
+ if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
+ ERROR("no space after that open square bracket '['\n" . $herecurr);
+ }
+ if ($line =~ /\s\]/) {
+ ERROR("no space before that close square bracket ']'\n" . $herecurr);
+ }
+
+# check spacing on paretheses
+ if ($line =~ /\(\s/ && $line !~ /\(\s*$/) {
+ ERROR("no space after that open parenthesis '('\n" . $herecurr);
+ }
+ if ($line =~ /\s\)/) {
+ ERROR("no space before that close parenthesis ')'\n" . $herecurr);
+ }
+
#goto labels aren't indented, allow a single space however
if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
!($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
@@ -910,7 +941,7 @@ sub process {
# grabbing the statement after the identifier
$prevline =~ m{^(.#\s*define\s*$Ident(?:\([^\)]*\))?\s*)(.*)\\\s*$};
##print "1<$1> 2<$2>\n";
- if ($2 ne '') {
+ if (defined $2 && $2 ne '') {
$off = length($1);
$ln--;
$cnt++;
@@ -950,8 +981,10 @@ sub process {
my ($lvl, @block) = ctx_block_level($nr, $cnt);
my $stmt = join(' ', @block);
- $stmt =~ s/^[^{]*{//;
- $stmt =~ s/}[^}]*$//;
+ $stmt =~ s/(^[^{]*){//;
+ my $before = $1;
+ $stmt =~ s/}([^}]*$)//;
+ my $after = $1;
#print "block<" . join(' ', @block) . "><" . scalar(@block) . ">\n";
#print "stmt<$stmt>\n\n";
@@ -963,12 +996,14 @@ sub process {
# Also nested if's often require braces to
# disambiguate the else binding so shhh there.
my @semi = ($stmt =~ /;/g);
+ push(@semi, "/**/") if ($stmt =~ m@/\*@);
##print "semi<" . scalar(@semi) . ">\n";
if ($lvl == 0 && scalar(@semi) < 2 &&
- $stmt !~ /{/ && $stmt !~ /\bif\b/) {
+ $stmt !~ /{/ && $stmt !~ /\bif\b/ &&
+ $before !~ /}/ && $after !~ /{/) {
my $herectx = "$here\n" . join("\n", @control, @block[1 .. $#block]) . "\n";
shift(@block);
- ERROR("braces {} are not necessary for single statement blocks\n" . $herectx);
+ WARN("braces {} are not necessary for single statement blocks\n" . $herectx);
}
}
}
@@ -1013,6 +1048,11 @@ sub process {
# $clean = 0;
# }
+# warn about spacing in #ifdefs
+ if ($line =~ /^.#\s*(ifdef|ifndef|elif)\s\s+/) {
+ ERROR("exactly one space required after that #$1\n" . $herecurr);
+ }
+
# check for spinlock_t definitions without a comment.
if ($line =~ /^.\s*(struct\s+mutex|spinlock_t)\s+\S+;/) {
my $which = $1;
@@ -1027,14 +1067,14 @@ sub process {
}
}
# check of hardware specific defines
- if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@) {
+ if ($line =~ m@^.#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
CHK("architecture specific defines should be avoided\n" . $herecurr);
}
# check the location of the inline attribute, that it is between
# storage class and type.
- if ($line =~ /$Type\s+(?:inline|__always_inline)\b/ ||
- $line =~ /\b(?:inline|always_inline)\s+$Storage/) {
+ if ($line =~ /$Type\s+(?:inline|__always_inline|noinline)\b/ ||
+ $line =~ /\b(?:inline|__always_inline|noinline)\s+$Storage/) {
ERROR("inline keyword should sit between storage class and type\n" . $herecurr);
}