aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl106
1 files changed, 87 insertions, 19 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2d5ece798c4..87bbb8bce9b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -10,7 +10,7 @@ use strict;
10my $P = $0; 10my $P = $0;
11$P =~ s@.*/@@g; 11$P =~ s@.*/@@g;
12 12
13my $V = '0.28'; 13my $V = '0.29';
14 14
15use Getopt::Long qw(:config no_auto_abbrev); 15use Getopt::Long qw(:config no_auto_abbrev);
16 16
@@ -28,6 +28,41 @@ my $mailback = 0;
28my $summary_file = 0; 28my $summary_file = 0;
29my $root; 29my $root;
30my %debug; 30my %debug;
31my $help = 0;
32
33sub help {
34 my ($exitcode) = @_;
35
36 print << "EOM";
37Usage: $P [OPTION]... [FILE]...
38Version: $V
39
40Options:
41 -q, --quiet quiet
42 --no-tree run without a kernel tree
43 --no-signoff do not check for 'Signed-off-by' line
44 --patch treat FILE as patchfile (default)
45 --emacs emacs compile window format
46 --terse one line per report
47 -f, --file treat FILE as regular source file
48 --subjective, --strict enable more subjective tests
49 --root=PATH PATH to the kernel tree root
50 --no-summary suppress the per-file summary
51 --mailback only produce a report in case of warnings/errors
52 --summary-file include the filename in summary
53 --debug KEY=[0|1] turn on/off debugging of KEY, where KEY is one of
54 'values', 'possible', 'type', and 'attr' (default
55 is all off)
56 --test-only=WORD report only warnings/errors containing WORD
57 literally
58 -h, --help, --version display this help and exit
59
60When FILE is - read standard input.
61EOM
62
63 exit($exitcode);
64}
65
31GetOptions( 66GetOptions(
32 'q|quiet+' => \$quiet, 67 'q|quiet+' => \$quiet,
33 'tree!' => \$tree, 68 'tree!' => \$tree,
@@ -35,7 +70,7 @@ GetOptions(
35 'patch!' => \$chk_patch, 70 'patch!' => \$chk_patch,
36 'emacs!' => \$emacs, 71 'emacs!' => \$emacs,
37 'terse!' => \$terse, 72 'terse!' => \$terse,
38 'file!' => \$file, 73 'f|file!' => \$file,
39 'subjective!' => \$check, 74 'subjective!' => \$check,
40 'strict!' => \$check, 75 'strict!' => \$check,
41 'root=s' => \$root, 76 'root=s' => \$root,
@@ -45,22 +80,16 @@ GetOptions(
45 80
46 'debug=s' => \%debug, 81 'debug=s' => \%debug,
47 'test-only=s' => \$tst_only, 82 'test-only=s' => \$tst_only,
48) or exit; 83 'h|help' => \$help,
84 'version' => \$help
85) or help(1);
86
87help(0) if ($help);
49 88
50my $exit = 0; 89my $exit = 0;
51 90
52if ($#ARGV < 0) { 91if ($#ARGV < 0) {
53 print "usage: $P [options] patchfile\n"; 92 print "$P: no input files\n";
54 print "version: $V\n";
55 print "options: -q => quiet\n";
56 print " --no-tree => run without a kernel tree\n";
57 print " --terse => one line per report\n";
58 print " --emacs => emacs compile window format\n";
59 print " --file => check a source file\n";
60 print " --strict => enable more subjective tests\n";
61 print " --root => path to the kernel tree root\n";
62 print " --no-summary => suppress the per-file summary\n";
63 print " --summary-file => include the filename in summary\n";
64 exit(1); 93 exit(1);
65} 94}
66 95
@@ -153,7 +182,7 @@ our $UTF8 = qr {
153}x; 182}x;
154 183
155our $typeTypedefs = qr{(?x: 184our $typeTypedefs = qr{(?x:
156 (?:__)?(?:u|s|be|le)(?:\d|\d\d)| 185 (?:__)?(?:u|s|be|le)(?:8|16|32|64)|
157 atomic_t 186 atomic_t
158)}; 187)};
159 188
@@ -356,6 +385,13 @@ sub sanitise_line {
356 $off++; 385 $off++;
357 next; 386 next;
358 } 387 }
388 if ($sanitise_quote eq '' && substr($line, $off, 2) eq '//') {
389 $sanitise_quote = '//';
390
391 substr($res, $off, 2, $sanitise_quote);
392 $off++;
393 next;
394 }
359 395
360 # A \ in a string means ignore the next character. 396 # A \ in a string means ignore the next character.
361 if (($sanitise_quote eq "'" || $sanitise_quote eq '"') && 397 if (($sanitise_quote eq "'" || $sanitise_quote eq '"') &&
@@ -379,6 +415,8 @@ sub sanitise_line {
379 #print "c<$c> SQ<$sanitise_quote>\n"; 415 #print "c<$c> SQ<$sanitise_quote>\n";
380 if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") { 416 if ($off != 0 && $sanitise_quote eq '*/' && $c ne "\t") {
381 substr($res, $off, 1, $;); 417 substr($res, $off, 1, $;);
418 } elsif ($off != 0 && $sanitise_quote eq '//' && $c ne "\t") {
419 substr($res, $off, 1, $;);
382 } elsif ($off != 0 && $sanitise_quote && $c ne "\t") { 420 } elsif ($off != 0 && $sanitise_quote && $c ne "\t") {
383 substr($res, $off, 1, 'X'); 421 substr($res, $off, 1, 'X');
384 } else { 422 } else {
@@ -386,6 +424,10 @@ sub sanitise_line {
386 } 424 }
387 } 425 }
388 426
427 if ($sanitise_quote eq '//') {
428 $sanitise_quote = '';
429 }
430
389 # The pathname on a #include may be surrounded by '<' and '>'. 431 # The pathname on a #include may be surrounded by '<' and '>'.
390 if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) { 432 if ($res =~ /^.\s*\#\s*include\s+\<(.*)\>/) {
391 my $clean = 'X' x length($1); 433 my $clean = 'X' x length($1);
@@ -1336,6 +1378,18 @@ sub process {
1336 WARN("adding a line without newline at end of file\n" . $herecurr); 1378 WARN("adding a line without newline at end of file\n" . $herecurr);
1337 } 1379 }
1338 1380
1381# Blackfin: use hi/lo macros
1382 if ($realfile =~ m@arch/blackfin/.*\.S$@) {
1383 if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) {
1384 my $herevet = "$here\n" . cat_vet($line) . "\n";
1385 ERROR("use the LO() macro, not (... & 0xFFFF)\n" . $herevet);
1386 }
1387 if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) {
1388 my $herevet = "$here\n" . cat_vet($line) . "\n";
1389 ERROR("use the HI() macro, not (... >> 16)\n" . $herevet);
1390 }
1391 }
1392
1339# check we are in a valid source file C or perl if not then ignore this hunk 1393# check we are in a valid source file C or perl if not then ignore this hunk
1340 next if ($realfile !~ /\.(h|c|pl)$/); 1394 next if ($realfile !~ /\.(h|c|pl)$/);
1341 1395
@@ -1355,6 +1409,16 @@ sub process {
1355 WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr); 1409 WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr);
1356 } 1410 }
1357 1411
1412# Blackfin: don't use __builtin_bfin_[cs]sync
1413 if ($line =~ /__builtin_bfin_csync/) {
1414 my $herevet = "$here\n" . cat_vet($line) . "\n";
1415 ERROR("use the CSYNC() macro in asm/blackfin.h\n" . $herevet);
1416 }
1417 if ($line =~ /__builtin_bfin_ssync/) {
1418 my $herevet = "$here\n" . cat_vet($line) . "\n";
1419 ERROR("use the SSYNC() macro in asm/blackfin.h\n" . $herevet);
1420 }
1421
1358# Check for potential 'bare' types 1422# Check for potential 'bare' types
1359 my ($stat, $cond, $line_nr_next, $remain_next, $off_next); 1423 my ($stat, $cond, $line_nr_next, $remain_next, $off_next);
1360 if ($realcnt && $line =~ /.\s*\S/) { 1424 if ($realcnt && $line =~ /.\s*\S/) {
@@ -1372,6 +1436,8 @@ sub process {
1372 # Ignore functions being called 1436 # Ignore functions being called
1373 } elsif ($s =~ /^.\s*$Ident\s*\(/s) { 1437 } elsif ($s =~ /^.\s*$Ident\s*\(/s) {
1374 1438
1439 } elsif ($s =~ /^.\s*else\b/s) {
1440
1375 # declarations always start with types 1441 # declarations always start with types
1376 } elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+?)\b(?:\s+$Sparse)?\s*\**\s*(?:$Ident|\(\*[^\)]*\))(?:\s*$Modifier)?\s*(?:;|=|,|\()/s) { 1442 } elsif ($prev_values eq 'E' && $s =~ /^.\s*(?:$Storage\s+)?(?:$Inline\s+)?(?:const\s+)?((?:\s*$Ident)+?)\b(?:\s+$Sparse)?\s*\**\s*(?:$Ident|\(\*[^\)]*\))(?:\s*$Modifier)?\s*(?:;|=|,|\()/s) {
1377 my $type = $1; 1443 my $type = $1;
@@ -1532,8 +1598,9 @@ sub process {
1532 $s =~ /^\s*#\s*?/ || 1598 $s =~ /^\s*#\s*?/ ||
1533 $s =~ /^\s*$Ident\s*:/) { 1599 $s =~ /^\s*$Ident\s*:/) {
1534 $continuation = ($s =~ /^.*?\\\n/) ? 1 : 0; 1600 $continuation = ($s =~ /^.*?\\\n/) ? 1 : 0;
1535 $s =~ s/^.*?\n//; 1601 if ($s =~ s/^.*?\n//) {
1536 $cond_lines++; 1602 $cond_lines++;
1603 }
1537 } 1604 }
1538 } 1605 }
1539 1606
@@ -1891,7 +1958,7 @@ sub process {
1891 # A unary '*' may be const 1958 # A unary '*' may be const
1892 1959
1893 } elsif ($ctx =~ /.xW/) { 1960 } elsif ($ctx =~ /.xW/) {
1894 ERROR("Aspace prohibited after that '$op' $at\n" . $hereptr); 1961 ERROR("space prohibited after that '$op' $at\n" . $hereptr);
1895 } 1962 }
1896 1963
1897 # unary ++ and unary -- are allowed no space on one side. 1964 # unary ++ and unary -- are allowed no space on one side.
@@ -2243,7 +2310,8 @@ sub process {
2243 DECLARE_PER_CPU| 2310 DECLARE_PER_CPU|
2244 DEFINE_PER_CPU| 2311 DEFINE_PER_CPU|
2245 __typeof__\(| 2312 __typeof__\(|
2246 \.$Ident\s*=\s* 2313 \.$Ident\s*=\s*|
2314 ^\"|\"$
2247 }x; 2315 }x;
2248 #print "REST<$rest> dstat<$dstat>\n"; 2316 #print "REST<$rest> dstat<$dstat>\n";
2249 if ($rest ne '') { 2317 if ($rest ne '') {