diff options
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 186 |
1 files changed, 160 insertions, 26 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index bd88f11b0953..90b54d4697fd 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -2,7 +2,7 @@ | |||
2 | # (c) 2001, Dave Jones. (the file handling bit) | 2 | # (c) 2001, Dave Jones. (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,2009, Andy Whitcroft <apw@canonical.com> | 5 | # (c) 2008-2010 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.30'; | 13 | my $V = '0.31'; |
14 | 14 | ||
15 | use Getopt::Long qw(:config no_auto_abbrev); | 15 | use Getopt::Long qw(:config no_auto_abbrev); |
16 | 16 | ||
@@ -103,6 +103,8 @@ for my $key (keys %debug) { | |||
103 | die "$@" if ($@); | 103 | die "$@" if ($@); |
104 | } | 104 | } |
105 | 105 | ||
106 | my $rpt_cleaners = 0; | ||
107 | |||
106 | if ($terse) { | 108 | if ($terse) { |
107 | $emacs = 1; | 109 | $emacs = 1; |
108 | $quiet++; | 110 | $quiet++; |
@@ -150,6 +152,20 @@ our $Sparse = qr{ | |||
150 | # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check | 152 | # We need \b after 'init' otherwise 'initconst' will cause a false positive in a check |
151 | our $Attribute = qr{ | 153 | our $Attribute = qr{ |
152 | const| | 154 | const| |
155 | __percpu| | ||
156 | __nocast| | ||
157 | __safe| | ||
158 | __bitwise__| | ||
159 | __packed__| | ||
160 | __packed2__| | ||
161 | __naked| | ||
162 | __maybe_unused| | ||
163 | __always_unused| | ||
164 | __noreturn| | ||
165 | __used| | ||
166 | __cold| | ||
167 | __noclone| | ||
168 | __deprecated| | ||
153 | __read_mostly| | 169 | __read_mostly| |
154 | __kprobes| | 170 | __kprobes| |
155 | __(?:mem|cpu|dev|)(?:initdata|initconst|init\b)| | 171 | __(?:mem|cpu|dev|)(?:initdata|initconst|init\b)| |
@@ -195,7 +211,7 @@ our $typeTypedefs = qr{(?x: | |||
195 | our $logFunctions = qr{(?x: | 211 | our $logFunctions = qr{(?x: |
196 | printk| | 212 | printk| |
197 | pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)| | 213 | pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)| |
198 | dev_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)| | 214 | (dev|netdev|netif)_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)| |
199 | WARN| | 215 | WARN| |
200 | panic | 216 | panic |
201 | )}; | 217 | )}; |
@@ -224,6 +240,12 @@ our @modifierList = ( | |||
224 | qr{fastcall}, | 240 | qr{fastcall}, |
225 | ); | 241 | ); |
226 | 242 | ||
243 | our $allowed_asm_includes = qr{(?x: | ||
244 | irq| | ||
245 | memory | ||
246 | )}; | ||
247 | # memory.h: ARM has a custom one | ||
248 | |||
227 | sub build_types { | 249 | sub build_types { |
228 | my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; | 250 | my $mods = "(?x: \n" . join("|\n ", @modifierList) . "\n)"; |
229 | my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; | 251 | my $all = "(?x: \n" . join("|\n ", @typeList) . "\n)"; |
@@ -552,6 +574,9 @@ sub ctx_statement_block { | |||
552 | $type = ($level != 0)? '{' : ''; | 574 | $type = ($level != 0)? '{' : ''; |
553 | 575 | ||
554 | if ($level == 0) { | 576 | if ($level == 0) { |
577 | if (substr($blk, $off + 1, 1) eq ';') { | ||
578 | $off++; | ||
579 | } | ||
555 | last; | 580 | last; |
556 | } | 581 | } |
557 | } | 582 | } |
@@ -666,15 +691,15 @@ sub ctx_block_get { | |||
666 | $blk .= $rawlines[$line]; | 691 | $blk .= $rawlines[$line]; |
667 | 692 | ||
668 | # Handle nested #if/#else. | 693 | # Handle nested #if/#else. |
669 | if ($rawlines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) { | 694 | if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) { |
670 | push(@stack, $level); | 695 | push(@stack, $level); |
671 | } elsif ($rawlines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) { | 696 | } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) { |
672 | $level = $stack[$#stack - 1]; | 697 | $level = $stack[$#stack - 1]; |
673 | } elsif ($rawlines[$line] =~ /^.\s*#\s*endif\b/) { | 698 | } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) { |
674 | $level = pop(@stack); | 699 | $level = pop(@stack); |
675 | } | 700 | } |
676 | 701 | ||
677 | foreach my $c (split(//, $rawlines[$line])) { | 702 | foreach my $c (split(//, $lines[$line])) { |
678 | ##print "C<$c>L<$level><$open$close>O<$off>\n"; | 703 | ##print "C<$c>L<$level><$open$close>O<$off>\n"; |
679 | if ($off > 0) { | 704 | if ($off > 0) { |
680 | $off--; | 705 | $off--; |
@@ -834,7 +859,12 @@ sub annotate_values { | |||
834 | $av_preprocessor = 0; | 859 | $av_preprocessor = 0; |
835 | } | 860 | } |
836 | 861 | ||
837 | } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\()/) { | 862 | } elsif ($cur =~ /^(\(\s*$Type\s*)\)/) { |
863 | print "CAST($1)\n" if ($dbg_values > 1); | ||
864 | push(@av_paren_type, $type); | ||
865 | $type = 'C'; | ||
866 | |||
867 | } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\(|\s*$)/) { | ||
838 | print "DECLARE($1)\n" if ($dbg_values > 1); | 868 | print "DECLARE($1)\n" if ($dbg_values > 1); |
839 | $type = 'T'; | 869 | $type = 'T'; |
840 | 870 | ||
@@ -1299,7 +1329,11 @@ sub process { | |||
1299 | $here = "#$realline: " if ($file); | 1329 | $here = "#$realline: " if ($file); |
1300 | 1330 | ||
1301 | # extract the filename as it passes | 1331 | # extract the filename as it passes |
1302 | if ($line=~/^\+\+\+\s+(\S+)/) { | 1332 | if ($line =~ /^diff --git.*?(\S+)$/) { |
1333 | $realfile = $1; | ||
1334 | $realfile =~ s@^([^/]*)/@@; | ||
1335 | |||
1336 | } elsif ($line =~ /^\+\+\+\s+(\S+)/) { | ||
1303 | $realfile = $1; | 1337 | $realfile = $1; |
1304 | $realfile =~ s@^([^/]*)/@@; | 1338 | $realfile =~ s@^([^/]*)/@@; |
1305 | 1339 | ||
@@ -1323,6 +1357,14 @@ sub process { | |||
1323 | 1357 | ||
1324 | $cnt_lines++ if ($realcnt != 0); | 1358 | $cnt_lines++ if ($realcnt != 0); |
1325 | 1359 | ||
1360 | # Check for incorrect file permissions | ||
1361 | if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) { | ||
1362 | my $permhere = $here . "FILE: $realfile\n"; | ||
1363 | if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) { | ||
1364 | ERROR("do not set execute permissions for source files\n" . $permhere); | ||
1365 | } | ||
1366 | } | ||
1367 | |||
1326 | #check the patch for a signoff: | 1368 | #check the patch for a signoff: |
1327 | if ($line =~ /^\s*signed-off-by:/i) { | 1369 | if ($line =~ /^\s*signed-off-by:/i) { |
1328 | # This is a signoff, if ugly, so do not double report. | 1370 | # This is a signoff, if ugly, so do not double report. |
@@ -1380,21 +1422,38 @@ sub process { | |||
1380 | } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { | 1422 | } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { |
1381 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; | 1423 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; |
1382 | ERROR("trailing whitespace\n" . $herevet); | 1424 | ERROR("trailing whitespace\n" . $herevet); |
1425 | $rpt_cleaners = 1; | ||
1383 | } | 1426 | } |
1384 | 1427 | ||
1385 | # check for Kconfig help text having a real description | 1428 | # check for Kconfig help text having a real description |
1429 | # Only applies when adding the entry originally, after that we do not have | ||
1430 | # sufficient context to determine whether it is indeed long enough. | ||
1386 | if ($realfile =~ /Kconfig/ && | 1431 | if ($realfile =~ /Kconfig/ && |
1387 | $line =~ /\+?\s*(---)?help(---)?$/) { | 1432 | $line =~ /\+\s*(?:---)?help(?:---)?$/) { |
1388 | my $length = 0; | 1433 | my $length = 0; |
1389 | for (my $l = $linenr; defined($lines[$l]); $l++) { | 1434 | my $cnt = $realcnt; |
1390 | my $f = $lines[$l]; | 1435 | my $ln = $linenr + 1; |
1436 | my $f; | ||
1437 | my $is_end = 0; | ||
1438 | while ($cnt > 0 && defined $lines[$ln - 1]) { | ||
1439 | $f = $lines[$ln - 1]; | ||
1440 | $cnt-- if ($lines[$ln - 1] !~ /^-/); | ||
1441 | $is_end = $lines[$ln - 1] =~ /^\+/; | ||
1442 | $ln++; | ||
1443 | |||
1444 | next if ($f =~ /^-/); | ||
1445 | $f =~ s/^.//; | ||
1391 | $f =~ s/#.*//; | 1446 | $f =~ s/#.*//; |
1392 | $f =~ s/^\s+//; | 1447 | $f =~ s/^\s+//; |
1393 | next if ($f =~ /^$/); | 1448 | next if ($f =~ /^$/); |
1394 | last if ($f =~ /^\s*config\s/); | 1449 | if ($f =~ /^\s*config\s/) { |
1450 | $is_end = 1; | ||
1451 | last; | ||
1452 | } | ||
1395 | $length++; | 1453 | $length++; |
1396 | } | 1454 | } |
1397 | WARN("please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($length < 4); | 1455 | WARN("please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_end && $length < 4); |
1456 | #print "is_end<$is_end> length<$length>\n"; | ||
1398 | } | 1457 | } |
1399 | 1458 | ||
1400 | # check we are in a valid source file if not then ignore this hunk | 1459 | # check we are in a valid source file if not then ignore this hunk |
@@ -1403,7 +1462,8 @@ sub process { | |||
1403 | #80 column limit | 1462 | #80 column limit |
1404 | if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && | 1463 | if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && |
1405 | $rawline !~ /^.\s*\*\s*\@$Ident\s/ && | 1464 | $rawline !~ /^.\s*\*\s*\@$Ident\s/ && |
1406 | $line !~ /^\+\s*$logFunctions\s*\(\s*(?:KERN_\S+\s*)?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ && | 1465 | !($line =~ /^\+\s*$logFunctions\s*\(\s*(?:(KERN_\S+\s*|[^"]*))?"[X\t]*"\s*(?:,|\)\s*;)\s*$/ || |
1466 | $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && | ||
1407 | $length > 80) | 1467 | $length > 80) |
1408 | { | 1468 | { |
1409 | WARN("line over 80 characters\n" . $herecurr); | 1469 | WARN("line over 80 characters\n" . $herecurr); |
@@ -1440,6 +1500,7 @@ sub process { | |||
1440 | $rawline =~ /^\+\s* \s*/) { | 1500 | $rawline =~ /^\+\s* \s*/) { |
1441 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; | 1501 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; |
1442 | ERROR("code indent should use tabs where possible\n" . $herevet); | 1502 | ERROR("code indent should use tabs where possible\n" . $herevet); |
1503 | $rpt_cleaners = 1; | ||
1443 | } | 1504 | } |
1444 | 1505 | ||
1445 | # check for space before tabs. | 1506 | # check for space before tabs. |
@@ -1448,6 +1509,16 @@ sub process { | |||
1448 | WARN("please, no space before tabs\n" . $herevet); | 1509 | WARN("please, no space before tabs\n" . $herevet); |
1449 | } | 1510 | } |
1450 | 1511 | ||
1512 | # check for spaces at the beginning of a line. | ||
1513 | # Exceptions: | ||
1514 | # 1) within comments | ||
1515 | # 2) indented preprocessor commands | ||
1516 | # 3) hanging labels | ||
1517 | if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) { | ||
1518 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; | ||
1519 | WARN("please, no spaces at the start of a line\n" . $herevet); | ||
1520 | } | ||
1521 | |||
1451 | # check we are in a valid C source file if not then ignore this hunk | 1522 | # check we are in a valid C source file if not then ignore this hunk |
1452 | next if ($realfile !~ /\.(h|c)$/); | 1523 | next if ($realfile !~ /\.(h|c)$/); |
1453 | 1524 | ||
@@ -1581,7 +1652,7 @@ sub process { | |||
1581 | 1652 | ||
1582 | if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { | 1653 | if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { |
1583 | ERROR("that open brace { should be on the previous line\n" . | 1654 | ERROR("that open brace { should be on the previous line\n" . |
1584 | "$here\n$ctx\n$lines[$ctx_ln - 1]\n"); | 1655 | "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); |
1585 | } | 1656 | } |
1586 | if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ && | 1657 | if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ && |
1587 | $ctx =~ /\)\s*\;\s*$/ && | 1658 | $ctx =~ /\)\s*\;\s*$/ && |
@@ -1590,7 +1661,7 @@ sub process { | |||
1590 | my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); | 1661 | my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); |
1591 | if ($nindent > $indent) { | 1662 | if ($nindent > $indent) { |
1592 | WARN("trailing semicolon indicates no statements, indent implies otherwise\n" . | 1663 | WARN("trailing semicolon indicates no statements, indent implies otherwise\n" . |
1593 | "$here\n$ctx\n$lines[$ctx_ln - 1]\n"); | 1664 | "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); |
1594 | } | 1665 | } |
1595 | } | 1666 | } |
1596 | } | 1667 | } |
@@ -1751,8 +1822,17 @@ sub process { | |||
1751 | !defined $suppress_export{$realline_next} && | 1822 | !defined $suppress_export{$realline_next} && |
1752 | ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ || | 1823 | ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ || |
1753 | $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { | 1824 | $lines[$realline_next - 1] =~ /EXPORT_UNUSED_SYMBOL.*\((.*)\)/)) { |
1825 | # Handle definitions which produce identifiers with | ||
1826 | # a prefix: | ||
1827 | # XXX(foo); | ||
1828 | # EXPORT_SYMBOL(something_foo); | ||
1754 | my $name = $1; | 1829 | my $name = $1; |
1755 | if ($stat !~ /(?: | 1830 | if ($stat =~ /^.([A-Z_]+)\s*\(\s*($Ident)/ && |
1831 | $name =~ /^${Ident}_$2/) { | ||
1832 | #print "FOO C name<$name>\n"; | ||
1833 | $suppress_export{$realline_next} = 1; | ||
1834 | |||
1835 | } elsif ($stat !~ /(?: | ||
1756 | \n.}\s*$| | 1836 | \n.}\s*$| |
1757 | ^.DEFINE_$Ident\(\Q$name\E\)| | 1837 | ^.DEFINE_$Ident\(\Q$name\E\)| |
1758 | ^.DECLARE_$Ident\(\Q$name\E\)| | 1838 | ^.DECLARE_$Ident\(\Q$name\E\)| |
@@ -1778,9 +1858,9 @@ sub process { | |||
1778 | WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); | 1858 | WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); |
1779 | } | 1859 | } |
1780 | 1860 | ||
1781 | # check for external initialisers. | 1861 | # check for global initialisers. |
1782 | if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) { | 1862 | if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) { |
1783 | ERROR("do not initialise externals to 0 or NULL\n" . | 1863 | ERROR("do not initialise globals to 0 or NULL\n" . |
1784 | $herecurr); | 1864 | $herecurr); |
1785 | } | 1865 | } |
1786 | # check for static initialisers. | 1866 | # check for static initialisers. |
@@ -1789,6 +1869,23 @@ sub process { | |||
1789 | $herecurr); | 1869 | $herecurr); |
1790 | } | 1870 | } |
1791 | 1871 | ||
1872 | # check for static const char * arrays. | ||
1873 | if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) { | ||
1874 | WARN("static const char * array should probably be static const char * const\n" . | ||
1875 | $herecurr); | ||
1876 | } | ||
1877 | |||
1878 | # check for static char foo[] = "bar" declarations. | ||
1879 | if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) { | ||
1880 | WARN("static char array declaration should probably be static const char\n" . | ||
1881 | $herecurr); | ||
1882 | } | ||
1883 | |||
1884 | # check for declarations of struct pci_device_id | ||
1885 | if ($line =~ /\bstruct\s+pci_device_id\s+\w+\s*\[\s*\]\s*\=\s*\{/) { | ||
1886 | WARN("Use DEFINE_PCI_DEVICE_TABLE for struct pci_device_id\n" . $herecurr); | ||
1887 | } | ||
1888 | |||
1792 | # check for new typedefs, only function parameters and sparse annotations | 1889 | # check for new typedefs, only function parameters and sparse annotations |
1793 | # make sense. | 1890 | # make sense. |
1794 | if ($line =~ /\btypedef\s/ && | 1891 | if ($line =~ /\btypedef\s/ && |
@@ -1882,6 +1979,11 @@ sub process { | |||
1882 | ERROR("open brace '{' following $1 go on the same line\n" . $hereprev); | 1979 | ERROR("open brace '{' following $1 go on the same line\n" . $hereprev); |
1883 | } | 1980 | } |
1884 | 1981 | ||
1982 | # missing space after union, struct or enum definition | ||
1983 | if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) { | ||
1984 | WARN("missing space after $1 definition\n" . $herecurr); | ||
1985 | } | ||
1986 | |||
1885 | # check for spacing round square brackets; allowed: | 1987 | # check for spacing round square brackets; allowed: |
1886 | # 1. with a type on the left -- int [] a; | 1988 | # 1. with a type on the left -- int [] a; |
1887 | # 2. at the beginning of a line for slice initialisers -- [0...10] = 5, | 1989 | # 2. at the beginning of a line for slice initialisers -- [0...10] = 5, |
@@ -2159,21 +2261,29 @@ sub process { | |||
2159 | my $value = $2; | 2261 | my $value = $2; |
2160 | 2262 | ||
2161 | # Flatten any parentheses | 2263 | # Flatten any parentheses |
2162 | $value =~ s/\)\(/\) \(/g; | 2264 | $value =~ s/\(/ \(/g; |
2265 | $value =~ s/\)/\) /g; | ||
2163 | while ($value =~ s/\[[^\{\}]*\]/1/ || | 2266 | while ($value =~ s/\[[^\{\}]*\]/1/ || |
2164 | $value !~ /(?:$Ident|-?$Constant)\s* | 2267 | $value !~ /(?:$Ident|-?$Constant)\s* |
2165 | $Compare\s* | 2268 | $Compare\s* |
2166 | (?:$Ident|-?$Constant)/x && | 2269 | (?:$Ident|-?$Constant)/x && |
2167 | $value =~ s/\([^\(\)]*\)/1/) { | 2270 | $value =~ s/\([^\(\)]*\)/1/) { |
2168 | } | 2271 | } |
2169 | 2272 | #print "value<$value>\n"; | |
2170 | if ($value =~ /^(?:$Ident|-?$Constant)$/) { | 2273 | if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) { |
2171 | ERROR("return is not a function, parentheses are not required\n" . $herecurr); | 2274 | ERROR("return is not a function, parentheses are not required\n" . $herecurr); |
2172 | 2275 | ||
2173 | } elsif ($spacing !~ /\s+/) { | 2276 | } elsif ($spacing !~ /\s+/) { |
2174 | ERROR("space required before the open parenthesis '('\n" . $herecurr); | 2277 | ERROR("space required before the open parenthesis '('\n" . $herecurr); |
2175 | } | 2278 | } |
2176 | } | 2279 | } |
2280 | # Return of what appears to be an errno should normally be -'ve | ||
2281 | if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { | ||
2282 | my $name = $1; | ||
2283 | if ($name ne 'EOF' && $name ne 'ERROR') { | ||
2284 | WARN("return of an errno should typically be -ve (return -$1)\n" . $herecurr); | ||
2285 | } | ||
2286 | } | ||
2177 | 2287 | ||
2178 | # Need a space before open parenthesis after if, while etc | 2288 | # Need a space before open parenthesis after if, while etc |
2179 | if ($line=~/\b(if|while|for|switch)\(/) { | 2289 | if ($line=~/\b(if|while|for|switch)\(/) { |
@@ -2308,7 +2418,7 @@ sub process { | |||
2308 | my $checkfile = "include/linux/$file"; | 2418 | my $checkfile = "include/linux/$file"; |
2309 | if (-f "$root/$checkfile" && | 2419 | if (-f "$root/$checkfile" && |
2310 | $realfile ne $checkfile && | 2420 | $realfile ne $checkfile && |
2311 | $1 ne 'irq') | 2421 | $1 !~ /$allowed_asm_includes/) |
2312 | { | 2422 | { |
2313 | if ($realfile =~ m{^arch/}) { | 2423 | if ($realfile =~ m{^arch/}) { |
2314 | CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); | 2424 | CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); |
@@ -2392,8 +2502,8 @@ sub process { | |||
2392 | \.$Ident\s*=\s*| | 2502 | \.$Ident\s*=\s*| |
2393 | ^\"|\"$ | 2503 | ^\"|\"$ |
2394 | }x; | 2504 | }x; |
2395 | #print "REST<$rest> dstat<$dstat>\n"; | 2505 | #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n"; |
2396 | if ($rest ne '') { | 2506 | if ($rest ne '' && $rest ne ',') { |
2397 | if ($rest !~ /while\s*\(/ && | 2507 | if ($rest !~ /while\s*\(/ && |
2398 | $dstat !~ /$exceptions/) | 2508 | $dstat !~ /$exceptions/) |
2399 | { | 2509 | { |
@@ -2570,6 +2680,21 @@ sub process { | |||
2570 | } | 2680 | } |
2571 | } | 2681 | } |
2572 | 2682 | ||
2683 | # prefer usleep_range over udelay | ||
2684 | if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) { | ||
2685 | # ignore udelay's < 10, however | ||
2686 | if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) { | ||
2687 | CHK("usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line); | ||
2688 | } | ||
2689 | } | ||
2690 | |||
2691 | # warn about unexpectedly long msleep's | ||
2692 | if ($line =~ /\bmsleep\s*\((\d+)\);/) { | ||
2693 | if ($1 < 20) { | ||
2694 | WARN("msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line); | ||
2695 | } | ||
2696 | } | ||
2697 | |||
2573 | # warn about #ifdefs in C files | 2698 | # warn about #ifdefs in C files |
2574 | # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { | 2699 | # if ($line =~ /^.\s*\#\s*if(|n)def/ && ($realfile =~ /\.c$/)) { |
2575 | # print "#ifdef in C files should be avoided\n"; | 2700 | # print "#ifdef in C files should be avoided\n"; |
@@ -2807,6 +2932,15 @@ sub process { | |||
2807 | print "\n" if ($quiet == 0); | 2932 | print "\n" if ($quiet == 0); |
2808 | } | 2933 | } |
2809 | 2934 | ||
2935 | if ($quiet == 0) { | ||
2936 | # If there were whitespace errors which cleanpatch can fix | ||
2937 | # then suggest that. | ||
2938 | if ($rpt_cleaners) { | ||
2939 | print "NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or\n"; | ||
2940 | print " scripts/cleanfile\n\n"; | ||
2941 | } | ||
2942 | } | ||
2943 | |||
2810 | if ($clean == 1 && $quiet == 0) { | 2944 | if ($clean == 1 && $quiet == 0) { |
2811 | print "$vname has no obvious style problems and is ready for submission.\n" | 2945 | print "$vname has no obvious style problems and is ready for submission.\n" |
2812 | } | 2946 | } |