aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2011-07-25 20:13:25 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-07-25 23:57:16 -0400
commit000d1cc1829f938c87402fc2fd4bb5e8daed6b52 (patch)
treeb893c94009680dc51556ba0838815b7c9f9b6236 /scripts/checkpatch.pl
parent39b7e2878e783af027ddd3530f7a0abec330905d (diff)
checkpatch.pl: add ability to ignore various messages
Some users would like the ability to not emit some of the messages that checkpatch produces. This can make it easier to use checkpatch in other projects and integrate into scm hook scripts. Add command line option to "--ignore" various message types. Add option --show-types to emit the "type" of each message. Categorize all ERROR, WARN and CHK messages with types. Add optional .checkpatch.conf file to store default options. 3 paths are searched for .checkpatch.conf . customized per-tree configurations $HOME user global configuration when per-tree configs don't exist ./scripts lk defaults to override script The .conf file can contain any valid command-line argument and the contents are prepended to any additional command line arguments. Multiple lines may be used, blank lines are ignored, # is a comment. Update "false positive" output for readability. Update version to 0.32 Signed-off-by: Joe Perches <joe@perches.com> Acked-by: Mike Frysinger <vapier@gentoo.org> Cc: Andy Whitcroft <apw@canonical.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl498
1 files changed, 355 insertions, 143 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 8f35f0e03518..05777ab818f1 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.31'; 13my $V = '0.32';
14 14
15use Getopt::Long qw(:config no_auto_abbrev); 15use Getopt::Long qw(:config no_auto_abbrev);
16 16
@@ -26,9 +26,13 @@ my $check = 0;
26my $summary = 1; 26my $summary = 1;
27my $mailback = 0; 27my $mailback = 0;
28my $summary_file = 0; 28my $summary_file = 0;
29my $show_types = 0;
29my $root; 30my $root;
30my %debug; 31my %debug;
32my %ignore_type = ();
33my @ignore = ();
31my $help = 0; 34my $help = 0;
35my $configuration_file = ".checkpatch.conf";
32 36
33sub help { 37sub help {
34 my ($exitcode) = @_; 38 my ($exitcode) = @_;
@@ -46,6 +50,8 @@ Options:
46 --terse one line per report 50 --terse one line per report
47 -f, --file treat FILE as regular source file 51 -f, --file treat FILE as regular source file
48 --subjective, --strict enable more subjective tests 52 --subjective, --strict enable more subjective tests
53 --ignore TYPE(,TYPE2...) ignore various comma separated message types
54 --show-types show the message "types" in the output
49 --root=PATH PATH to the kernel tree root 55 --root=PATH PATH to the kernel tree root
50 --no-summary suppress the per-file summary 56 --no-summary suppress the per-file summary
51 --mailback only produce a report in case of warnings/errors 57 --mailback only produce a report in case of warnings/errors
@@ -63,6 +69,32 @@ EOM
63 exit($exitcode); 69 exit($exitcode);
64} 70}
65 71
72my $conf = which_conf($configuration_file);
73if (-f $conf) {
74 my @conf_args;
75 open(my $conffile, '<', "$conf")
76 or warn "$P: Can't find a readable $configuration_file file $!\n";
77
78 while (<$conffile>) {
79 my $line = $_;
80
81 $line =~ s/\s*\n?$//g;
82 $line =~ s/^\s*//g;
83 $line =~ s/\s+/ /g;
84
85 next if ($line =~ m/^\s*#/);
86 next if ($line =~ m/^\s*$/);
87
88 my @words = split(" ", $line);
89 foreach my $word (@words) {
90 last if ($word =~ m/^#/);
91 push (@conf_args, $word);
92 }
93 }
94 close($conffile);
95 unshift(@ARGV, @conf_args) if @conf_args;
96}
97
66GetOptions( 98GetOptions(
67 'q|quiet+' => \$quiet, 99 'q|quiet+' => \$quiet,
68 'tree!' => \$tree, 100 'tree!' => \$tree,
@@ -73,6 +105,8 @@ GetOptions(
73 'f|file!' => \$file, 105 'f|file!' => \$file,
74 'subjective!' => \$check, 106 'subjective!' => \$check,
75 'strict!' => \$check, 107 'strict!' => \$check,
108 'ignore=s' => \@ignore,
109 'show-types!' => \$show_types,
76 'root=s' => \$root, 110 'root=s' => \$root,
77 'summary!' => \$summary, 111 'summary!' => \$summary,
78 'mailback!' => \$mailback, 112 'mailback!' => \$mailback,
@@ -93,6 +127,19 @@ if ($#ARGV < 0) {
93 exit(1); 127 exit(1);
94} 128}
95 129
130@ignore = split(/,/, join(',',@ignore));
131foreach my $word (@ignore) {
132 $word =~ s/\s*\n?$//g;
133 $word =~ s/^\s*//g;
134 $word =~ s/\s+/ /g;
135 $word =~ tr/[a-z]/[A-Z]/;
136
137 next if ($word =~ m/^\s*#/);
138 next if ($word =~ m/^\s*$/);
139
140 $ignore_type{$word}++;
141}
142
96my $dbg_values = 0; 143my $dbg_values = 0;
97my $dbg_possible = 0; 144my $dbg_possible = 0;
98my $dbg_type = 0; 145my $dbg_type = 0;
@@ -364,7 +411,7 @@ sub top_of_kernel_tree {
364 } 411 }
365 } 412 }
366 return 1; 413 return 1;
367} 414 }
368 415
369sub parse_email { 416sub parse_email {
370 my ($formatted_email) = @_; 417 my ($formatted_email) = @_;
@@ -436,6 +483,18 @@ sub format_email {
436 return $formatted_email; 483 return $formatted_email;
437} 484}
438 485
486sub which_conf {
487 my ($conf) = @_;
488
489 foreach my $path (split(/:/, ".:$ENV{HOME}:.scripts")) {
490 if (-e "$path/$conf") {
491 return "$path/$conf";
492 }
493 }
494
495 return "";
496}
497
439sub expand_tabs { 498sub expand_tabs {
440 my ($str) = @_; 499 my ($str) = @_;
441 500
@@ -1181,12 +1240,21 @@ sub possible {
1181 1240
1182my $prefix = ''; 1241my $prefix = '';
1183 1242
1243sub show_type {
1244 return !defined $ignore_type{$_[0]};
1245}
1246
1184sub report { 1247sub report {
1185 if (defined $tst_only && $_[0] !~ /\Q$tst_only\E/) { 1248 if (!show_type($_[1]) ||
1249 (defined $tst_only && $_[2] !~ /\Q$tst_only\E/)) {
1186 return 0; 1250 return 0;
1187 } 1251 }
1188 my $line = $prefix . $_[0]; 1252 my $line;
1189 1253 if ($show_types) {
1254 $line = "$prefix$_[0]:$_[1]: $_[2]\n";
1255 } else {
1256 $line = "$prefix$_[0]: $_[2]\n";
1257 }
1190 $line = (split('\n', $line))[0] . "\n" if ($terse); 1258 $line = (split('\n', $line))[0] . "\n" if ($terse);
1191 1259
1192 push(our @report, $line); 1260 push(our @report, $line);
@@ -1196,20 +1264,21 @@ sub report {
1196sub report_dump { 1264sub report_dump {
1197 our @report; 1265 our @report;
1198} 1266}
1267
1199sub ERROR { 1268sub ERROR {
1200 if (report("ERROR: $_[0]\n")) { 1269 if (report("ERROR", $_[0], $_[1])) {
1201 our $clean = 0; 1270 our $clean = 0;
1202 our $cnt_error++; 1271 our $cnt_error++;
1203 } 1272 }
1204} 1273}
1205sub WARN { 1274sub WARN {
1206 if (report("WARNING: $_[0]\n")) { 1275 if (report("WARNING", $_[0], $_[1])) {
1207 our $clean = 0; 1276 our $clean = 0;
1208 our $cnt_warn++; 1277 our $cnt_warn++;
1209 } 1278 }
1210} 1279}
1211sub CHK { 1280sub CHK {
1212 if ($check && report("CHECK: $_[0]\n")) { 1281 if ($check && report("CHECK", $_[0], $_[1])) {
1213 our $clean = 0; 1282 our $clean = 0;
1214 our $cnt_chk++; 1283 our $cnt_chk++;
1215 } 1284 }
@@ -1238,7 +1307,8 @@ sub check_absolute_file {
1238 1307
1239 ##print "prefix<$prefix>\n"; 1308 ##print "prefix<$prefix>\n";
1240 if ($prefix ne ".../") { 1309 if ($prefix ne ".../") {
1241 WARN("use relative pathname instead of absolute in changelog text\n" . $herecurr); 1310 WARN("USE_RELATIVE_PATH",
1311 "use relative pathname instead of absolute in changelog text\n" . $herecurr);
1242 } 1312 }
1243} 1313}
1244 1314
@@ -1435,11 +1505,13 @@ sub process {
1435 $p1_prefix = $1; 1505 $p1_prefix = $1;
1436 if (!$file && $tree && $p1_prefix ne '' && 1506 if (!$file && $tree && $p1_prefix ne '' &&
1437 -e "$root/$p1_prefix") { 1507 -e "$root/$p1_prefix") {
1438 WARN("patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n"); 1508 WARN("PATCH_PREFIX",
1509 "patch prefix '$p1_prefix' exists, appears to be a -p0 patch\n");
1439 } 1510 }
1440 1511
1441 if ($realfile =~ m@^include/asm/@) { 1512 if ($realfile =~ m@^include/asm/@) {
1442 ERROR("do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n"); 1513 ERROR("MODIFIED_INCLUDE_ASM",
1514 "do not modify files in include/asm, change architecture specific files in include/asm-<architecture>\n" . "$here$rawline\n");
1443 } 1515 }
1444 next; 1516 next;
1445 } 1517 }
@@ -1456,7 +1528,8 @@ sub process {
1456 if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) { 1528 if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) {
1457 my $permhere = $here . "FILE: $realfile\n"; 1529 my $permhere = $here . "FILE: $realfile\n";
1458 if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) { 1530 if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) {
1459 ERROR("do not set execute permissions for source files\n" . $permhere); 1531 ERROR("EXECUTE_PERMISSIONS",
1532 "do not set execute permissions for source files\n" . $permhere);
1460 } 1533 }
1461 } 1534 }
1462 1535
@@ -1474,19 +1547,23 @@ sub process {
1474 my $ucfirst_sign_off = ucfirst(lc($sign_off)); 1547 my $ucfirst_sign_off = ucfirst(lc($sign_off));
1475 1548
1476 if (defined $space_before && $space_before ne "") { 1549 if (defined $space_before && $space_before ne "") {
1477 WARN("Do not use whitespace before $ucfirst_sign_off\n" . $herecurr); 1550 WARN("BAD_SIGN_OFF",
1551 "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr);
1478 } 1552 }
1479 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) { 1553 if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) {
1480 WARN("'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr); 1554 WARN("BAD_SIGN_OFF",
1555 "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr);
1481 } 1556 }
1482 if (!defined $space_after || $space_after ne " ") { 1557 if (!defined $space_after || $space_after ne " ") {
1483 WARN("Use a single space after $ucfirst_sign_off\n" . $herecurr); 1558 WARN("BAD_SIGN_OFF",
1559 "Use a single space after $ucfirst_sign_off\n" . $herecurr);
1484 } 1560 }
1485 1561
1486 my ($email_name, $email_address, $comment) = parse_email($email); 1562 my ($email_name, $email_address, $comment) = parse_email($email);
1487 my $suggested_email = format_email(($email_name, $email_address)); 1563 my $suggested_email = format_email(($email_name, $email_address));
1488 if ($suggested_email eq "") { 1564 if ($suggested_email eq "") {
1489 ERROR("Unrecognized email address: '$email'\n" . $herecurr); 1565 ERROR("BAD_SIGN_OFF",
1566 "Unrecognized email address: '$email'\n" . $herecurr);
1490 } else { 1567 } else {
1491 my $dequoted = $suggested_email; 1568 my $dequoted = $suggested_email;
1492 $dequoted =~ s/^"//; 1569 $dequoted =~ s/^"//;
@@ -1496,14 +1573,16 @@ sub process {
1496 if ("$dequoted$comment" ne $email && 1573 if ("$dequoted$comment" ne $email &&
1497 "<$email_address>$comment" ne $email && 1574 "<$email_address>$comment" ne $email &&
1498 "$suggested_email$comment" ne $email) { 1575 "$suggested_email$comment" ne $email) {
1499 WARN("email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr); 1576 WARN("BAD_SIGN_OFF",
1577 "email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr);
1500 } 1578 }
1501 } 1579 }
1502 } 1580 }
1503 1581
1504# Check for wrappage within a valid hunk of the file 1582# Check for wrappage within a valid hunk of the file
1505 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) { 1583 if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) {
1506 ERROR("patch seems to be corrupt (line wrapped?)\n" . 1584 ERROR("CORRUPTED_PATCH",
1585 "patch seems to be corrupt (line wrapped?)\n" .
1507 $herecurr) if (!$emitted_corrupt++); 1586 $herecurr) if (!$emitted_corrupt++);
1508 } 1587 }
1509 1588
@@ -1530,7 +1609,8 @@ sub process {
1530 my $ptr = substr($blank, 0, length($utf8_prefix)) . "^"; 1609 my $ptr = substr($blank, 0, length($utf8_prefix)) . "^";
1531 my $hereptr = "$hereline$ptr\n"; 1610 my $hereptr = "$hereline$ptr\n";
1532 1611
1533 ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr); 1612 ERROR("INVALID_UTF8",
1613 "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr);
1534 } 1614 }
1535 1615
1536# ignore non-hunk lines and lines being removed 1616# ignore non-hunk lines and lines being removed
@@ -1539,11 +1619,13 @@ sub process {
1539#trailing whitespace 1619#trailing whitespace
1540 if ($line =~ /^\+.*\015/) { 1620 if ($line =~ /^\+.*\015/) {
1541 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1621 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1542 ERROR("DOS line endings\n" . $herevet); 1622 ERROR("DOS_LINE_ENDINGS",
1623 "DOS line endings\n" . $herevet);
1543 1624
1544 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { 1625 } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) {
1545 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1626 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1546 ERROR("trailing whitespace\n" . $herevet); 1627 ERROR("TRAILING_WHITESPACE",
1628 "trailing whitespace\n" . $herevet);
1547 $rpt_cleaners = 1; 1629 $rpt_cleaners = 1;
1548 } 1630 }
1549 1631
@@ -1574,7 +1656,8 @@ sub process {
1574 } 1656 }
1575 $length++; 1657 $length++;
1576 } 1658 }
1577 WARN("please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_end && $length < 4); 1659 WARN("CONFIG_DESCRIPTION",
1660 "please write a paragraph that describes the config symbol fully\n" . $herecurr) if ($is_end && $length < 4);
1578 #print "is_end<$is_end> length<$length>\n"; 1661 #print "is_end<$is_end> length<$length>\n";
1579 } 1662 }
1580 1663
@@ -1588,28 +1671,33 @@ sub process {
1588 $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && 1671 $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) &&
1589 $length > 80) 1672 $length > 80)
1590 { 1673 {
1591 WARN("line over 80 characters\n" . $herecurr); 1674 WARN("LONG_LINE",
1675 "line over 80 characters\n" . $herecurr);
1592 } 1676 }
1593 1677
1594# check for spaces before a quoted newline 1678# check for spaces before a quoted newline
1595 if ($rawline =~ /^.*\".*\s\\n/) { 1679 if ($rawline =~ /^.*\".*\s\\n/) {
1596 WARN("unnecessary whitespace before a quoted newline\n" . $herecurr); 1680 WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE",
1681 "unnecessary whitespace before a quoted newline\n" . $herecurr);
1597 } 1682 }
1598 1683
1599# check for adding lines without a newline. 1684# check for adding lines without a newline.
1600 if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) { 1685 if ($line =~ /^\+/ && defined $lines[$linenr] && $lines[$linenr] =~ /^\\ No newline at end of file/) {
1601 WARN("adding a line without newline at end of file\n" . $herecurr); 1686 WARN("MISSING_EOF_NEWLINE",
1687 "adding a line without newline at end of file\n" . $herecurr);
1602 } 1688 }
1603 1689
1604# Blackfin: use hi/lo macros 1690# Blackfin: use hi/lo macros
1605 if ($realfile =~ m@arch/blackfin/.*\.S$@) { 1691 if ($realfile =~ m@arch/blackfin/.*\.S$@) {
1606 if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) { 1692 if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) {
1607 my $herevet = "$here\n" . cat_vet($line) . "\n"; 1693 my $herevet = "$here\n" . cat_vet($line) . "\n";
1608 ERROR("use the LO() macro, not (... & 0xFFFF)\n" . $herevet); 1694 ERROR("LO_MACRO",
1695 "use the LO() macro, not (... & 0xFFFF)\n" . $herevet);
1609 } 1696 }
1610 if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) { 1697 if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) {
1611 my $herevet = "$here\n" . cat_vet($line) . "\n"; 1698 my $herevet = "$here\n" . cat_vet($line) . "\n";
1612 ERROR("use the HI() macro, not (... >> 16)\n" . $herevet); 1699 ERROR("HI_MACRO",
1700 "use the HI() macro, not (... >> 16)\n" . $herevet);
1613 } 1701 }
1614 } 1702 }
1615 1703
@@ -1621,14 +1709,16 @@ sub process {
1621 if ($rawline =~ /^\+\s* \t\s*\S/ || 1709 if ($rawline =~ /^\+\s* \t\s*\S/ ||
1622 $rawline =~ /^\+\s* \s*/) { 1710 $rawline =~ /^\+\s* \s*/) {
1623 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1711 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1624 ERROR("code indent should use tabs where possible\n" . $herevet); 1712 ERROR("CODE_INDENT",
1713 "code indent should use tabs where possible\n" . $herevet);
1625 $rpt_cleaners = 1; 1714 $rpt_cleaners = 1;
1626 } 1715 }
1627 1716
1628# check for space before tabs. 1717# check for space before tabs.
1629 if ($rawline =~ /^\+/ && $rawline =~ / \t/) { 1718 if ($rawline =~ /^\+/ && $rawline =~ / \t/) {
1630 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1719 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1631 WARN("please, no space before tabs\n" . $herevet); 1720 WARN("SPACE_BEFORE_TAB",
1721 "please, no space before tabs\n" . $herevet);
1632 } 1722 }
1633 1723
1634# check for spaces at the beginning of a line. 1724# check for spaces at the beginning of a line.
@@ -1638,7 +1728,8 @@ sub process {
1638# 3) hanging labels 1728# 3) hanging labels
1639 if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) { 1729 if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) {
1640 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 1730 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
1641 WARN("please, no spaces at the start of a line\n" . $herevet); 1731 WARN("LEADING_SPACE",
1732 "please, no spaces at the start of a line\n" . $herevet);
1642 } 1733 }
1643 1734
1644# check we are in a valid C source file if not then ignore this hunk 1735# check we are in a valid C source file if not then ignore this hunk
@@ -1646,17 +1737,20 @@ sub process {
1646 1737
1647# check for RCS/CVS revision markers 1738# check for RCS/CVS revision markers
1648 if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) { 1739 if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) {
1649 WARN("CVS style keyword markers, these will _not_ be updated\n". $herecurr); 1740 WARN("CVS_KEYWORD",
1741 "CVS style keyword markers, these will _not_ be updated\n". $herecurr);
1650 } 1742 }
1651 1743
1652# Blackfin: don't use __builtin_bfin_[cs]sync 1744# Blackfin: don't use __builtin_bfin_[cs]sync
1653 if ($line =~ /__builtin_bfin_csync/) { 1745 if ($line =~ /__builtin_bfin_csync/) {
1654 my $herevet = "$here\n" . cat_vet($line) . "\n"; 1746 my $herevet = "$here\n" . cat_vet($line) . "\n";
1655 ERROR("use the CSYNC() macro in asm/blackfin.h\n" . $herevet); 1747 ERROR("CSYNC",
1748 "use the CSYNC() macro in asm/blackfin.h\n" . $herevet);
1656 } 1749 }
1657 if ($line =~ /__builtin_bfin_ssync/) { 1750 if ($line =~ /__builtin_bfin_ssync/) {
1658 my $herevet = "$here\n" . cat_vet($line) . "\n"; 1751 my $herevet = "$here\n" . cat_vet($line) . "\n";
1659 ERROR("use the SSYNC() macro in asm/blackfin.h\n" . $herevet); 1752 ERROR("SSYNC",
1753 "use the SSYNC() macro in asm/blackfin.h\n" . $herevet);
1660 } 1754 }
1661 1755
1662# Check for potential 'bare' types 1756# Check for potential 'bare' types
@@ -1745,7 +1839,8 @@ sub process {
1745 } 1839 }
1746 } 1840 }
1747 if ($err ne '') { 1841 if ($err ne '') {
1748 ERROR("switch and case should be at the same indent\n$hereline$err"); 1842 ERROR("SWITCH_CASE_INDENT_LEVEL",
1843 "switch and case should be at the same indent\n$hereline$err");
1749 } 1844 }
1750 } 1845 }
1751 1846
@@ -1773,7 +1868,8 @@ sub process {
1773 #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n"; 1868 #print "pre<$pre_ctx>\nline<$line>\nctx<$ctx>\nnext<$lines[$ctx_ln - 1]>\n";
1774 1869
1775 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) { 1870 if ($ctx !~ /{\s*/ && defined($lines[$ctx_ln -1]) && $lines[$ctx_ln - 1] =~ /^\+\s*{/) {
1776 ERROR("that open brace { should be on the previous line\n" . 1871 ERROR("OPEN_BRACE",
1872 "that open brace { should be on the previous line\n" .
1777 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); 1873 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
1778 } 1874 }
1779 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ && 1875 if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ &&
@@ -1782,7 +1878,8 @@ sub process {
1782 { 1878 {
1783 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); 1879 my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]);
1784 if ($nindent > $indent) { 1880 if ($nindent > $indent) {
1785 WARN("trailing semicolon indicates no statements, indent implies otherwise\n" . 1881 WARN("TRAILING_SEMICOLON",
1882 "trailing semicolon indicates no statements, indent implies otherwise\n" .
1786 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); 1883 "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n");
1787 } 1884 }
1788 } 1885 }
@@ -1870,7 +1967,8 @@ sub process {
1870 1967
1871 if ($check && (($sindent % 8) != 0 || 1968 if ($check && (($sindent % 8) != 0 ||
1872 ($sindent <= $indent && $s ne ''))) { 1969 ($sindent <= $indent && $s ne ''))) {
1873 WARN("suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n"); 1970 WARN("SUSPECT_CODE_INDENT",
1971 "suspect code indent for conditional statements ($indent, $sindent)\n" . $herecurr . "$stat_real\n");
1874 } 1972 }
1875 } 1973 }
1876 1974
@@ -1893,18 +1991,22 @@ sub process {
1893# TEST: allow direct testing of the type matcher. 1991# TEST: allow direct testing of the type matcher.
1894 if ($dbg_type) { 1992 if ($dbg_type) {
1895 if ($line =~ /^.\s*$Declare\s*$/) { 1993 if ($line =~ /^.\s*$Declare\s*$/) {
1896 ERROR("TEST: is type\n" . $herecurr); 1994 ERROR("TEST_TYPE",
1995 "TEST: is type\n" . $herecurr);
1897 } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) { 1996 } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) {
1898 ERROR("TEST: is not type ($1 is)\n". $herecurr); 1997 ERROR("TEST_NOT_TYPE",
1998 "TEST: is not type ($1 is)\n". $herecurr);
1899 } 1999 }
1900 next; 2000 next;
1901 } 2001 }
1902# TEST: allow direct testing of the attribute matcher. 2002# TEST: allow direct testing of the attribute matcher.
1903 if ($dbg_attr) { 2003 if ($dbg_attr) {
1904 if ($line =~ /^.\s*$Modifier\s*$/) { 2004 if ($line =~ /^.\s*$Modifier\s*$/) {
1905 ERROR("TEST: is attr\n" . $herecurr); 2005 ERROR("TEST_ATTR",
2006 "TEST: is attr\n" . $herecurr);
1906 } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) { 2007 } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) {
1907 ERROR("TEST: is not attr ($1 is)\n". $herecurr); 2008 ERROR("TEST_NOT_ATTR",
2009 "TEST: is not attr ($1 is)\n". $herecurr);
1908 } 2010 }
1909 next; 2011 next;
1910 } 2012 }
@@ -1912,7 +2014,8 @@ sub process {
1912# check for initialisation to aggregates open brace on the next line 2014# check for initialisation to aggregates open brace on the next line
1913 if ($line =~ /^.\s*{/ && 2015 if ($line =~ /^.\s*{/ &&
1914 $prevline =~ /(?:^|[^=])=\s*$/) { 2016 $prevline =~ /(?:^|[^=])=\s*$/) {
1915 ERROR("that open brace { should be on the previous line\n" . $hereprev); 2017 ERROR("OPEN_BRACE",
2018 "that open brace { should be on the previous line\n" . $hereprev);
1916 } 2019 }
1917 2020
1918# 2021#
@@ -1923,14 +2026,16 @@ sub process {
1923 if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) { 2026 if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) {
1924 my $path = $1; 2027 my $path = $1;
1925 if ($path =~ m{//}) { 2028 if ($path =~ m{//}) {
1926 ERROR("malformed #include filename\n" . 2029 ERROR("MALFORMED_INCLUDE",
2030 "malformed #include filename\n" .
1927 $herecurr); 2031 $herecurr);
1928 } 2032 }
1929 } 2033 }
1930 2034
1931# no C99 // comments 2035# no C99 // comments
1932 if ($line =~ m{//}) { 2036 if ($line =~ m{//}) {
1933 ERROR("do not use C99 // comments\n" . $herecurr); 2037 ERROR("C99_COMMENTS",
2038 "do not use C99 // comments\n" . $herecurr);
1934 } 2039 }
1935 # Remove C99 comments. 2040 # Remove C99 comments.
1936 $line =~ s@//.*@@; 2041 $line =~ s@//.*@@;
@@ -1977,35 +2082,41 @@ sub process {
1977 } 2082 }
1978 if (defined $suppress_export{$linenr} && 2083 if (defined $suppress_export{$linenr} &&
1979 $suppress_export{$linenr} == 2) { 2084 $suppress_export{$linenr} == 2) {
1980 WARN("EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr); 2085 WARN("EXPORT_SYMBOL",
2086 "EXPORT_SYMBOL(foo); should immediately follow its function/variable\n" . $herecurr);
1981 } 2087 }
1982 2088
1983# check for global initialisers. 2089# check for global initialisers.
1984 if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) { 2090 if ($line =~ /^.$Type\s*$Ident\s*(?:\s+$Modifier)*\s*=\s*(0|NULL|false)\s*;/) {
1985 ERROR("do not initialise globals to 0 or NULL\n" . 2091 ERROR("GLOBAL_INITIALISERS",
2092 "do not initialise globals to 0 or NULL\n" .
1986 $herecurr); 2093 $herecurr);
1987 } 2094 }
1988# check for static initialisers. 2095# check for static initialisers.
1989 if ($line =~ /\bstatic\s.*=\s*(0|NULL|false)\s*;/) { 2096 if ($line =~ /\bstatic\s.*=\s*(0|NULL|false)\s*;/) {
1990 ERROR("do not initialise statics to 0 or NULL\n" . 2097 ERROR("INITIALISED_STATIC",
2098 "do not initialise statics to 0 or NULL\n" .
1991 $herecurr); 2099 $herecurr);
1992 } 2100 }
1993 2101
1994# check for static const char * arrays. 2102# check for static const char * arrays.
1995 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) { 2103 if ($line =~ /\bstatic\s+const\s+char\s*\*\s*(\w+)\s*\[\s*\]\s*=\s*/) {
1996 WARN("static const char * array should probably be static const char * const\n" . 2104 WARN("STATIC_CONST_CHAR_ARRAY",
2105 "static const char * array should probably be static const char * const\n" .
1997 $herecurr); 2106 $herecurr);
1998 } 2107 }
1999 2108
2000# check for static char foo[] = "bar" declarations. 2109# check for static char foo[] = "bar" declarations.
2001 if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) { 2110 if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) {
2002 WARN("static char array declaration should probably be static const char\n" . 2111 WARN("STATIC_CONST_CHAR_ARRAY",
2112 "static char array declaration should probably be static const char\n" .
2003 $herecurr); 2113 $herecurr);
2004 } 2114 }
2005 2115
2006# check for declarations of struct pci_device_id 2116# check for declarations of struct pci_device_id
2007 if ($line =~ /\bstruct\s+pci_device_id\s+\w+\s*\[\s*\]\s*\=\s*\{/) { 2117 if ($line =~ /\bstruct\s+pci_device_id\s+\w+\s*\[\s*\]\s*\=\s*\{/) {
2008 WARN("Use DEFINE_PCI_DEVICE_TABLE for struct pci_device_id\n" . $herecurr); 2118 WARN("DEFINE_PCI_DEVICE_TABLE",
2119 "Use DEFINE_PCI_DEVICE_TABLE for struct pci_device_id\n" . $herecurr);
2009 } 2120 }
2010 2121
2011# check for new typedefs, only function parameters and sparse annotations 2122# check for new typedefs, only function parameters and sparse annotations
@@ -2015,7 +2126,8 @@ sub process {
2015 $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && 2126 $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ &&
2016 $line !~ /\b$typeTypedefs\b/ && 2127 $line !~ /\b$typeTypedefs\b/ &&
2017 $line !~ /\b__bitwise(?:__|)\b/) { 2128 $line !~ /\b__bitwise(?:__|)\b/) {
2018 WARN("do not add new typedefs\n" . $herecurr); 2129 WARN("NEW_TYPEDEFS",
2130 "do not add new typedefs\n" . $herecurr);
2019 } 2131 }
2020 2132
2021# * goes on variable not on type 2133# * goes on variable not on type
@@ -2033,7 +2145,8 @@ sub process {
2033 2145
2034 #print "from<$from> to<$to>\n"; 2146 #print "from<$from> to<$to>\n";
2035 if ($from ne $to) { 2147 if ($from ne $to) {
2036 ERROR("\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr); 2148 ERROR("POINTER_LOCATION",
2149 "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr);
2037 } 2150 }
2038 } elsif ($line =~ m{\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident)}) { 2151 } elsif ($line =~ m{\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident)}) {
2039 my ($from, $to, $ident) = ($1, $1, $2); 2152 my ($from, $to, $ident) = ($1, $1, $2);
@@ -2050,7 +2163,8 @@ sub process {
2050 2163
2051 #print "from<$from> to<$to> ident<$ident>\n"; 2164 #print "from<$from> to<$to> ident<$ident>\n";
2052 if ($from ne $to && $ident !~ /^$Modifier$/) { 2165 if ($from ne $to && $ident !~ /^$Modifier$/) {
2053 ERROR("\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr); 2166 ERROR("POINTER_LOCATION",
2167 "\"foo${from}bar\" should be \"foo${to}bar\"\n" . $herecurr);
2054 } 2168 }
2055 } 2169 }
2056 2170
@@ -2062,12 +2176,14 @@ sub process {
2062# } 2176# }
2063 2177
2064 if ($line =~ /\bLINUX_VERSION_CODE\b/) { 2178 if ($line =~ /\bLINUX_VERSION_CODE\b/) {
2065 WARN("LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr); 2179 WARN("LINUX_VERSION_CODE",
2180 "LINUX_VERSION_CODE should be avoided, code should be for the version to which it is merged\n" . $herecurr);
2066 } 2181 }
2067 2182
2068# check for uses of printk_ratelimit 2183# check for uses of printk_ratelimit
2069 if ($line =~ /\bprintk_ratelimit\s*\(/) { 2184 if ($line =~ /\bprintk_ratelimit\s*\(/) {
2070 WARN("Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr); 2185 WARN("PRINTK_RATELIMITED",
2186"Prefer printk_ratelimited or pr_<level>_ratelimited to printk_ratelimit\n" . $herecurr);
2071 } 2187 }
2072 2188
2073# printk should use KERN_* levels. Note that follow on printk's on the 2189# printk should use KERN_* levels. Note that follow on printk's on the
@@ -2089,7 +2205,8 @@ sub process {
2089 } 2205 }
2090 } 2206 }
2091 if ($ok == 0) { 2207 if ($ok == 0) {
2092 WARN("printk() should include KERN_ facility level\n" . $herecurr); 2208 WARN("PRINTK_WITHOUT_KERN_LEVEL",
2209 "printk() should include KERN_ facility level\n" . $herecurr);
2093 } 2210 }
2094 } 2211 }
2095 2212
@@ -2097,18 +2214,21 @@ sub process {
2097# or if closed on same line 2214# or if closed on same line
2098 if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and 2215 if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and
2099 !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) { 2216 !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) {
2100 ERROR("open brace '{' following function declarations go on the next line\n" . $herecurr); 2217 ERROR("OPEN_BRACE",
2218 "open brace '{' following function declarations go on the next line\n" . $herecurr);
2101 } 2219 }
2102 2220
2103# open braces for enum, union and struct go on the same line. 2221# open braces for enum, union and struct go on the same line.
2104 if ($line =~ /^.\s*{/ && 2222 if ($line =~ /^.\s*{/ &&
2105 $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) { 2223 $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) {
2106 ERROR("open brace '{' following $1 go on the same line\n" . $hereprev); 2224 ERROR("OPEN_BRACE",
2225 "open brace '{' following $1 go on the same line\n" . $hereprev);
2107 } 2226 }
2108 2227
2109# missing space after union, struct or enum definition 2228# missing space after union, struct or enum definition
2110 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) { 2229 if ($line =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?(?:\s+$Ident)?[=\{]/) {
2111 WARN("missing space after $1 definition\n" . $herecurr); 2230 WARN("SPACING",
2231 "missing space after $1 definition\n" . $herecurr);
2112 } 2232 }
2113 2233
2114# check for spacing round square brackets; allowed: 2234# check for spacing round square brackets; allowed:
@@ -2120,7 +2240,8 @@ sub process {
2120 if ($prefix !~ /$Type\s+$/ && 2240 if ($prefix !~ /$Type\s+$/ &&
2121 ($where != 0 || $prefix !~ /^.\s+$/) && 2241 ($where != 0 || $prefix !~ /^.\s+$/) &&
2122 $prefix !~ /{\s+$/) { 2242 $prefix !~ /{\s+$/) {
2123 ERROR("space prohibited before open square bracket '['\n" . $herecurr); 2243 ERROR("BRACKET_SPACE",
2244 "space prohibited before open square bracket '['\n" . $herecurr);
2124 } 2245 }
2125 } 2246 }
2126 2247
@@ -2151,7 +2272,8 @@ sub process {
2151 } elsif ($ctx =~ /$Type$/) { 2272 } elsif ($ctx =~ /$Type$/) {
2152 2273
2153 } else { 2274 } else {
2154 WARN("space prohibited between function name and open parenthesis '('\n" . $herecurr); 2275 WARN("SPACING",
2276 "space prohibited between function name and open parenthesis '('\n" . $herecurr);
2155 } 2277 }
2156 } 2278 }
2157# Check operator spacing. 2279# Check operator spacing.
@@ -2225,7 +2347,8 @@ sub process {
2225 } elsif ($op eq ';') { 2347 } elsif ($op eq ';') {
2226 if ($ctx !~ /.x[WEBC]/ && 2348 if ($ctx !~ /.x[WEBC]/ &&
2227 $cc !~ /^\\/ && $cc !~ /^;/) { 2349 $cc !~ /^\\/ && $cc !~ /^;/) {
2228 ERROR("space required after that '$op' $at\n" . $hereptr); 2350 ERROR("SPACING",
2351 "space required after that '$op' $at\n" . $hereptr);
2229 } 2352 }
2230 2353
2231 # // is a comment 2354 # // is a comment
@@ -2236,13 +2359,15 @@ sub process {
2236 # : when part of a bitfield 2359 # : when part of a bitfield
2237 } elsif ($op eq '->' || $opv eq ':B') { 2360 } elsif ($op eq '->' || $opv eq ':B') {
2238 if ($ctx =~ /Wx.|.xW/) { 2361 if ($ctx =~ /Wx.|.xW/) {
2239 ERROR("spaces prohibited around that '$op' $at\n" . $hereptr); 2362 ERROR("SPACING",
2363 "spaces prohibited around that '$op' $at\n" . $hereptr);
2240 } 2364 }
2241 2365
2242 # , must have a space on the right. 2366 # , must have a space on the right.
2243 } elsif ($op eq ',') { 2367 } elsif ($op eq ',') {
2244 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) { 2368 if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) {
2245 ERROR("space required after that '$op' $at\n" . $hereptr); 2369 ERROR("SPACING",
2370 "space required after that '$op' $at\n" . $hereptr);
2246 } 2371 }
2247 2372
2248 # '*' as part of a type definition -- reported already. 2373 # '*' as part of a type definition -- reported already.
@@ -2256,26 +2381,31 @@ sub process {
2256 $opv eq '*U' || $opv eq '-U' || 2381 $opv eq '*U' || $opv eq '-U' ||
2257 $opv eq '&U' || $opv eq '&&U') { 2382 $opv eq '&U' || $opv eq '&&U') {
2258 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { 2383 if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) {
2259 ERROR("space required before that '$op' $at\n" . $hereptr); 2384 ERROR("SPACING",
2385 "space required before that '$op' $at\n" . $hereptr);
2260 } 2386 }
2261 if ($op eq '*' && $cc =~/\s*$Modifier\b/) { 2387 if ($op eq '*' && $cc =~/\s*$Modifier\b/) {
2262 # A unary '*' may be const 2388 # A unary '*' may be const
2263 2389
2264 } elsif ($ctx =~ /.xW/) { 2390 } elsif ($ctx =~ /.xW/) {
2265 ERROR("space prohibited after that '$op' $at\n" . $hereptr); 2391 ERROR("SPACING",
2392 "space prohibited after that '$op' $at\n" . $hereptr);
2266 } 2393 }
2267 2394
2268 # unary ++ and unary -- are allowed no space on one side. 2395 # unary ++ and unary -- are allowed no space on one side.
2269 } elsif ($op eq '++' or $op eq '--') { 2396 } elsif ($op eq '++' or $op eq '--') {
2270 if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) { 2397 if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) {
2271 ERROR("space required one side of that '$op' $at\n" . $hereptr); 2398 ERROR("SPACING",
2399 "space required one side of that '$op' $at\n" . $hereptr);
2272 } 2400 }
2273 if ($ctx =~ /Wx[BE]/ || 2401 if ($ctx =~ /Wx[BE]/ ||
2274 ($ctx =~ /Wx./ && $cc =~ /^;/)) { 2402 ($ctx =~ /Wx./ && $cc =~ /^;/)) {
2275 ERROR("space prohibited before that '$op' $at\n" . $hereptr); 2403 ERROR("SPACING",
2404 "space prohibited before that '$op' $at\n" . $hereptr);
2276 } 2405 }
2277 if ($ctx =~ /ExW/) { 2406 if ($ctx =~ /ExW/) {
2278 ERROR("space prohibited after that '$op' $at\n" . $hereptr); 2407 ERROR("SPACING",
2408 "space prohibited after that '$op' $at\n" . $hereptr);
2279 } 2409 }
2280 2410
2281 2411
@@ -2287,7 +2417,8 @@ sub process {
2287 $op eq '%') 2417 $op eq '%')
2288 { 2418 {
2289 if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) { 2419 if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) {
2290 ERROR("need consistent spacing around '$op' $at\n" . 2420 ERROR("SPACING",
2421 "need consistent spacing around '$op' $at\n" .
2291 $hereptr); 2422 $hereptr);
2292 } 2423 }
2293 2424
@@ -2295,7 +2426,8 @@ sub process {
2295 # terminating a case value or a label. 2426 # terminating a case value or a label.
2296 } elsif ($opv eq ':C' || $opv eq ':L') { 2427 } elsif ($opv eq ':C' || $opv eq ':L') {
2297 if ($ctx =~ /Wx./) { 2428 if ($ctx =~ /Wx./) {
2298 ERROR("space prohibited before that '$op' $at\n" . $hereptr); 2429 ERROR("SPACING",
2430 "space prohibited before that '$op' $at\n" . $hereptr);
2299 } 2431 }
2300 2432
2301 # All the others need spaces both sides. 2433 # All the others need spaces both sides.
@@ -2318,7 +2450,8 @@ sub process {
2318 } 2450 }
2319 2451
2320 if ($ok == 0) { 2452 if ($ok == 0) {
2321 ERROR("spaces required around that '$op' $at\n" . $hereptr); 2453 ERROR("SPACING",
2454 "spaces required around that '$op' $at\n" . $hereptr);
2322 } 2455 }
2323 } 2456 }
2324 $off += length($elements[$n + 1]); 2457 $off += length($elements[$n + 1]);
@@ -2327,7 +2460,8 @@ sub process {
2327 2460
2328# check for multiple assignments 2461# check for multiple assignments
2329 if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) { 2462 if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) {
2330 CHK("multiple assignments should be avoided\n" . $herecurr); 2463 CHK("MULTIPLE_ASSIGNMENTS",
2464 "multiple assignments should be avoided\n" . $herecurr);
2331 } 2465 }
2332 2466
2333## # check for multiple declarations, allowing for a function declaration 2467## # check for multiple declarations, allowing for a function declaration
@@ -2341,45 +2475,53 @@ sub process {
2341## while ($ln =~ s/\([^\(\)]*\)//g) { 2475## while ($ln =~ s/\([^\(\)]*\)//g) {
2342## } 2476## }
2343## if ($ln =~ /,/) { 2477## if ($ln =~ /,/) {
2344## WARN("declaring multiple variables together should be avoided\n" . $herecurr); 2478## WARN("MULTIPLE_DECLARATION",
2479## "declaring multiple variables together should be avoided\n" . $herecurr);
2345## } 2480## }
2346## } 2481## }
2347 2482
2348#need space before brace following if, while, etc 2483#need space before brace following if, while, etc
2349 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || 2484 if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) ||
2350 $line =~ /do{/) { 2485 $line =~ /do{/) {
2351 ERROR("space required before the open brace '{'\n" . $herecurr); 2486 ERROR("SPACING",
2487 "space required before the open brace '{'\n" . $herecurr);
2352 } 2488 }
2353 2489
2354# closing brace should have a space following it when it has anything 2490# closing brace should have a space following it when it has anything
2355# on the line 2491# on the line
2356 if ($line =~ /}(?!(?:,|;|\)))\S/) { 2492 if ($line =~ /}(?!(?:,|;|\)))\S/) {
2357 ERROR("space required after that close brace '}'\n" . $herecurr); 2493 ERROR("SPACING",
2494 "space required after that close brace '}'\n" . $herecurr);
2358 } 2495 }
2359 2496
2360# check spacing on square brackets 2497# check spacing on square brackets
2361 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) { 2498 if ($line =~ /\[\s/ && $line !~ /\[\s*$/) {
2362 ERROR("space prohibited after that open square bracket '['\n" . $herecurr); 2499 ERROR("SPACING",
2500 "space prohibited after that open square bracket '['\n" . $herecurr);
2363 } 2501 }
2364 if ($line =~ /\s\]/) { 2502 if ($line =~ /\s\]/) {
2365 ERROR("space prohibited before that close square bracket ']'\n" . $herecurr); 2503 ERROR("SPACING",
2504 "space prohibited before that close square bracket ']'\n" . $herecurr);
2366 } 2505 }
2367 2506
2368# check spacing on parentheses 2507# check spacing on parentheses
2369 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ && 2508 if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ &&
2370 $line !~ /for\s*\(\s+;/) { 2509 $line !~ /for\s*\(\s+;/) {
2371 ERROR("space prohibited after that open parenthesis '('\n" . $herecurr); 2510 ERROR("SPACING",
2511 "space prohibited after that open parenthesis '('\n" . $herecurr);
2372 } 2512 }
2373 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ && 2513 if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ &&
2374 $line !~ /for\s*\(.*;\s+\)/ && 2514 $line !~ /for\s*\(.*;\s+\)/ &&
2375 $line !~ /:\s+\)/) { 2515 $line !~ /:\s+\)/) {
2376 ERROR("space prohibited before that close parenthesis ')'\n" . $herecurr); 2516 ERROR("SPACING",
2517 "space prohibited before that close parenthesis ')'\n" . $herecurr);
2377 } 2518 }
2378 2519
2379#goto labels aren't indented, allow a single space however 2520#goto labels aren't indented, allow a single space however
2380 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and 2521 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
2381 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { 2522 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {
2382 WARN("labels should not be indented\n" . $herecurr); 2523 WARN("INDENTED_LABEL",
2524 "labels should not be indented\n" . $herecurr);
2383 } 2525 }
2384 2526
2385# Return is not a function. 2527# Return is not a function.
@@ -2398,17 +2540,20 @@ sub process {
2398 } 2540 }
2399#print "value<$value>\n"; 2541#print "value<$value>\n";
2400 if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) { 2542 if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) {
2401 ERROR("return is not a function, parentheses are not required\n" . $herecurr); 2543 ERROR("RETURN_PARENTHESES",
2544 "return is not a function, parentheses are not required\n" . $herecurr);
2402 2545
2403 } elsif ($spacing !~ /\s+/) { 2546 } elsif ($spacing !~ /\s+/) {
2404 ERROR("space required before the open parenthesis '('\n" . $herecurr); 2547 ERROR("SPACING",
2548 "space required before the open parenthesis '('\n" . $herecurr);
2405 } 2549 }
2406 } 2550 }
2407# Return of what appears to be an errno should normally be -'ve 2551# Return of what appears to be an errno should normally be -'ve
2408 if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { 2552 if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) {
2409 my $name = $1; 2553 my $name = $1;
2410 if ($name ne 'EOF' && $name ne 'ERROR') { 2554 if ($name ne 'EOF' && $name ne 'ERROR') {
2411 WARN("return of an errno should typically be -ve (return -$1)\n" . $herecurr); 2555 WARN("USE_NEGATIVE_ERRNO",
2556 "return of an errno should typically be -ve (return -$1)\n" . $herecurr);
2412 } 2557 }
2413 } 2558 }
2414 2559
@@ -2435,7 +2580,7 @@ sub process {
2435 2580
2436# Need a space before open parenthesis after if, while etc 2581# Need a space before open parenthesis after if, while etc
2437 if ($line=~/\b(if|while|for|switch)\(/) { 2582 if ($line=~/\b(if|while|for|switch)\(/) {
2438 ERROR("space required before the open parenthesis '('\n" . $herecurr); 2583 ERROR("SPACING", "space required before the open parenthesis '('\n" . $herecurr);
2439 } 2584 }
2440 2585
2441# Check for illegal assignment in if conditional -- and check for trailing 2586# Check for illegal assignment in if conditional -- and check for trailing
@@ -2463,7 +2608,8 @@ sub process {
2463 my ($s, $c) = ($stat, $cond); 2608 my ($s, $c) = ($stat, $cond);
2464 2609
2465 if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) { 2610 if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) {
2466 ERROR("do not use assignment in if condition\n" . $herecurr); 2611 ERROR("ASSIGN_IN_IF",
2612 "do not use assignment in if condition\n" . $herecurr);
2467 } 2613 }
2468 2614
2469 # Find out what is on the end of the line after the 2615 # Find out what is on the end of the line after the
@@ -2485,7 +2631,8 @@ sub process {
2485 $stat_real = "[...]\n$stat_real"; 2631 $stat_real = "[...]\n$stat_real";
2486 } 2632 }
2487 2633
2488 ERROR("trailing statements should be on next line\n" . $herecurr . $stat_real); 2634 ERROR("TRAILING_STATEMENTS",
2635 "trailing statements should be on next line\n" . $herecurr . $stat_real);
2489 } 2636 }
2490 } 2637 }
2491 2638
@@ -2501,7 +2648,8 @@ sub process {
2501 (?:\&\&|\|\||\)|\]) 2648 (?:\&\&|\|\||\)|\])
2502 )/x) 2649 )/x)
2503 { 2650 {
2504 WARN("boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr); 2651 WARN("HEXADECIMAL_BOOLEAN_TEST",
2652 "boolean test with hexadecimal, perhaps just 1 \& or \|?\n" . $herecurr);
2505 } 2653 }
2506 2654
2507# if and else should not have general statements after it 2655# if and else should not have general statements after it
@@ -2509,12 +2657,14 @@ sub process {
2509 my $s = $1; 2657 my $s = $1;
2510 $s =~ s/$;//g; # Remove any comments 2658 $s =~ s/$;//g; # Remove any comments
2511 if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) { 2659 if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) {
2512 ERROR("trailing statements should be on next line\n" . $herecurr); 2660 ERROR("TRAILING_STATEMENTS",
2661 "trailing statements should be on next line\n" . $herecurr);
2513 } 2662 }
2514 } 2663 }
2515# if should not continue a brace 2664# if should not continue a brace
2516 if ($line =~ /}\s*if\b/) { 2665 if ($line =~ /}\s*if\b/) {
2517 ERROR("trailing statements should be on next line\n" . 2666 ERROR("TRAILING_STATEMENTS",
2667 "trailing statements should be on next line\n" .
2518 $herecurr); 2668 $herecurr);
2519 } 2669 }
2520# case and default should not have general statements after them 2670# case and default should not have general statements after them
@@ -2524,14 +2674,16 @@ sub process {
2524 \s*return\s+ 2674 \s*return\s+
2525 )/xg) 2675 )/xg)
2526 { 2676 {
2527 ERROR("trailing statements should be on next line\n" . $herecurr); 2677 ERROR("TRAILING_STATEMENTS",
2678 "trailing statements should be on next line\n" . $herecurr);
2528 } 2679 }
2529 2680
2530 # Check for }<nl>else {, these must be at the same 2681 # Check for }<nl>else {, these must be at the same
2531 # indent level to be relevant to each other. 2682 # indent level to be relevant to each other.
2532 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and 2683 if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and
2533 $previndent == $indent) { 2684 $previndent == $indent) {
2534 ERROR("else should follow close brace '}'\n" . $hereprev); 2685 ERROR("ELSE_AFTER_BRACE",
2686 "else should follow close brace '}'\n" . $hereprev);
2535 } 2687 }
2536 2688
2537 if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and 2689 if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and
@@ -2544,7 +2696,8 @@ sub process {
2544 $s =~ s/\n.*//g; 2696 $s =~ s/\n.*//g;
2545 2697
2546 if ($s =~ /^\s*;/) { 2698 if ($s =~ /^\s*;/) {
2547 ERROR("while should follow close brace '}'\n" . $hereprev); 2699 ERROR("WHILE_AFTER_BRACE",
2700 "while should follow close brace '}'\n" . $hereprev);
2548 } 2701 }
2549 } 2702 }
2550 2703
@@ -2557,7 +2710,8 @@ sub process {
2557 2710
2558#no spaces allowed after \ in define 2711#no spaces allowed after \ in define
2559 if ($line=~/\#\s*define.*\\\s$/) { 2712 if ($line=~/\#\s*define.*\\\s$/) {
2560 WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr); 2713 WARN("WHITESPACE_AFTER_LINE_CONTINUATION",
2714 "Whitepspace after \\ makes next lines useless\n" . $herecurr);
2561 } 2715 }
2562 2716
2563#warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line) 2717#warn if <asm/foo.h> is #included and <linux/foo.h> is available (uses RAW line)
@@ -2569,9 +2723,11 @@ sub process {
2569 $1 !~ /$allowed_asm_includes/) 2723 $1 !~ /$allowed_asm_includes/)
2570 { 2724 {
2571 if ($realfile =~ m{^arch/}) { 2725 if ($realfile =~ m{^arch/}) {
2572 CHK("Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr); 2726 CHK("ARCH_INCLUDE_LINUX",
2727 "Consider using #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
2573 } else { 2728 } else {
2574 WARN("Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr); 2729 WARN("INCLUDE_LINUX",
2730 "Use #include <linux/$file> instead of <asm/$file>\n" . $herecurr);
2575 } 2731 }
2576 } 2732 }
2577 } 2733 }
@@ -2655,7 +2811,8 @@ sub process {
2655 if ($rest !~ /while\s*\(/ && 2811 if ($rest !~ /while\s*\(/ &&
2656 $dstat !~ /$exceptions/) 2812 $dstat !~ /$exceptions/)
2657 { 2813 {
2658 ERROR("Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n"); 2814 ERROR("MULTISTATEMENT_MACRO_USE_DO_WHILE",
2815 "Macros with multiple statements should be enclosed in a do - while loop\n" . "$here\n$ctx\n");
2659 } 2816 }
2660 2817
2661 } elsif ($ctx !~ /;/) { 2818 } elsif ($ctx !~ /;/) {
@@ -2665,7 +2822,8 @@ sub process {
2665 $dstat !~ /^\.$Ident\s*=/ && 2822 $dstat !~ /^\.$Ident\s*=/ &&
2666 $dstat =~ /$Operators/) 2823 $dstat =~ /$Operators/)
2667 { 2824 {
2668 ERROR("Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n"); 2825 ERROR("COMPLEX_MACRO",
2826 "Macros with complex values should be enclosed in parenthesis\n" . "$here\n$ctx\n");
2669 } 2827 }
2670 } 2828 }
2671 } 2829 }
@@ -2676,7 +2834,8 @@ sub process {
2676# ALIGN(...) 2834# ALIGN(...)
2677# VMLINUX_SYMBOL(...) 2835# VMLINUX_SYMBOL(...)
2678 if ($realfile eq 'vmlinux.lds.h' && $line =~ /(?:(?:^|\s)$Ident\s*=|=\s*$Ident(?:\s|$))/) { 2836 if ($realfile eq 'vmlinux.lds.h' && $line =~ /(?:(?:^|\s)$Ident\s*=|=\s*$Ident(?:\s|$))/) {
2679 WARN("vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr); 2837 WARN("MISSING_VMLINUX_SYMBOL",
2838 "vmlinux.lds.h needs VMLINUX_SYMBOL() around C-visible symbols\n" . $herecurr);
2680 } 2839 }
2681 2840
2682# check for redundant bracing round if etc 2841# check for redundant bracing round if etc
@@ -2724,7 +2883,8 @@ sub process {
2724 } 2883 }
2725 } 2884 }
2726 if ($seen && !$allowed) { 2885 if ($seen && !$allowed) {
2727 WARN("braces {} are not necessary for any arm of this statement\n" . $herectx); 2886 WARN("BRACES",
2887 "braces {} are not necessary for any arm of this statement\n" . $herectx);
2728 } 2888 }
2729 } 2889 }
2730 } 2890 }
@@ -2778,33 +2938,38 @@ sub process {
2778 $herectx .= raw_line($linenr, $n) . "\n";; 2938 $herectx .= raw_line($linenr, $n) . "\n";;
2779 } 2939 }
2780 2940
2781 WARN("braces {} are not necessary for single statement blocks\n" . $herectx); 2941 WARN("BRACES",
2942 "braces {} are not necessary for single statement blocks\n" . $herectx);
2782 } 2943 }
2783 } 2944 }
2784 2945
2785# don't include deprecated include files (uses RAW line) 2946# don't include deprecated include files (uses RAW line)
2786 for my $inc (@dep_includes) { 2947 for my $inc (@dep_includes) {
2787 if ($rawline =~ m@^.\s*\#\s*include\s*\<$inc>@) { 2948 if ($rawline =~ m@^.\s*\#\s*include\s*\<$inc>@) {
2788 ERROR("Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr); 2949 ERROR("DEPRECATED_INCLUDE",
2950 "Don't use <$inc>: see Documentation/feature-removal-schedule.txt\n" . $herecurr);
2789 } 2951 }
2790 } 2952 }
2791 2953
2792# don't use deprecated functions 2954# don't use deprecated functions
2793 for my $func (@dep_functions) { 2955 for my $func (@dep_functions) {
2794 if ($line =~ /\b$func\b/) { 2956 if ($line =~ /\b$func\b/) {
2795 ERROR("Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr); 2957 ERROR("DEPRECATED_FUNCTION",
2958 "Don't use $func(): see Documentation/feature-removal-schedule.txt\n" . $herecurr);
2796 } 2959 }
2797 } 2960 }
2798 2961
2799# no volatiles please 2962# no volatiles please
2800 my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; 2963 my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b};
2801 if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { 2964 if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) {
2802 WARN("Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr); 2965 WARN("VOLATILE",
2966 "Use of volatile is usually wrong: see Documentation/volatile-considered-harmful.txt\n" . $herecurr);
2803 } 2967 }
2804 2968
2805# warn about #if 0 2969# warn about #if 0
2806 if ($line =~ /^.\s*\#\s*if\s+0\b/) { 2970 if ($line =~ /^.\s*\#\s*if\s+0\b/) {
2807 CHK("if this code is redundant consider removing it\n" . 2971 CHK("REDUNDANT_CODE",
2972 "if this code is redundant consider removing it\n" .
2808 $herecurr); 2973 $herecurr);
2809 } 2974 }
2810 2975
@@ -2812,14 +2977,16 @@ sub process {
2812 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { 2977 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
2813 my $expr = $1; 2978 my $expr = $1;
2814 if ($line =~ /\bkfree\(\Q$expr\E\);/) { 2979 if ($line =~ /\bkfree\(\Q$expr\E\);/) {
2815 WARN("kfree(NULL) is safe this check is probably not required\n" . $hereprev); 2980 WARN("NEEDLESS_KFREE",
2981 "kfree(NULL) is safe this check is probably not required\n" . $hereprev);
2816 } 2982 }
2817 } 2983 }
2818# check for needless usb_free_urb() checks 2984# check for needless usb_free_urb() checks
2819 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { 2985 if ($prevline =~ /\bif\s*\(([^\)]*)\)/) {
2820 my $expr = $1; 2986 my $expr = $1;
2821 if ($line =~ /\busb_free_urb\(\Q$expr\E\);/) { 2987 if ($line =~ /\busb_free_urb\(\Q$expr\E\);/) {
2822 WARN("usb_free_urb(NULL) is safe this check is probably not required\n" . $hereprev); 2988 WARN("NEEDLESS_USB_FREE_URB",
2989 "usb_free_urb(NULL) is safe this check is probably not required\n" . $hereprev);
2823 } 2990 }
2824 } 2991 }
2825 2992
@@ -2827,14 +2994,16 @@ sub process {
2827 if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) { 2994 if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) {
2828 # ignore udelay's < 10, however 2995 # ignore udelay's < 10, however
2829 if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) { 2996 if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) {
2830 CHK("usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line); 2997 CHK("USLEEP_RANGE",
2998 "usleep_range is preferred over udelay; see Documentation/timers/timers-howto.txt\n" . $line);
2831 } 2999 }
2832 } 3000 }
2833 3001
2834# warn about unexpectedly long msleep's 3002# warn about unexpectedly long msleep's
2835 if ($line =~ /\bmsleep\s*\((\d+)\);/) { 3003 if ($line =~ /\bmsleep\s*\((\d+)\);/) {
2836 if ($1 < 20) { 3004 if ($1 < 20) {
2837 WARN("msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line); 3005 WARN("MSLEEP",
3006 "msleep < 20ms can sleep for up to 20ms; see Documentation/timers/timers-howto.txt\n" . $line);
2838 } 3007 }
2839 } 3008 }
2840 3009
@@ -2847,7 +3016,8 @@ sub process {
2847 3016
2848# warn about spacing in #ifdefs 3017# warn about spacing in #ifdefs
2849 if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) { 3018 if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) {
2850 ERROR("exactly one space required after that #$1\n" . $herecurr); 3019 ERROR("SPACING",
3020 "exactly one space required after that #$1\n" . $herecurr);
2851 } 3021 }
2852 3022
2853# check for spinlock_t definitions without a comment. 3023# check for spinlock_t definitions without a comment.
@@ -2855,55 +3025,65 @@ sub process {
2855 $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) { 3025 $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) {
2856 my $which = $1; 3026 my $which = $1;
2857 if (!ctx_has_comment($first_line, $linenr)) { 3027 if (!ctx_has_comment($first_line, $linenr)) {
2858 CHK("$1 definition without comment\n" . $herecurr); 3028 CHK("UNCOMMENTED_DEFINITION",
3029 "$1 definition without comment\n" . $herecurr);
2859 } 3030 }
2860 } 3031 }
2861# check for memory barriers without a comment. 3032# check for memory barriers without a comment.
2862 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) { 3033 if ($line =~ /\b(mb|rmb|wmb|read_barrier_depends|smp_mb|smp_rmb|smp_wmb|smp_read_barrier_depends)\(/) {
2863 if (!ctx_has_comment($first_line, $linenr)) { 3034 if (!ctx_has_comment($first_line, $linenr)) {
2864 CHK("memory barrier without comment\n" . $herecurr); 3035 CHK("MEMORY_BARRIER",
3036 "memory barrier without comment\n" . $herecurr);
2865 } 3037 }
2866 } 3038 }
2867# check of hardware specific defines 3039# check of hardware specific defines
2868 if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) { 3040 if ($line =~ m@^.\s*\#\s*if.*\b(__i386__|__powerpc64__|__sun__|__s390x__)\b@ && $realfile !~ m@include/asm-@) {
2869 CHK("architecture specific defines should be avoided\n" . $herecurr); 3041 CHK("ARCH_DEFINES",
3042 "architecture specific defines should be avoided\n" . $herecurr);
2870 } 3043 }
2871 3044
2872# Check that the storage class is at the beginning of a declaration 3045# Check that the storage class is at the beginning of a declaration
2873 if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) { 3046 if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) {
2874 WARN("storage class should be at the beginning of the declaration\n" . $herecurr) 3047 WARN("STORAGE_CLASS",
3048 "storage class should be at the beginning of the declaration\n" . $herecurr)
2875 } 3049 }
2876 3050
2877# check the location of the inline attribute, that it is between 3051# check the location of the inline attribute, that it is between
2878# storage class and type. 3052# storage class and type.
2879 if ($line =~ /\b$Type\s+$Inline\b/ || 3053 if ($line =~ /\b$Type\s+$Inline\b/ ||
2880 $line =~ /\b$Inline\s+$Storage\b/) { 3054 $line =~ /\b$Inline\s+$Storage\b/) {
2881 ERROR("inline keyword should sit between storage class and type\n" . $herecurr); 3055 ERROR("INLINE_LOCATION",
3056 "inline keyword should sit between storage class and type\n" . $herecurr);
2882 } 3057 }
2883 3058
2884# Check for __inline__ and __inline, prefer inline 3059# Check for __inline__ and __inline, prefer inline
2885 if ($line =~ /\b(__inline__|__inline)\b/) { 3060 if ($line =~ /\b(__inline__|__inline)\b/) {
2886 WARN("plain inline is preferred over $1\n" . $herecurr); 3061 WARN("INLINE",
3062 "plain inline is preferred over $1\n" . $herecurr);
2887 } 3063 }
2888 3064
2889# Check for __attribute__ packed, prefer __packed 3065# Check for __attribute__ packed, prefer __packed
2890 if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) { 3066 if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) {
2891 WARN("__packed is preferred over __attribute__((packed))\n" . $herecurr); 3067 WARN("PREFER_PACKED",
3068 "__packed is preferred over __attribute__((packed))\n" . $herecurr);
2892 } 3069 }
2893 3070
2894# Check for __attribute__ aligned, prefer __aligned 3071# Check for __attribute__ aligned, prefer __aligned
2895 if ($line =~ /\b__attribute__\s*\(\s*\(.*aligned/) { 3072 if ($line =~ /\b__attribute__\s*\(\s*\(.*aligned/) {
2896 WARN("__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr); 3073 WARN("PREFER_ALIGNED",
3074 "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr);
2897 } 3075 }
2898 3076
2899# check for sizeof(&) 3077# check for sizeof(&)
2900 if ($line =~ /\bsizeof\s*\(\s*\&/) { 3078 if ($line =~ /\bsizeof\s*\(\s*\&/) {
2901 WARN("sizeof(& should be avoided\n" . $herecurr); 3079 WARN("SIZEOF_ADDRESS",
3080 "sizeof(& should be avoided\n" . $herecurr);
2902 } 3081 }
2903 3082
2904# check for line continuations in quoted strings with odd counts of " 3083# check for line continuations in quoted strings with odd counts of "
2905 if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) { 3084 if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) {
2906 WARN("Avoid line continuations in quoted strings\n" . $herecurr); 3085 WARN("LINE_CONTINUATIONS",
3086 "Avoid line continuations in quoted strings\n" . $herecurr);
2907 } 3087 }
2908 3088
2909# check for new externs in .c files. 3089# check for new externs in .c files.
@@ -2920,17 +3100,20 @@ sub process {
2920 if ($s =~ /^\s*;/ && 3100 if ($s =~ /^\s*;/ &&
2921 $function_name ne 'uninitialized_var') 3101 $function_name ne 'uninitialized_var')
2922 { 3102 {
2923 WARN("externs should be avoided in .c files\n" . $herecurr); 3103 WARN("AVOID_EXTERNS",
3104 "externs should be avoided in .c files\n" . $herecurr);
2924 } 3105 }
2925 3106
2926 if ($paren_space =~ /\n/) { 3107 if ($paren_space =~ /\n/) {
2927 WARN("arguments for function declarations should follow identifier\n" . $herecurr); 3108 WARN("FUNCTION_ARGUMENTS",
3109 "arguments for function declarations should follow identifier\n" . $herecurr);
2928 } 3110 }
2929 3111
2930 } elsif ($realfile =~ /\.c$/ && defined $stat && 3112 } elsif ($realfile =~ /\.c$/ && defined $stat &&
2931 $stat =~ /^.\s*extern\s+/) 3113 $stat =~ /^.\s*extern\s+/)
2932 { 3114 {
2933 WARN("externs should be avoided in .c files\n" . $herecurr); 3115 WARN("AVOID_EXTERNS",
3116 "externs should be avoided in .c files\n" . $herecurr);
2934 } 3117 }
2935 3118
2936# checks for new __setup's 3119# checks for new __setup's
@@ -2938,37 +3121,44 @@ sub process {
2938 my $name = $1; 3121 my $name = $1;
2939 3122
2940 if (!grep(/$name/, @setup_docs)) { 3123 if (!grep(/$name/, @setup_docs)) {
2941 CHK("__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr); 3124 CHK("UNDOCUMENTED_SETUP",
3125 "__setup appears un-documented -- check Documentation/kernel-parameters.txt\n" . $herecurr);
2942 } 3126 }
2943 } 3127 }
2944 3128
2945# check for pointless casting of kmalloc return 3129# check for pointless casting of kmalloc return
2946 if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) { 3130 if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) {
2947 WARN("unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); 3131 WARN("UNNECESSARY_CASTS",
3132 "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
2948 } 3133 }
2949 3134
2950# check for multiple semicolons 3135# check for multiple semicolons
2951 if ($line =~ /;\s*;\s*$/) { 3136 if ($line =~ /;\s*;\s*$/) {
2952 WARN("Statements terminations use 1 semicolon\n" . $herecurr); 3137 WARN("ONE_SEMICOLON",
3138 "Statements terminations use 1 semicolon\n" . $herecurr);
2953 } 3139 }
2954 3140
2955# check for gcc specific __FUNCTION__ 3141# check for gcc specific __FUNCTION__
2956 if ($line =~ /__FUNCTION__/) { 3142 if ($line =~ /__FUNCTION__/) {
2957 WARN("__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr); 3143 WARN("USE_FUNC",
3144 "__func__ should be used instead of gcc specific __FUNCTION__\n" . $herecurr);
2958 } 3145 }
2959 3146
2960# check for semaphores initialized locked 3147# check for semaphores initialized locked
2961 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) { 3148 if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) {
2962 WARN("consider using a completion\n" . $herecurr); 3149 WARN("CONSIDER_COMPLETION",
3150 "consider using a completion\n" . $herecurr);
2963 3151
2964 } 3152 }
2965# recommend kstrto* over simple_strto* 3153# recommend kstrto* over simple_strto*
2966 if ($line =~ /\bsimple_(strto.*?)\s*\(/) { 3154 if ($line =~ /\bsimple_(strto.*?)\s*\(/) {
2967 WARN("consider using kstrto* in preference to simple_$1\n" . $herecurr); 3155 WARN("CONSIDER_KSTRTO",
3156 "consider using kstrto* in preference to simple_$1\n" . $herecurr);
2968 } 3157 }
2969# check for __initcall(), use device_initcall() explicitly please 3158# check for __initcall(), use device_initcall() explicitly please
2970 if ($line =~ /^.\s*__initcall\s*\(/) { 3159 if ($line =~ /^.\s*__initcall\s*\(/) {
2971 WARN("please use device_initcall() instead of __initcall()\n" . $herecurr); 3160 WARN("USE_DEVICE_INITCALL",
3161 "please use device_initcall() instead of __initcall()\n" . $herecurr);
2972 } 3162 }
2973# check for various ops structs, ensure they are const. 3163# check for various ops structs, ensure they are const.
2974 my $struct_ops = qr{acpi_dock_ops| 3164 my $struct_ops = qr{acpi_dock_ops|
@@ -3010,7 +3200,8 @@ sub process {
3010 wd_ops}x; 3200 wd_ops}x;
3011 if ($line !~ /\bconst\b/ && 3201 if ($line !~ /\bconst\b/ &&
3012 $line =~ /\bstruct\s+($struct_ops)\b/) { 3202 $line =~ /\bstruct\s+($struct_ops)\b/) {
3013 WARN("struct $1 should normally be const\n" . 3203 WARN("CONST_STRUCT",
3204 "struct $1 should normally be const\n" .
3014 $herecurr); 3205 $herecurr);
3015 } 3206 }
3016 3207
@@ -3023,7 +3214,8 @@ sub process {
3023 $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ && 3214 $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ &&
3024 $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/) 3215 $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/)
3025 { 3216 {
3026 WARN("usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr); 3217 WARN("NR_CPUS",
3218 "usage of NR_CPUS is often wrong - consider using cpu_possible(), num_possible_cpus(), for_each_possible_cpu(), etc\n" . $herecurr);
3027 } 3219 }
3028 3220
3029# check for %L{u,d,i} in strings 3221# check for %L{u,d,i} in strings
@@ -3032,7 +3224,8 @@ sub process {
3032 $string = substr($rawline, $-[1], $+[1] - $-[1]); 3224 $string = substr($rawline, $-[1], $+[1] - $-[1]);
3033 $string =~ s/%%/__/g; 3225 $string =~ s/%%/__/g;
3034 if ($string =~ /(?<!%)%L[udi]/) { 3226 if ($string =~ /(?<!%)%L[udi]/) {
3035 WARN("\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr); 3227 WARN("PRINTF_L",
3228 "\%Ld/%Lu are not-standard C, use %lld/%llu\n" . $herecurr);
3036 last; 3229 last;
3037 } 3230 }
3038 } 3231 }
@@ -3040,9 +3233,11 @@ sub process {
3040# whine mightly about in_atomic 3233# whine mightly about in_atomic
3041 if ($line =~ /\bin_atomic\s*\(/) { 3234 if ($line =~ /\bin_atomic\s*\(/) {
3042 if ($realfile =~ m@^drivers/@) { 3235 if ($realfile =~ m@^drivers/@) {
3043 ERROR("do not use in_atomic in drivers\n" . $herecurr); 3236 ERROR("IN_ATOMIC",
3237 "do not use in_atomic in drivers\n" . $herecurr);
3044 } elsif ($realfile !~ m@^kernel/@) { 3238 } elsif ($realfile !~ m@^kernel/@) {
3045 WARN("use of in_atomic() is incorrect outside core kernel code\n" . $herecurr); 3239 WARN("IN_ATOMIC",
3240 "use of in_atomic() is incorrect outside core kernel code\n" . $herecurr);
3046 } 3241 }
3047 } 3242 }
3048 3243
@@ -3052,18 +3247,21 @@ sub process {
3052 if ($realfile !~ m@^kernel/lockdep@ && 3247 if ($realfile !~ m@^kernel/lockdep@ &&
3053 $realfile !~ m@^include/linux/lockdep@ && 3248 $realfile !~ m@^include/linux/lockdep@ &&
3054 $realfile !~ m@^drivers/base/core@) { 3249 $realfile !~ m@^drivers/base/core@) {
3055 ERROR("lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr); 3250 ERROR("LOCKDEP",
3251 "lockdep_no_validate class is reserved for device->mutex.\n" . $herecurr);
3056 } 3252 }
3057 } 3253 }
3058 3254
3059 if ($line =~ /debugfs_create_file.*S_IWUGO/ || 3255 if ($line =~ /debugfs_create_file.*S_IWUGO/ ||
3060 $line =~ /DEVICE_ATTR.*S_IWUGO/ ) { 3256 $line =~ /DEVICE_ATTR.*S_IWUGO/ ) {
3061 WARN("Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr); 3257 WARN("EXPORTED_WORLD_WRITABLE",
3258 "Exporting world writable files is usually an error. Consider more restrictive permissions.\n" . $herecurr);
3062 } 3259 }
3063 3260
3064 # Check for memset with swapped arguments 3261 # Check for memset with swapped arguments
3065 if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) { 3262 if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) {
3066 ERROR("memset size is 3rd argument, not the second.\n" . $herecurr); 3263 ERROR("MEMSET",
3264 "memset size is 3rd argument, not the second.\n" . $herecurr);
3067 } 3265 }
3068 } 3266 }
3069 3267
@@ -3086,10 +3284,12 @@ sub process {
3086 } 3284 }
3087 3285
3088 if (!$is_patch) { 3286 if (!$is_patch) {
3089 ERROR("Does not appear to be a unified-diff format patch\n"); 3287 ERROR("NOT_UNIFIED_DIFF",
3288 "Does not appear to be a unified-diff format patch\n");
3090 } 3289 }
3091 if ($is_patch && $chk_signoff && $signoff == 0) { 3290 if ($is_patch && $chk_signoff && $signoff == 0) {
3092 ERROR("Missing Signed-off-by: line(s)\n"); 3291 ERROR("MISSING_SIGN_OFF",
3292 "Missing Signed-off-by: line(s)\n");
3093 } 3293 }
3094 3294
3095 print report_dump(); 3295 print report_dump();
@@ -3111,13 +3311,25 @@ sub process {
3111 } 3311 }
3112 } 3312 }
3113 3313
3314 if (keys %ignore_type) {
3315 print "NOTE: Ignored message types:";
3316 foreach my $ignore (sort keys %ignore_type) {
3317 print " $ignore";
3318 }
3319 print "\n";
3320 print "\n" if ($quiet == 0);
3321 }
3322
3114 if ($clean == 1 && $quiet == 0) { 3323 if ($clean == 1 && $quiet == 0) {
3115 print "$vname has no obvious style problems and is ready for submission.\n" 3324 print "$vname has no obvious style problems and is ready for submission.\n"
3116 } 3325 }
3117 if ($clean == 0 && $quiet == 0) { 3326 if ($clean == 0 && $quiet == 0) {
3118 print "$vname has style problems, please review. If any of these errors\n"; 3327 print << "EOM";
3119 print "are false positives report them to the maintainer, see\n"; 3328$vname has style problems, please review.
3120 print "CHECKPATCH in MAINTAINERS.\n"; 3329
3330If any of these errors are false positives, please report
3331them to the maintainer, see CHECKPATCH in MAINTAINERS.
3332EOM
3121 } 3333 }
3122 3334
3123 return $clean; 3335 return $clean;