aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl84
-rwxr-xr-xscripts/get_maintainer.pl37
2 files changed, 96 insertions, 25 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 87bbb8bce9bf..bc4114f1ab30 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -2,7 +2,7 @@
2# (c) 2001, Dave Jones. <davej@redhat.com> (the file handling bit) 2# (c) 2001, Dave Jones. <davej@redhat.com> (the file handling bit)
3# (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit) 3# (c) 2005, Joel Schopp <jschopp@austin.ibm.com> (the ugly bit)
4# (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite) 4# (c) 2007,2008, Andy Whitcroft <apw@uk.ibm.com> (new conditions, test suite)
5# (c) 2008, Andy Whitcroft <apw@canonical.com> 5# (c) 2008,2009, Andy Whitcroft <apw@canonical.com>
6# Licensed under the terms of the GNU GPL License version 2 6# Licensed under the terms of the GNU GPL License version 2
7 7
8use strict; 8use strict;
@@ -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.29'; 13my $V = '0.30';
14 14
15use Getopt::Long qw(:config no_auto_abbrev); 15use Getopt::Long qw(:config no_auto_abbrev);
16 16
@@ -130,7 +130,10 @@ if ($tree) {
130 130
131my $emitted_corrupt = 0; 131my $emitted_corrupt = 0;
132 132
133our $Ident = qr{[A-Za-z_][A-Za-z\d_]*}; 133our $Ident = qr{
134 [A-Za-z_][A-Za-z\d_]*
135 (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)*
136 }x;
134our $Storage = qr{extern|static|asmlinkage}; 137our $Storage = qr{extern|static|asmlinkage};
135our $Sparse = qr{ 138our $Sparse = qr{
136 __user| 139 __user|
@@ -997,23 +1000,25 @@ sub annotate_values {
997 1000
998sub possible { 1001sub possible {
999 my ($possible, $line) = @_; 1002 my ($possible, $line) = @_;
1000 1003 my $notPermitted = qr{(?:
1001 print "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
1002 if ($possible !~ /(?:
1003 ^(?: 1004 ^(?:
1004 $Modifier| 1005 $Modifier|
1005 $Storage| 1006 $Storage|
1006 $Type| 1007 $Type|
1007 DEFINE_\S+| 1008 DEFINE_\S+
1009 )$|
1010 ^(?:
1008 goto| 1011 goto|
1009 return| 1012 return|
1010 case| 1013 case|
1011 else| 1014 else|
1012 asm|__asm__| 1015 asm|__asm__|
1013 do 1016 do
1014 )$| 1017 )(?:\s|$)|
1015 ^(?:typedef|struct|enum)\b 1018 ^(?:typedef|struct|enum)\b
1016 )/x) { 1019 )}x;
1020 warn "CHECK<$possible> ($line)\n" if ($dbg_possible > 2);
1021 if ($possible !~ $notPermitted) {
1017 # Check for modifiers. 1022 # Check for modifiers.
1018 $possible =~ s/\s*$Storage\s*//g; 1023 $possible =~ s/\s*$Storage\s*//g;
1019 $possible =~ s/\s*$Sparse\s*//g; 1024 $possible =~ s/\s*$Sparse\s*//g;
@@ -1022,8 +1027,10 @@ sub possible {
1022 } elsif ($possible =~ /\s/) { 1027 } elsif ($possible =~ /\s/) {
1023 $possible =~ s/\s*$Type\s*//g; 1028 $possible =~ s/\s*$Type\s*//g;
1024 for my $modifier (split(' ', $possible)) { 1029 for my $modifier (split(' ', $possible)) {
1025 warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible); 1030 if ($modifier !~ $notPermitted) {
1026 push(@modifierList, $modifier); 1031 warn "MODIFIER: $modifier ($possible) ($line)\n" if ($dbg_possible);
1032 push(@modifierList, $modifier);
1033 }
1027 } 1034 }
1028 1035
1029 } else { 1036 } else {
@@ -1138,6 +1145,7 @@ sub process {
1138 # suppression flags 1145 # suppression flags
1139 my %suppress_ifbraces; 1146 my %suppress_ifbraces;
1140 my %suppress_whiletrailers; 1147 my %suppress_whiletrailers;
1148 my %suppress_export;
1141 1149
1142 # Pre-scan the patch sanitizing the lines. 1150 # Pre-scan the patch sanitizing the lines.
1143 # Pre-scan the patch looking for any __setup documentation. 1151 # Pre-scan the patch looking for any __setup documentation.
@@ -1230,7 +1238,6 @@ sub process {
1230 $linenr++; 1238 $linenr++;
1231 1239
1232 my $rawline = $rawlines[$linenr - 1]; 1240 my $rawline = $rawlines[$linenr - 1];
1233 my $hunk_line = ($realcnt != 0);
1234 1241
1235#extract the line range in the file after the patch is applied 1242#extract the line range in the file after the patch is applied
1236 if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) { 1243 if ($line=~/^\@\@ -\d+(?:,\d+)? \+(\d+)(,(\d+))? \@\@/) {
@@ -1247,6 +1254,7 @@ sub process {
1247 1254
1248 %suppress_ifbraces = (); 1255 %suppress_ifbraces = ();
1249 %suppress_whiletrailers = (); 1256 %suppress_whiletrailers = ();
1257 %suppress_export = ();
1250 next; 1258 next;
1251 1259
1252# track the line number as we move through the hunk, note that 1260# track the line number as we move through the hunk, note that
@@ -1270,6 +1278,8 @@ sub process {
1270 $realcnt--; 1278 $realcnt--;
1271 } 1279 }
1272 1280
1281 my $hunk_line = ($realcnt != 0);
1282
1273#make up the handle for any error we report on this line 1283#make up the handle for any error we report on this line
1274 $prefix = "$filename:$realline: " if ($emacs && $file); 1284 $prefix = "$filename:$realline: " if ($emacs && $file);
1275 $prefix = "$filename:$linenr: " if ($emacs && !$file); 1285 $prefix = "$filename:$linenr: " if ($emacs && !$file);
@@ -1420,13 +1430,22 @@ sub process {
1420 } 1430 }
1421 1431
1422# Check for potential 'bare' types 1432# Check for potential 'bare' types
1423 my ($stat, $cond, $line_nr_next, $remain_next, $off_next); 1433 my ($stat, $cond, $line_nr_next, $remain_next, $off_next,
1434 $realline_next);
1424 if ($realcnt && $line =~ /.\s*\S/) { 1435 if ($realcnt && $line =~ /.\s*\S/) {
1425 ($stat, $cond, $line_nr_next, $remain_next, $off_next) = 1436 ($stat, $cond, $line_nr_next, $remain_next, $off_next) =
1426 ctx_statement_block($linenr, $realcnt, 0); 1437 ctx_statement_block($linenr, $realcnt, 0);
1427 $stat =~ s/\n./\n /g; 1438 $stat =~ s/\n./\n /g;
1428 $cond =~ s/\n./\n /g; 1439 $cond =~ s/\n./\n /g;
1429 1440
1441 # Find the real next line.
1442 $realline_next = $line_nr_next;
1443 if (defined $realline_next &&
1444 (!defined $lines[$realline_next - 1] ||
1445 substr($lines[$realline_next - 1], $off_next) =~ /^\s*$/)) {
1446 $realline_next++;
1447 }
1448
1430 my $s = $stat; 1449 my $s = $stat;
1431 $s =~ s/{.*$//s; 1450 $s =~ s/{.*$//s;
1432 1451
@@ -1661,8 +1680,8 @@ sub process {
1661 } 1680 }
1662 1681
1663# check for initialisation to aggregates open brace on the next line 1682# check for initialisation to aggregates open brace on the next line
1664 if ($prevline =~ /$Declare\s*$Ident\s*=\s*$/ && 1683 if ($line =~ /^.\s*{/ &&
1665 $line =~ /^.\s*{/) { 1684 $prevline =~ /(?:^|[^=])=\s*$/) {
1666 ERROR("that open brace { should be on the previous line\n" . $hereprev); 1685 ERROR("that open brace { should be on the previous line\n" . $hereprev);
1667 } 1686 }
1668 1687
@@ -1687,21 +1706,40 @@ sub process {
1687 $line =~ s@//.*@@; 1706 $line =~ s@//.*@@;
1688 $opline =~ s@//.*@@; 1707 $opline =~ s@//.*@@;
1689 1708
1690#EXPORT_SYMBOL should immediately follow its function closing }. 1709# EXPORT_SYMBOL should immediately follow the thing it is exporting, consider
1691 if (($line =~ /EXPORT_SYMBOL.*\((.*)\)/) || 1710# the whole statement.
1692 ($line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { 1711#print "APW <$lines[$realline_next - 1]>\n";
1712 if (defined $realline_next &&
1713 exists $lines[$realline_next - 1] &&
1714 !defined $suppress_export{$realline_next} &&
1715 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
1716 $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
1693 my $name = $1; 1717 my $name = $1;
1694 if ($prevline !~ /(?: 1718 if ($stat !~ /(?:
1695 ^.}| 1719 \n.}\s*$|
1696 ^.DEFINE_$Ident\(\Q$name\E\)| 1720 ^.DEFINE_$Ident\(\Q$name\E\)|
1697 ^.DECLARE_$Ident\(\Q$name\E\)| 1721 ^.DECLARE_$Ident\(\Q$name\E\)|
1698 ^.LIST_HEAD\(\Q$name\E\)| 1722 ^.LIST_HEAD\(\Q$name\E\)|
1699 ^.$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(| 1723 ^.(?:$Storage\s+)?$Type\s*\(\s*\*\s*\Q$name\E\s*\)\s*\(|
1700 \b\Q$name\E(?:\s+$Attribute)?\s*(?:;|=|\[) 1724 \b\Q$name\E(?:\s+$Attribute)*\s*(?:;|=|\[|\()
1701 )/x) { 1725 )/x) {
1702 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); 1726#print "FOO A<$lines[$realline_next - 1]> stat<$stat> name<$name>\n";
1727 $suppress_export{$realline_next} = 2;
1728 } else {
1729 $suppress_export{$realline_next} = 1;
1703 } 1730 }
1704 } 1731 }
1732 if (!defined $suppress_export{$linenr} &&
1733 $prevline =~ /^.\s*$/ &&
1734 ($line =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
1735 $line =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) {
1736#print "FOO B <$lines[$linenr - 1]>\n";
1737 $suppress_export{$linenr} = 2;
1738 }
1739 if (defined $suppress_export{$linenr} &&
1740 $suppress_export{$linenr} == 2) {
1741 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
1742 }
1705 1743
1706# check for external initialisers. 1744# check for external initialisers.
1707 if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) { 1745 if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) {
diff --git a/scripts/get_maintainer.pl b/scripts/get_maintainer.pl
index cdb44b63342e..102b76608f35 100755
--- a/scripts/get_maintainer.pl
+++ b/scripts/get_maintainer.pl
@@ -13,7 +13,7 @@
13use strict; 13use strict;
14 14
15my $P = $0; 15my $P = $0;
16my $V = '0.20'; 16my $V = '0.21';
17 17
18use Getopt::Long qw(:config no_auto_abbrev); 18use Getopt::Long qw(:config no_auto_abbrev);
19 19
@@ -37,6 +37,7 @@ my $scm = 0;
37my $web = 0; 37my $web = 0;
38my $subsystem = 0; 38my $subsystem = 0;
39my $status = 0; 39my $status = 0;
40my $keywords = 1;
40my $from_filename = 0; 41my $from_filename = 0;
41my $pattern_depth = 0; 42my $pattern_depth = 0;
42my $version = 0; 43my $version = 0;
@@ -84,6 +85,7 @@ if (!GetOptions(
84 'scm!' => \$scm, 85 'scm!' => \$scm,
85 'web!' => \$web, 86 'web!' => \$web,
86 'pattern-depth=i' => \$pattern_depth, 87 'pattern-depth=i' => \$pattern_depth,
88 'k|keywords!' => \$keywords,
87 'f|file' => \$from_filename, 89 'f|file' => \$from_filename,
88 'v|version' => \$version, 90 'v|version' => \$version,
89 'h|help' => \$help, 91 'h|help' => \$help,
@@ -132,6 +134,8 @@ if (!top_of_kernel_tree($lk_path)) {
132## Read MAINTAINERS for type/value pairs 134## Read MAINTAINERS for type/value pairs
133 135
134my @typevalue = (); 136my @typevalue = ();
137my %keyword_hash;
138
135open(MAINT, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n"; 139open(MAINT, "<${lk_path}MAINTAINERS") || die "$P: Can't open MAINTAINERS\n";
136while (<MAINT>) { 140while (<MAINT>) {
137 my $line = $_; 141 my $line = $_;
@@ -149,6 +153,8 @@ while (<MAINT>) {
149 if ((-d $value)) { 153 if ((-d $value)) {
150 $value =~ s@([^/])$@$1/@; 154 $value =~ s@([^/])$@$1/@;
151 } 155 }
156 } elsif ($type eq "K") {
157 $keyword_hash{@typevalue} = $value;
152 } 158 }
153 push(@typevalue, "$type:$value"); 159 push(@typevalue, "$type:$value");
154 } elsif (!/^(\s)*$/) { 160 } elsif (!/^(\s)*$/) {
@@ -188,6 +194,7 @@ if ($email_remove_duplicates) {
188 194
189my @files = (); 195my @files = ();
190my @range = (); 196my @range = ();
197my @keyword_tvi = ();
191 198
192foreach my $file (@ARGV) { 199foreach my $file (@ARGV) {
193 ##if $file is a directory and it lacks a trailing slash, add one 200 ##if $file is a directory and it lacks a trailing slash, add one
@@ -198,11 +205,24 @@ foreach my $file (@ARGV) {
198 } 205 }
199 if ($from_filename) { 206 if ($from_filename) {
200 push(@files, $file); 207 push(@files, $file);
208 if (-f $file && $keywords) {
209 open(FILE, "<$file") or die "$P: Can't open ${file}\n";
210 while (<FILE>) {
211 my $patch_line = $_;
212 foreach my $line (keys %keyword_hash) {
213 if ($patch_line =~ m/^.*$keyword_hash{$line}/x) {
214 push(@keyword_tvi, $line);
215 }
216 }
217 }
218 close(FILE);
219 }
201 } else { 220 } else {
202 my $file_cnt = @files; 221 my $file_cnt = @files;
203 my $lastfile; 222 my $lastfile;
204 open(PATCH, "<$file") or die "$P: Can't open ${file}\n"; 223 open(PATCH, "<$file") or die "$P: Can't open ${file}\n";
205 while (<PATCH>) { 224 while (<PATCH>) {
225 my $patch_line = $_;
206 if (m/^\+\+\+\s+(\S+)/) { 226 if (m/^\+\+\+\s+(\S+)/) {
207 my $filename = $1; 227 my $filename = $1;
208 $filename =~ s@^[^/]*/@@; 228 $filename =~ s@^[^/]*/@@;
@@ -213,6 +233,12 @@ foreach my $file (@ARGV) {
213 if ($email_git_blame) { 233 if ($email_git_blame) {
214 push(@range, "$lastfile:$1:$2"); 234 push(@range, "$lastfile:$1:$2");
215 } 235 }
236 } elsif ($keywords) {
237 foreach my $line (keys %keyword_hash) {
238 if ($patch_line =~ m/^[+-].*$keyword_hash{$line}/x) {
239 push(@keyword_tvi, $line);
240 }
241 }
216 } 242 }
217 } 243 }
218 close(PATCH); 244 close(PATCH);
@@ -286,6 +312,13 @@ foreach my $file (@files) {
286 } 312 }
287} 313}
288 314
315if ($keywords) {
316 @keyword_tvi = sort_and_uniq(@keyword_tvi);
317 foreach my $line (@keyword_tvi) {
318 add_categories($line);
319 }
320}
321
289if ($email) { 322if ($email) {
290 foreach my $chief (@penguin_chief) { 323 foreach my $chief (@penguin_chief) {
291 if ($chief =~ m/^(.*):(.*)/) { 324 if ($chief =~ m/^(.*):(.*)/) {
@@ -384,6 +417,7 @@ Output type options:
384 417
385Other options: 418Other options:
386 --pattern-depth => Number of pattern directory traversals (default: 0 (all)) 419 --pattern-depth => Number of pattern directory traversals (default: 0 (all))
420 --keywords => scan patch for keywords (default: 1 (on))
387 --version => show version 421 --version => show version
388 --help => show this help information 422 --help => show this help information
389 423
@@ -486,7 +520,6 @@ sub format_email {
486} 520}
487 521
488sub find_starting_index { 522sub find_starting_index {
489
490 my ($index) = @_; 523 my ($index) = @_;
491 524
492 while ($index > 0) { 525 while ($index > 0) {