aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl214
1 files changed, 169 insertions, 45 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2039acdf5122..b0aa2c680593 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
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.30'; 13my $V = '0.31';
14 14
15use Getopt::Long qw(:config no_auto_abbrev); 15use 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
106my $rpt_cleaners = 0;
107
106if ($terse) { 108if ($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
151our $Attribute = qr{ 153our $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)|
@@ -194,10 +210,10 @@ our $typeTypedefs = qr{(?x:
194 210
195our $logFunctions = qr{(?x: 211our $logFunctions = qr{(?x:
196 printk| 212 printk|
197 pr_(debug|dbg|vdbg|devel|info|warning|err|notice|alert|crit|emerg|cont)| 213 [a-z]+_(emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)|
198 (dev|netdev|netif)_(printk|dbg|vdbg|info|warn|err|notice|alert|crit|emerg|WARN)|
199 WARN| 214 WARN|
200 panic 215 panic|
216 MODULE_[A-Z_]+
201)}; 217)};
202 218
203our @typeList = ( 219our @typeList = (
@@ -675,15 +691,15 @@ sub ctx_block_get {
675 $blk .= $rawlines[$line]; 691 $blk .= $rawlines[$line];
676 692
677 # Handle nested #if/#else. 693 # Handle nested #if/#else.
678 if ($rawlines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) { 694 if ($lines[$line] =~ /^.\s*#\s*(?:ifndef|ifdef|if)\s/) {
679 push(@stack, $level); 695 push(@stack, $level);
680 } elsif ($rawlines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) { 696 } elsif ($lines[$line] =~ /^.\s*#\s*(?:else|elif)\b/) {
681 $level = $stack[$#stack - 1]; 697 $level = $stack[$#stack - 1];
682 } elsif ($rawlines[$line] =~ /^.\s*#\s*endif\b/) { 698 } elsif ($lines[$line] =~ /^.\s*#\s*endif\b/) {
683 $level = pop(@stack); 699 $level = pop(@stack);
684 } 700 }
685 701
686 foreach my $c (split(//, $rawlines[$line])) { 702 foreach my $c (split(//, $lines[$line])) {
687 ##print "C<$c>L<$level><$open$close>O<$off>\n"; 703 ##print "C<$c>L<$level><$open$close>O<$off>\n";
688 if ($off > 0) { 704 if ($off > 0) {
689 $off--; 705 $off--;
@@ -843,7 +859,12 @@ sub annotate_values {
843 $av_preprocessor = 0; 859 $av_preprocessor = 0;
844 } 860 }
845 861
846 } elsif ($cur =~ /^($Type)\s*(?:$Ident|,|\)|\()/) { 862 } elsif ($cur =~ /^(\(\s*$Type\s*)\)/ && $av_pending eq '_') {
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*$)/) {
847 print "DECLARE($1)\n" if ($dbg_values > 1); 868 print "DECLARE($1)\n" if ($dbg_values > 1);
848 $type = 'T'; 869 $type = 'T';
849 870
@@ -1308,7 +1329,11 @@ sub process {
1308 $here = "#$realline: " if ($file); 1329 $here = "#$realline: " if ($file);
1309 1330
1310 # extract the filename as it passes 1331 # extract the filename as it passes
1311 if ($line=~/^\+\+\+\s+(\S+)/) { 1332 if ($line =~ /^diff --git.*?(\S+)$/) {
1333 $realfile = $1;
1334 $realfile =~ s@^([^/]*)/@@;
1335
1336 } elsif ($line =~ /^\+\+\+\s+(\S+)/) {
1312 $realfile = $1; 1337 $realfile = $1;
1313 $realfile =~ s@^([^/]*)/@@; 1338 $realfile =~ s@^([^/]*)/@@;
1314 1339
@@ -1332,6 +1357,14 @@ sub process {
1332 1357
1333 $cnt_lines++ if ($realcnt != 0); 1358 $cnt_lines++ if ($realcnt != 0);
1334 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
1335#check the patch for a signoff: 1368#check the patch for a signoff:
1336 if ($line =~ /^\s*signed-off-by:/i) { 1369 if ($line =~ /^\s*signed-off-by:/i) {
1337 # This is a signoff, if ugly, so do not double report. 1370 # This is a signoff, if ugly, so do not double report.
@@ -1389,21 +1422,38 @@ sub process {
1389 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { 1422 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
1390 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1423 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1391 ERROR("trailing whitespace\n" . $herevet); 1424 ERROR("trailing whitespace\n" . $herevet);
1425 $rpt_cleaners = 1;
1392 } 1426 }
1393 1427
1394# 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.
1395 if ($realfile =~ /Kconfig/ && 1431 if ($realfile =~ /Kconfig/ &&
1396 $line =~ /\+?\s*(---)?help(---)?$/) { 1432 $line =~ /\+\s*(?:---)?help(?:---)?$/) {
1397 my $length = 0; 1433 my $length = 0;
1398 for (my $l = $linenr; defined($lines[$l]); $l++) { 1434 my $cnt = $realcnt;
1399 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/^.//;
1400 $f =~ s/#.*//; 1446 $f =~ s/#.*//;
1401 $f =~ s/^\s+//; 1447 $f =~ s/^\s+//;
1402 next if ($f =~ /^$/); 1448 next if ($f =~ /^$/);
1403 last if ($f =~ /^\s*config\s/); 1449 if ($f =~ /^\s*config\s/) {
1450 $is_end = 1;
1451 last;
1452 }
1404 $length++; 1453 $length++;
1405 } 1454 }
1406 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";
1407 } 1457 }
1408 1458
1409# 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
@@ -1412,7 +1462,7 @@ sub process {
1412#80 column limit 1462#80 column limit
1413 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ && 1463 if ($line =~ /^\+/ && $prevrawline !~ /\/\*\*/ &&
1414 $rawline !~ /^.\s*\*\s*\@$Ident\s/ && 1464 $rawline !~ /^.\s*\*\s*\@$Ident\s/ &&
1415 !($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*$/ ||
1416 $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && 1466 $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
1417 $length > 80) 1467 $length > 80)
1418 { 1468 {
@@ -1450,6 +1500,7 @@ sub process {
1450 $rawline =~ /^\+\s* \s*/) { 1500 $rawline =~ /^\+\s* \s*/) {
1451 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1501 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1452 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;
1453 } 1504 }
1454 1505
1455# check for space before tabs. 1506# check for space before tabs.
@@ -1459,10 +1510,13 @@ sub process {
1459 } 1510 }
1460 1511
1461# check for spaces at the beginning of a line. 1512# check for spaces at the beginning of a line.
1462 if ($rawline =~ /^\+ / && $rawline !~ /\+ +\*/) { 1513# Exceptions:
1514# 1) within comments
1515# 2) indented preprocessor commands
1516# 3) hanging labels
1517 if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) {
1463 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1518 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1464 WARN("please, no space for starting a line, \ 1519 WARN("please, no spaces at the start of a line\n" . $herevet);
1465 excluding comments\n" . $herevet);
1466 } 1520 }
1467 1521
1468# 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
@@ -1598,7 +1652,7 @@ sub process {
1598 1652
1599 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*{/) {
1600 ERROR("that open brace { should be on the previous line\n" . 1654 ERROR("that open brace { should be on the previous line\n" .
1601 "$here\n$ctx\n$lines[$ctx_ln - 1]\n"); 1655 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
1602 } 1656 }
1603 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ && 1657 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
1604 $ctx =~ /\)\s*\;\s*$/ && 1658 $ctx =~ /\)\s*\;\s*$/ &&
@@ -1607,7 +1661,7 @@ sub process {
1607 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); 1661 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
1608 if ($nindent > $indent) { 1662 if ($nindent > $indent) {
1609 WARN("trailing semicolon indicates no statements, indent implies otherwise\n" . 1663 WARN("trailing semicolon indicates no statements, indent implies otherwise\n" .
1610 "$here\n$ctx\n$lines[$ctx_ln - 1]\n"); 1664 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
1611 } 1665 }
1612 } 1666 }
1613 } 1667 }
@@ -1768,8 +1822,17 @@ sub process {
1768 !defined $suppress_export{$realline_next} && 1822 !defined $suppress_export{$realline_next} &&
1769 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ || 1823 ($lines[$realline_next - 1] =~ /EXPORT_SYMBOL.*\((.*)\)/ ||
1770 $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);
1771 my $name = $1; 1829 my $name = $1;
1772 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 !~ /(?:
1773 \n.}\s*$| 1836 \n.}\s*$|
1774 ^.DEFINE_$Ident\(\Q$name\E\)| 1837 ^.DEFINE_$Ident\(\Q$name\E\)|
1775 ^.DECLARE_$Ident\(\Q$name\E\)| 1838 ^.DECLARE_$Ident\(\Q$name\E\)|
@@ -1806,6 +1869,23 @@ sub process {
1806 $herecurr); 1869 $herecurr);
1807 } 1870 }
1808 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
1809# check for new typedefs, only function parameters and sparse annotations 1889# check for new typedefs, only function parameters and sparse annotations
1810# make sense. 1890# make sense.
1811 if ($line =~ /\btypedef\s/ && 1891 if ($line =~ /\btypedef\s/ &&
@@ -1863,16 +1943,21 @@ sub process {
1863 WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); 1943 WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
1864 } 1944 }
1865 1945
1946# check for uses of printk_ratelimit
1947 if ($line =~ /\bprintk_ratelimit\s*\(/) {
1948 WARN("Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
1949 }
1950
1866# printk should use KERN_* levels. Note that follow on printk's on the 1951# printk should use KERN_* levels. Note that follow on printk's on the
1867# same line do not need a level, so we use the current block context 1952# same line do not need a level, so we use the current block context
1868# to try and find and validate the current printk. In summary the current 1953# to try and find and validate the current printk. In summary the current
1869# printk includes all preceeding printk's which have no newline on the end. 1954# printk includes all preceding printk's which have no newline on the end.
1870# we assume the first bad printk is the one to report. 1955# we assume the first bad printk is the one to report.
1871 if ($line =~ /\bprintk\((?!KERN_)\s*"/) { 1956 if ($line =~ /\bprintk\((?!KERN_)\s*"/) {
1872 my $ok = 0; 1957 my $ok = 0;
1873 for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) { 1958 for (my $ln = $linenr - 1; $ln >= $first_line; $ln--) {
1874 #print "CHECK<$lines[$ln - 1]\n"; 1959 #print "CHECK<$lines[$ln - 1]\n";
1875 # we have a preceeding printk if it ends 1960 # we have a preceding printk if it ends
1876 # with "\n" ignore it, else it is to blame 1961 # with "\n" ignore it, else it is to blame
1877 if ($lines[$ln - 1] =~ m{\bprintk\(}) { 1962 if ($lines[$ln - 1] =~ m{\bprintk\(}) {
1878 if ($rawlines[$ln - 1] !~ m{\\n"}) { 1963 if ($rawlines[$ln - 1] !~ m{\\n"}) {
@@ -1899,6 +1984,11 @@ sub process {
1899 ERROR("open brace '{' following $1 go on the same line\n" . $hereprev); 1984 ERROR("open brace '{' following $1 go on the same line\n" . $hereprev);
1900 } 1985 }
1901 1986
1987# missing space after union, struct or enum definition
1988 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) {
1989 WARN("missing space after $1 definition\n" . $herecurr);
1990 }
1991
1902# check for spacing round square brackets; allowed: 1992# check for spacing round square brackets; allowed:
1903# 1. with a type on the left -- int [] a; 1993# 1. with a type on the left -- int [] a;
1904# 2. at the beginning of a line for slice initialisers -- [0...10] = 5, 1994# 2. at the beginning of a line for slice initialisers -- [0...10] = 5,
@@ -1959,7 +2049,7 @@ sub process {
1959 for (my $n = 0; $n < $#elements; $n += 2) { 2049 for (my $n = 0; $n < $#elements; $n += 2) {
1960 $off += length($elements[$n]); 2050 $off += length($elements[$n]);
1961 2051
1962 # Pick up the preceeding and succeeding characters. 2052 # Pick up the preceding and succeeding characters.
1963 my $ca = substr($opline, 0, $off); 2053 my $ca = substr($opline, 0, $off);
1964 my $cc = ''; 2054 my $cc = '';
1965 if (length($opline) >= ($off + length($elements[$n + 1]))) { 2055 if (length($opline) >= ($off + length($elements[$n + 1]))) {
@@ -2176,21 +2266,29 @@ sub process {
2176 my $value = $2; 2266 my $value = $2;
2177 2267
2178 # Flatten any parentheses 2268 # Flatten any parentheses
2179 $value =~ s/\)\(/\) \(/g; 2269 $value =~ s/\(/ \(/g;
2270 $value =~ s/\)/\) /g;
2180 while ($value =~ s/\[[^\{\}]*\]/1/ || 2271 while ($value =~ s/\[[^\{\}]*\]/1/ ||
2181 $value !~ /(?:$Ident|-?$Constant)\s* 2272 $value !~ /(?:$Ident|-?$Constant)\s*
2182 $Compare\s* 2273 $Compare\s*
2183 (?:$Ident|-?$Constant)/x && 2274 (?:$Ident|-?$Constant)/x &&
2184 $value =~ s/\([^\(\)]*\)/1/) { 2275 $value =~ s/\([^\(\)]*\)/1/) {
2185 } 2276 }
2186 2277#print "value<$value>\n";
2187 if ($value =~ /^(?:$Ident|-?$Constant)$/) { 2278 if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) {
2188 ERROR("return is not a function, parentheses are not required\n" . $herecurr); 2279 ERROR("return is not a function, parentheses are not required\n" . $herecurr);
2189 2280
2190 } elsif ($spacing !~ /\s+/) { 2281 } elsif ($spacing !~ /\s+/) {
2191 ERROR("space required before the open parenthesis '('\n" . $herecurr); 2282 ERROR("space required before the open parenthesis '('\n" . $herecurr);
2192 } 2283 }
2193 } 2284 }
2285# Return of what appears to be an errno should normally be -'ve
2286 if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
2287 my $name = $1;
2288 if ($name ne 'EOF' && $name ne 'ERROR') {
2289 WARN("return of an errno should typically be -ve (return -$1)\n" . $herecurr);
2290 }
2291 }
2194 2292
2195# Need a space before open parenthesis after if, while etc 2293# Need a space before open parenthesis after if, while etc
2196 if ($line=~/\b(if|while|for|switch)\(/) { 2294 if ($line=~/\b(if|while|for|switch)\(/) {
@@ -2409,8 +2507,8 @@ sub process {
2409 \.$Ident\s*=\s*| 2507 \.$Ident\s*=\s*|
2410 ^\"|\"$ 2508 ^\"|\"$
2411 }x; 2509 }x;
2412 #print "REST<$rest> dstat<$dstat>\n"; 2510 #print "REST<$rest> dstat<$dstat> ctx<$ctx>\n";
2413 if ($rest ne '') { 2511 if ($rest ne '' && $rest ne ',') {
2414 if ($rest !~ /while\s*\(/ && 2512 if ($rest !~ /while\s*\(/ &&
2415 $dstat !~ /$exceptions/) 2513 $dstat !~ /$exceptions/)
2416 { 2514 {
@@ -2561,11 +2659,6 @@ sub process {
2561 WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); 2659 WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
2562 } 2660 }
2563 2661
2564# SPIN_LOCK_UNLOCKED & RW_LOCK_UNLOCKED are deprecated
2565 if ($line =~ /\b(SPIN_LOCK_UNLOCKED|RW_LOCK_UNLOCKED)/) {
2566 ERROR("Use of $1 is deprecated: see Documentation/spinlocks.txt\n" . $herecurr);
2567 }
2568
2569# warn about #if 0 2662# warn about #if 0
2570 if ($line =~ /^.\s*\#\s*if\s+0\b/) { 2663 if ($line =~ /^.\s*\#\s*if\s+0\b/) {
2571 CHK("if this code is redundant consider removing it\n" . 2664 CHK("if this code is redundant consider removing it\n" .
@@ -2650,11 +2743,21 @@ sub process {
2650 WARN("plain inline is preferred over $1\n" . $herecurr); 2743 WARN("plain inline is preferred over $1\n" . $herecurr);
2651 } 2744 }
2652 2745
2746# Check for __attribute__ packed, prefer __packed
2747 if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
2748 WARN("__packed is preferred over __attribute__((packed))\n" . $herecurr);
2749 }
2750
2653# check for sizeof(&) 2751# check for sizeof(&)
2654 if ($line =~ /\bsizeof\s*\(\s*\&/) { 2752 if ($line =~ /\bsizeof\s*\(\s*\&/) {
2655 WARN("sizeof(& should be avoided\n" . $herecurr); 2753 WARN("sizeof(& should be avoided\n" . $herecurr);
2656 } 2754 }
2657 2755
2756# check for line continuations in quoted strings with odd counts of "
2757 if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) {
2758 WARN("Avoid line continuations in quoted strings\n" . $herecurr);
2759 }
2760
2658# check for new externs in .c files. 2761# check for new externs in .c files.
2659 if ($realfile =~ /\.c$/ && defined $stat && 2762 if ($realfile =~ /\.c$/ && defined $stat &&
2660 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s) 2763 $stat =~ /^.\s*(?:extern\s+)?$Type\s+($Ident)(\s*)\(/s)
@@ -2692,27 +2795,28 @@ sub process {
2692 } 2795 }
2693 2796
2694# check for pointless casting of kmalloc return 2797# check for pointless casting of kmalloc return
2695 if ($line =~ /\*\s*\)\s*k[czm]alloc\b/) { 2798 if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) {
2696 WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); 2799 WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
2697 } 2800 }
2698 2801
2802# check for multiple semicolons
2803 if ($line =~ /;\s*;\s*$/) {
2804 WARN("Statements terminations use 1 semicolon\n" . $herecurr);
2805 }
2806
2699# check for gcc specific __FUNCTION__ 2807# check for gcc specific __FUNCTION__
2700 if ($line =~ /__FUNCTION__/) { 2808 if ($line =~ /__FUNCTION__/) {
2701 WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr); 2809 WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr);
2702 } 2810 }
2703 2811
2704# check for semaphores used as mutexes 2812# check for semaphores initialized locked
2705 if ($line =~ /^.\s*(DECLARE_MUTEX|init_MUTEX)\s*\(/) { 2813 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
2706 WARN("mutexes are preferred for single holder semaphores\n" . $herecurr);
2707 }
2708# check for semaphores used as mutexes
2709 if ($line =~ /^.\s*init_MUTEX_LOCKED\s*\(/) {
2710 WARN("consider using a completion\n" . $herecurr); 2814 WARN("consider using a completion\n" . $herecurr);
2711 2815
2712 } 2816 }
2713# recommend strict_strto* over simple_strto* 2817# recommend kstrto* over simple_strto*
2714 if ($line =~ /\bsimple_(strto.*?)\s*\(/) { 2818 if ($line =~ /\bsimple_(strto.*?)\s*\(/) {
2715 WARN("consider using strict_$1 in preference to simple_$1\n" . $herecurr); 2819 WARN("consider using kstrto* in preference to simple_$1\n" . $herecurr);
2716 } 2820 }
2717# check for __initcall(), use device_initcall() explicitly please 2821# check for __initcall(), use device_initcall() explicitly please
2718 if ($line =~ /^.\s*__initcall\s*\(/) { 2822 if ($line =~ /^.\s*__initcall\s*\(/) {
@@ -2803,6 +2907,16 @@ sub process {
2803 ERROR("lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr); 2907 ERROR("lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
2804 } 2908 }
2805 } 2909 }
2910
2911 if ($line =~ /debugfs_create_file.*S_IWUGO/ ||
2912 $line =~ /DEVICE_ATTR.*S_IWUGO/ ) {
2913 WARN("Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
2914 }
2915
2916 # Check for memset with swapped arguments
2917 if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) {
2918 ERROR("memset size is 3rd argument, not the second.\n" . $herecurr);
2919 }
2806 } 2920 }
2807 2921
2808 # If we have no input at all, then there is nothing to report on 2922 # If we have no input at all, then there is nothing to report on
@@ -2839,6 +2953,16 @@ sub process {
2839 print "\n" if ($quiet == 0); 2953 print "\n" if ($quiet == 0);
2840 } 2954 }
2841 2955
2956 if ($quiet == 0) {
2957 # If there were whitespace errors which cleanpatch can fix
2958 # then suggest that.
2959 if ($rpt_cleaners) {
2960 print "NOTE: whitespace errors detected, you may wish to use scripts/cleanpatch or\n";
2961 print " scripts/cleanfile\n\n";
2962 $rpt_cleaners = 0;
2963 }
2964 }
2965
2842 if ($clean == 1 && $quiet == 0) { 2966 if ($clean == 1 && $quiet == 0) {
2843 print "$vname has no obvious style problems and is ready for submission.\n" 2967 print "$vname has no obvious style problems and is ready for submission.\n"
2844 } 2968 }