diff options
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 84 |
1 files changed, 61 insertions, 23 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 | ||
8 | use strict; | 8 | use strict; |
@@ -10,7 +10,7 @@ use strict; | |||
10 | my $P = $0; | 10 | my $P = $0; |
11 | $P =~ s@.*/@@g; | 11 | $P =~ s@.*/@@g; |
12 | 12 | ||
13 | my $V = '0.29'; | 13 | my $V = '0.30'; |
14 | 14 | ||
15 | use Getopt::Long qw(:config no_auto_abbrev); | 15 | use Getopt::Long qw(:config no_auto_abbrev); |
16 | 16 | ||
@@ -130,7 +130,10 @@ if ($tree) { | |||
130 | 130 | ||
131 | my $emitted_corrupt = 0; | 131 | my $emitted_corrupt = 0; |
132 | 132 | ||
133 | our $Ident = qr{[A-Za-z_][A-Za-z\d_]*}; | 133 | our $Ident = qr{ |
134 | [A-Za-z_][A-Za-z\d_]* | ||
135 | (?:\s*\#\#\s*[A-Za-z_][A-Za-z\d_]*)* | ||
136 | }x; | ||
134 | our $Storage = qr{extern|static|asmlinkage}; | 137 | our $Storage = qr{extern|static|asmlinkage}; |
135 | our $Sparse = qr{ | 138 | our $Sparse = qr{ |
136 | __user| | 139 | __user| |
@@ -997,23 +1000,25 @@ sub annotate_values { | |||
997 | 1000 | ||
998 | sub possible { | 1001 | sub 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*;/) { |