diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-26 00:00:19 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2011-07-26 00:00:19 -0400 |
commit | 45b583b10a8b438b970e95a7d1d4db22c9e35004 (patch) | |
tree | 14fa481598289df0459580c582b48a9d95db51f6 /scripts/checkpatch.pl | |
parent | 154dd78d30b56ffb8b447f629bfcceb14150e5c4 (diff) | |
parent | f19da2ce8ef5e49b8b8ea199c3601dd45d71b262 (diff) |
Merge 'akpm' patch series
* Merge akpm patch series: (122 commits)
drivers/connector/cn_proc.c: remove unused local
Documentation/SubmitChecklist: add RCU debug config options
reiserfs: use hweight_long()
reiserfs: use proper little-endian bitops
pnpacpi: register disabled resources
drivers/rtc/rtc-tegra.c: properly initialize spinlock
drivers/rtc/rtc-twl.c: check return value of twl_rtc_write_u8() in twl_rtc_set_time()
drivers/rtc: add support for Qualcomm PMIC8xxx RTC
drivers/rtc/rtc-s3c.c: support clock gating
drivers/rtc/rtc-mpc5121.c: add support for RTC on MPC5200
init: skip calibration delay if previously done
misc/eeprom: add eeprom access driver for digsy_mtc board
misc/eeprom: add driver for microwire 93xx46 EEPROMs
checkpatch.pl: update $logFunctions
checkpatch: make utf-8 test --strict
checkpatch.pl: add ability to ignore various messages
checkpatch: add a "prefer __aligned" check
checkpatch: validate signature styles and To: and Cc: lines
checkpatch: add __rcu as a sparse modifier
checkpatch: suggest using min_t or max_t
...
Did this as a merge because of (trivial) conflicts in
- Documentation/feature-removal-schedule.txt
- arch/xtensa/include/asm/uaccess.h
that were just easier to fix up in the merge than in the patch series.
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 656 |
1 files changed, 508 insertions, 148 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b0aa2c680593..9d761c95eca2 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -10,7 +10,7 @@ use strict; | |||
10 | my $P = $0; | 10 | my $P = $0; |
11 | $P =~ s@.*/@@g; | 11 | $P =~ s@.*/@@g; |
12 | 12 | ||
13 | my $V = '0.31'; | 13 | my $V = '0.32'; |
14 | 14 | ||
15 | use Getopt::Long qw(:config no_auto_abbrev); | 15 | use Getopt::Long qw(:config no_auto_abbrev); |
16 | 16 | ||
@@ -26,9 +26,13 @@ my $check = 0; | |||
26 | my $summary = 1; | 26 | my $summary = 1; |
27 | my $mailback = 0; | 27 | my $mailback = 0; |
28 | my $summary_file = 0; | 28 | my $summary_file = 0; |
29 | my $show_types = 0; | ||
29 | my $root; | 30 | my $root; |
30 | my %debug; | 31 | my %debug; |
32 | my %ignore_type = (); | ||
33 | my @ignore = (); | ||
31 | my $help = 0; | 34 | my $help = 0; |
35 | my $configuration_file = ".checkpatch.conf"; | ||
32 | 36 | ||
33 | sub help { | 37 | sub 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 | ||
72 | my $conf = which_conf($configuration_file); | ||
73 | if (-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 | |||
66 | GetOptions( | 98 | GetOptions( |
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)); | ||
131 | foreach 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 | |||
96 | my $dbg_values = 0; | 143 | my $dbg_values = 0; |
97 | my $dbg_possible = 0; | 144 | my $dbg_possible = 0; |
98 | my $dbg_type = 0; | 145 | my $dbg_type = 0; |
@@ -145,7 +192,8 @@ our $Sparse = qr{ | |||
145 | __must_check| | 192 | __must_check| |
146 | __init_refok| | 193 | __init_refok| |
147 | __kprobes| | 194 | __kprobes| |
148 | __ref | 195 | __ref| |
196 | __rcu | ||
149 | }x; | 197 | }x; |
150 | 198 | ||
151 | # Notes to $Attribute: | 199 | # Notes to $Attribute: |
@@ -209,13 +257,23 @@ our $typeTypedefs = qr{(?x: | |||
209 | )}; | 257 | )}; |
210 | 258 | ||
211 | our $logFunctions = qr{(?x: | 259 | our $logFunctions = qr{(?x: |
212 | printk| | 260 | printk(?:_ratelimited|_once|)| |
213 | [a-z]+_(emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)| | 261 | [a-z0-9]+_(?:printk|emerg|alert|crit|err|warning|warn|notice|info|debug|dbg|vdbg|devel|cont|WARN)(?:_ratelimited|_once|)| |
214 | WARN| | 262 | WARN(?:_RATELIMIT|_ONCE|)| |
215 | panic| | 263 | panic| |
216 | MODULE_[A-Z_]+ | 264 | MODULE_[A-Z_]+ |
217 | )}; | 265 | )}; |
218 | 266 | ||
267 | our $signature_tags = qr{(?xi: | ||
268 | Signed-off-by:| | ||
269 | Acked-by:| | ||
270 | Tested-by:| | ||
271 | Reviewed-by:| | ||
272 | Reported-by:| | ||
273 | To:| | ||
274 | Cc: | ||
275 | )}; | ||
276 | |||
219 | our @typeList = ( | 277 | our @typeList = ( |
220 | qr{void}, | 278 | qr{void}, |
221 | qr{(?:unsigned\s+)?char}, | 279 | qr{(?:unsigned\s+)?char}, |
@@ -268,6 +326,20 @@ sub build_types { | |||
268 | } | 326 | } |
269 | build_types(); | 327 | build_types(); |
270 | 328 | ||
329 | our $match_balanced_parentheses = qr/(\((?:[^\(\)]+|(-1))*\))/; | ||
330 | |||
331 | our $Typecast = qr{\s*(\(\s*$NonptrType\s*\)){0,1}\s*}; | ||
332 | our $LvalOrFunc = qr{($Lval)\s*($match_balanced_parentheses{0,1})\s*}; | ||
333 | |||
334 | sub deparenthesize { | ||
335 | my ($string) = @_; | ||
336 | return "" if (!defined($string)); | ||
337 | $string =~ s@^\s*\(\s*@@g; | ||
338 | $string =~ s@\s*\)\s*$@@g; | ||
339 | $string =~ s@\s+@ @g; | ||
340 | return $string; | ||
341 | } | ||
342 | |||
271 | $chk_signoff = 0 if ($file); | 343 | $chk_signoff = 0 if ($file); |
272 | 344 | ||
273 | my @dep_includes = (); | 345 | my @dep_includes = (); |
@@ -339,6 +411,88 @@ sub top_of_kernel_tree { | |||
339 | } | 411 | } |
340 | } | 412 | } |
341 | return 1; | 413 | return 1; |
414 | } | ||
415 | |||
416 | sub parse_email { | ||
417 | my ($formatted_email) = @_; | ||
418 | |||
419 | my $name = ""; | ||
420 | my $address = ""; | ||
421 | my $comment = ""; | ||
422 | |||
423 | if ($formatted_email =~ /^(.*)<(\S+\@\S+)>(.*)$/) { | ||
424 | $name = $1; | ||
425 | $address = $2; | ||
426 | $comment = $3 if defined $3; | ||
427 | } elsif ($formatted_email =~ /^\s*<(\S+\@\S+)>(.*)$/) { | ||
428 | $address = $1; | ||
429 | $comment = $2 if defined $2; | ||
430 | } elsif ($formatted_email =~ /(\S+\@\S+)(.*)$/) { | ||
431 | $address = $1; | ||
432 | $comment = $2 if defined $2; | ||
433 | $formatted_email =~ s/$address.*$//; | ||
434 | $name = $formatted_email; | ||
435 | $name =~ s/^\s+|\s+$//g; | ||
436 | $name =~ s/^\"|\"$//g; | ||
437 | # If there's a name left after stripping spaces and | ||
438 | # leading quotes, and the address doesn't have both | ||
439 | # leading and trailing angle brackets, the address | ||
440 | # is invalid. ie: | ||
441 | # "joe smith joe@smith.com" bad | ||
442 | # "joe smith <joe@smith.com" bad | ||
443 | if ($name ne "" && $address !~ /^<[^>]+>$/) { | ||
444 | $name = ""; | ||
445 | $address = ""; | ||
446 | $comment = ""; | ||
447 | } | ||
448 | } | ||
449 | |||
450 | $name =~ s/^\s+|\s+$//g; | ||
451 | $name =~ s/^\"|\"$//g; | ||
452 | $address =~ s/^\s+|\s+$//g; | ||
453 | $address =~ s/^\<|\>$//g; | ||
454 | |||
455 | if ($name =~ /[^\w \-]/i) { ##has "must quote" chars | ||
456 | $name =~ s/(?<!\\)"/\\"/g; ##escape quotes | ||
457 | $name = "\"$name\""; | ||
458 | } | ||
459 | |||
460 | return ($name, $address, $comment); | ||
461 | } | ||
462 | |||
463 | sub format_email { | ||
464 | my ($name, $address) = @_; | ||
465 | |||
466 | my $formatted_email; | ||
467 | |||
468 | $name =~ s/^\s+|\s+$//g; | ||
469 | $name =~ s/^\"|\"$//g; | ||
470 | $address =~ s/^\s+|\s+$//g; | ||
471 | |||
472 | if ($name =~ /[^\w \-]/i) { ##has "must quote" chars | ||
473 | $name =~ s/(?<!\\)"/\\"/g; ##escape quotes | ||
474 | $name = "\"$name\""; | ||
475 | } | ||
476 | |||
477 | if ("$name" eq "") { | ||
478 | $formatted_email = "$address"; | ||
479 | } else { | ||
480 | $formatted_email = "$name <$address>"; | ||
481 | } | ||
482 | |||
483 | return $formatted_email; | ||
484 | } | ||
485 | |||
486 | sub 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 ""; | ||
342 | } | 496 | } |
343 | 497 | ||
344 | sub expand_tabs { | 498 | sub expand_tabs { |
@@ -1086,12 +1240,21 @@ sub possible { | |||
1086 | 1240 | ||
1087 | my $prefix = ''; | 1241 | my $prefix = ''; |
1088 | 1242 | ||
1243 | sub show_type { | ||
1244 | return !defined $ignore_type{$_[0]}; | ||
1245 | } | ||
1246 | |||
1089 | sub report { | 1247 | sub report { |
1090 | if (defined $tst_only && $_[0] !~ /\Q$tst_only\E/) { | 1248 | if (!show_type($_[1]) || |
1249 | (defined $tst_only && $_[2] !~ /\Q$tst_only\E/)) { | ||
1091 | return 0; | 1250 | return 0; |
1092 | } | 1251 | } |
1093 | my $line = $prefix . $_[0]; | 1252 | my $line; |
1094 | 1253 | if ($show_types) { | |
1254 | $line = "$prefix$_[0]:$_[1]: $_[2]\n"; | ||
1255 | } else { | ||
1256 | $line = "$prefix$_[0]: $_[2]\n"; | ||
1257 | } | ||
1095 | $line = (split('\n', $line))[0] . "\n" if ($terse); | 1258 | $line = (split('\n', $line))[0] . "\n" if ($terse); |
1096 | 1259 | ||
1097 | push(our @report, $line); | 1260 | push(our @report, $line); |
@@ -1101,20 +1264,21 @@ sub report { | |||
1101 | sub report_dump { | 1264 | sub report_dump { |
1102 | our @report; | 1265 | our @report; |
1103 | } | 1266 | } |
1267 | |||
1104 | sub ERROR { | 1268 | sub ERROR { |
1105 | if (report("ERROR: $_[0]\n")) { | 1269 | if (report("ERROR", $_[0], $_[1])) { |
1106 | our $clean = 0; | 1270 | our $clean = 0; |
1107 | our $cnt_error++; | 1271 | our $cnt_error++; |
1108 | } | 1272 | } |
1109 | } | 1273 | } |
1110 | sub WARN { | 1274 | sub WARN { |
1111 | if (report("WARNING: $_[0]\n")) { | 1275 | if (report("WARNING", $_[0], $_[1])) { |
1112 | our $clean = 0; | 1276 | our $clean = 0; |
1113 | our $cnt_warn++; | 1277 | our $cnt_warn++; |
1114 | } | 1278 | } |
1115 | } | 1279 | } |
1116 | sub CHK { | 1280 | sub CHK { |
1117 | if ($check && report("CHECK: $_[0]\n")) { | 1281 | if ($check && report("CHECK", $_[0], $_[1])) { |
1118 | our $clean = 0; | 1282 | our $clean = 0; |
1119 | our $cnt_chk++; | 1283 | our $cnt_chk++; |
1120 | } | 1284 | } |
@@ -1143,7 +1307,8 @@ sub check_absolute_file { | |||
1143 | 1307 | ||
1144 | ##print "prefix<$prefix>\n"; | 1308 | ##print "prefix<$prefix>\n"; |
1145 | if ($prefix ne ".../") { | 1309 | if ($prefix ne ".../") { |
1146 | 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); | ||
1147 | } | 1312 | } |
1148 | } | 1313 | } |
1149 | 1314 | ||
@@ -1340,11 +1505,13 @@ sub process { | |||
1340 | $p1_prefix = $1; | 1505 | $p1_prefix = $1; |
1341 | if (!$file && $tree && $p1_prefix ne '' && | 1506 | if (!$file && $tree && $p1_prefix ne '' && |
1342 | -e "$root/$p1_prefix") { | 1507 | -e "$root/$p1_prefix") { |
1343 | 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"); | ||
1344 | } | 1510 | } |
1345 | 1511 | ||
1346 | if ($realfile =~ m@^include/asm/@) { | 1512 | if ($realfile =~ m@^include/asm/@) { |
1347 | 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"); | ||
1348 | } | 1515 | } |
1349 | next; | 1516 | next; |
1350 | } | 1517 | } |
@@ -1361,27 +1528,61 @@ sub process { | |||
1361 | if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) { | 1528 | if ($line =~ /^new (file )?mode.*[7531]\d{0,2}$/) { |
1362 | my $permhere = $here . "FILE: $realfile\n"; | 1529 | my $permhere = $here . "FILE: $realfile\n"; |
1363 | if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) { | 1530 | if ($realfile =~ /(Makefile|Kconfig|\.c|\.h|\.S|\.tmpl)$/) { |
1364 | 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); | ||
1365 | } | 1533 | } |
1366 | } | 1534 | } |
1367 | 1535 | ||
1368 | #check the patch for a signoff: | 1536 | # Check the patch for a signoff: |
1369 | if ($line =~ /^\s*signed-off-by:/i) { | 1537 | if ($line =~ /^\s*signed-off-by:/i) { |
1370 | # This is a signoff, if ugly, so do not double report. | ||
1371 | $signoff++; | 1538 | $signoff++; |
1372 | if (!($line =~ /^\s*Signed-off-by:/)) { | 1539 | } |
1373 | WARN("Signed-off-by: is the preferred form\n" . | 1540 | |
1374 | $herecurr); | 1541 | # Check signature styles |
1542 | if ($line =~ /^(\s*)($signature_tags)(\s*)(.*)/) { | ||
1543 | my $space_before = $1; | ||
1544 | my $sign_off = $2; | ||
1545 | my $space_after = $3; | ||
1546 | my $email = $4; | ||
1547 | my $ucfirst_sign_off = ucfirst(lc($sign_off)); | ||
1548 | |||
1549 | if (defined $space_before && $space_before ne "") { | ||
1550 | WARN("BAD_SIGN_OFF", | ||
1551 | "Do not use whitespace before $ucfirst_sign_off\n" . $herecurr); | ||
1375 | } | 1552 | } |
1376 | if ($line =~ /^\s*signed-off-by:\S/i) { | 1553 | if ($sign_off =~ /-by:$/i && $sign_off ne $ucfirst_sign_off) { |
1377 | WARN("space required after Signed-off-by:\n" . | 1554 | WARN("BAD_SIGN_OFF", |
1378 | $herecurr); | 1555 | "'$ucfirst_sign_off' is the preferred signature form\n" . $herecurr); |
1556 | } | ||
1557 | if (!defined $space_after || $space_after ne " ") { | ||
1558 | WARN("BAD_SIGN_OFF", | ||
1559 | "Use a single space after $ucfirst_sign_off\n" . $herecurr); | ||
1560 | } | ||
1561 | |||
1562 | my ($email_name, $email_address, $comment) = parse_email($email); | ||
1563 | my $suggested_email = format_email(($email_name, $email_address)); | ||
1564 | if ($suggested_email eq "") { | ||
1565 | ERROR("BAD_SIGN_OFF", | ||
1566 | "Unrecognized email address: '$email'\n" . $herecurr); | ||
1567 | } else { | ||
1568 | my $dequoted = $suggested_email; | ||
1569 | $dequoted =~ s/^"//; | ||
1570 | $dequoted =~ s/" </ </; | ||
1571 | # Don't force email to have quotes | ||
1572 | # Allow just an angle bracketed address | ||
1573 | if ("$dequoted$comment" ne $email && | ||
1574 | "<$email_address>$comment" ne $email && | ||
1575 | "$suggested_email$comment" ne $email) { | ||
1576 | WARN("BAD_SIGN_OFF", | ||
1577 | "email address '$email' might be better as '$suggested_email$comment'\n" . $herecurr); | ||
1578 | } | ||
1379 | } | 1579 | } |
1380 | } | 1580 | } |
1381 | 1581 | ||
1382 | # Check for wrappage within a valid hunk of the file | 1582 | # Check for wrappage within a valid hunk of the file |
1383 | if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) { | 1583 | if ($realcnt != 0 && $line !~ m{^(?:\+|-| |\\ No newline|$)}) { |
1384 | ERROR("patch seems to be corrupt (line wrapped?)\n" . | 1584 | ERROR("CORRUPTED_PATCH", |
1585 | "patch seems to be corrupt (line wrapped?)\n" . | ||
1385 | $herecurr) if (!$emitted_corrupt++); | 1586 | $herecurr) if (!$emitted_corrupt++); |
1386 | } | 1587 | } |
1387 | 1588 | ||
@@ -1408,7 +1609,8 @@ sub process { | |||
1408 | my $ptr = substr($blank, 0, length($utf8_prefix)) . "^"; | 1609 | my $ptr = substr($blank, 0, length($utf8_prefix)) . "^"; |
1409 | my $hereptr = "$hereline$ptr\n"; | 1610 | my $hereptr = "$hereline$ptr\n"; |
1410 | 1611 | ||
1411 | ERROR("Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr); | 1612 | CHK("INVALID_UTF8", |
1613 | "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr); | ||
1412 | } | 1614 | } |
1413 | 1615 | ||
1414 | # ignore non-hunk lines and lines being removed | 1616 | # ignore non-hunk lines and lines being removed |
@@ -1417,11 +1619,13 @@ sub process { | |||
1417 | #trailing whitespace | 1619 | #trailing whitespace |
1418 | if ($line =~ /^\+.*\015/) { | 1620 | if ($line =~ /^\+.*\015/) { |
1419 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; | 1621 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; |
1420 | ERROR("DOS line endings\n" . $herevet); | 1622 | ERROR("DOS_LINE_ENDINGS", |
1623 | "DOS line endings\n" . $herevet); | ||
1421 | 1624 | ||
1422 | } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { | 1625 | } elsif ($rawline =~ /^\+.*\S\s+$/ || $rawline =~ /^\+\s+$/) { |
1423 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; | 1626 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; |
1424 | ERROR("trailing whitespace\n" . $herevet); | 1627 | ERROR("TRAILING_WHITESPACE", |
1628 | "trailing whitespace\n" . $herevet); | ||
1425 | $rpt_cleaners = 1; | 1629 | $rpt_cleaners = 1; |
1426 | } | 1630 | } |
1427 | 1631 | ||
@@ -1452,7 +1656,8 @@ sub process { | |||
1452 | } | 1656 | } |
1453 | $length++; | 1657 | $length++; |
1454 | } | 1658 | } |
1455 | 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); | ||
1456 | #print "is_end<$is_end> length<$length>\n"; | 1661 | #print "is_end<$is_end> length<$length>\n"; |
1457 | } | 1662 | } |
1458 | 1663 | ||
@@ -1466,28 +1671,33 @@ sub process { | |||
1466 | $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && | 1671 | $line =~ /^\+\s*"[^"]*"\s*(?:\s*|,|\)\s*;)\s*$/) && |
1467 | $length > 80) | 1672 | $length > 80) |
1468 | { | 1673 | { |
1469 | WARN("line over 80 characters\n" . $herecurr); | 1674 | WARN("LONG_LINE", |
1675 | "line over 80 characters\n" . $herecurr); | ||
1470 | } | 1676 | } |
1471 | 1677 | ||
1472 | # check for spaces before a quoted newline | 1678 | # check for spaces before a quoted newline |
1473 | if ($rawline =~ /^.*\".*\s\\n/) { | 1679 | if ($rawline =~ /^.*\".*\s\\n/) { |
1474 | WARN("unnecessary whitespace before a quoted newline\n" . $herecurr); | 1680 | WARN("QUOTED_WHITESPACE_BEFORE_NEWLINE", |
1681 | "unnecessary whitespace before a quoted newline\n" . $herecurr); | ||
1475 | } | 1682 | } |
1476 | 1683 | ||
1477 | # check for adding lines without a newline. | 1684 | # check for adding lines without a newline. |
1478 | 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/) { |
1479 | 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); | ||
1480 | } | 1688 | } |
1481 | 1689 | ||
1482 | # Blackfin: use hi/lo macros | 1690 | # Blackfin: use hi/lo macros |
1483 | if ($realfile =~ m@arch/blackfin/.*\.S$@) { | 1691 | if ($realfile =~ m@arch/blackfin/.*\.S$@) { |
1484 | if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) { | 1692 | if ($line =~ /\.[lL][[:space:]]*=.*&[[:space:]]*0x[fF][fF][fF][fF]/) { |
1485 | my $herevet = "$here\n" . cat_vet($line) . "\n"; | 1693 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
1486 | ERROR("use the LO() macro, not (... & 0xFFFF)\n" . $herevet); | 1694 | ERROR("LO_MACRO", |
1695 | "use the LO() macro, not (... & 0xFFFF)\n" . $herevet); | ||
1487 | } | 1696 | } |
1488 | if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) { | 1697 | if ($line =~ /\.[hH][[:space:]]*=.*>>[[:space:]]*16/) { |
1489 | my $herevet = "$here\n" . cat_vet($line) . "\n"; | 1698 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
1490 | ERROR("use the HI() macro, not (... >> 16)\n" . $herevet); | 1699 | ERROR("HI_MACRO", |
1700 | "use the HI() macro, not (... >> 16)\n" . $herevet); | ||
1491 | } | 1701 | } |
1492 | } | 1702 | } |
1493 | 1703 | ||
@@ -1499,14 +1709,16 @@ sub process { | |||
1499 | if ($rawline =~ /^\+\s* \t\s*\S/ || | 1709 | if ($rawline =~ /^\+\s* \t\s*\S/ || |
1500 | $rawline =~ /^\+\s* \s*/) { | 1710 | $rawline =~ /^\+\s* \s*/) { |
1501 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; | 1711 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; |
1502 | ERROR("code indent should use tabs where possible\n" . $herevet); | 1712 | ERROR("CODE_INDENT", |
1713 | "code indent should use tabs where possible\n" . $herevet); | ||
1503 | $rpt_cleaners = 1; | 1714 | $rpt_cleaners = 1; |
1504 | } | 1715 | } |
1505 | 1716 | ||
1506 | # check for space before tabs. | 1717 | # check for space before tabs. |
1507 | if ($rawline =~ /^\+/ && $rawline =~ / \t/) { | 1718 | if ($rawline =~ /^\+/ && $rawline =~ / \t/) { |
1508 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; | 1719 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; |
1509 | WARN("please, no space before tabs\n" . $herevet); | 1720 | WARN("SPACE_BEFORE_TAB", |
1721 | "please, no space before tabs\n" . $herevet); | ||
1510 | } | 1722 | } |
1511 | 1723 | ||
1512 | # check for spaces at the beginning of a line. | 1724 | # check for spaces at the beginning of a line. |
@@ -1516,7 +1728,8 @@ sub process { | |||
1516 | # 3) hanging labels | 1728 | # 3) hanging labels |
1517 | if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) { | 1729 | if ($rawline =~ /^\+ / && $line !~ /\+ *(?:$;|#|$Ident:)/) { |
1518 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; | 1730 | my $herevet = "$here\n" . cat_vet($rawline) . "\n"; |
1519 | 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); | ||
1520 | } | 1733 | } |
1521 | 1734 | ||
1522 | # 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 |
@@ -1524,17 +1737,20 @@ sub process { | |||
1524 | 1737 | ||
1525 | # check for RCS/CVS revision markers | 1738 | # check for RCS/CVS revision markers |
1526 | if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) { | 1739 | if ($rawline =~ /^\+.*\$(Revision|Log|Id)(?:\$|)/) { |
1527 | 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); | ||
1528 | } | 1742 | } |
1529 | 1743 | ||
1530 | # Blackfin: don't use __builtin_bfin_[cs]sync | 1744 | # Blackfin: don't use __builtin_bfin_[cs]sync |
1531 | if ($line =~ /__builtin_bfin_csync/) { | 1745 | if ($line =~ /__builtin_bfin_csync/) { |
1532 | my $herevet = "$here\n" . cat_vet($line) . "\n"; | 1746 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
1533 | 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); | ||
1534 | } | 1749 | } |
1535 | if ($line =~ /__builtin_bfin_ssync/) { | 1750 | if ($line =~ /__builtin_bfin_ssync/) { |
1536 | my $herevet = "$here\n" . cat_vet($line) . "\n"; | 1751 | my $herevet = "$here\n" . cat_vet($line) . "\n"; |
1537 | 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); | ||
1538 | } | 1754 | } |
1539 | 1755 | ||
1540 | # Check for potential 'bare' types | 1756 | # Check for potential 'bare' types |
@@ -1623,7 +1839,8 @@ sub process { | |||
1623 | } | 1839 | } |
1624 | } | 1840 | } |
1625 | if ($err ne '') { | 1841 | if ($err ne '') { |
1626 | 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"); | ||
1627 | } | 1844 | } |
1628 | } | 1845 | } |
1629 | 1846 | ||
@@ -1651,7 +1868,8 @@ sub process { | |||
1651 | #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"; |
1652 | 1869 | ||
1653 | 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*{/) { |
1654 | 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" . | ||
1655 | "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); | 1873 | "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); |
1656 | } | 1874 | } |
1657 | if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ && | 1875 | if ($level == 0 && $pre_ctx !~ /}\s*while\s*\($/ && |
@@ -1660,7 +1878,8 @@ sub process { | |||
1660 | { | 1878 | { |
1661 | my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); | 1879 | my ($nlength, $nindent) = line_stats($lines[$ctx_ln - 1]); |
1662 | if ($nindent > $indent) { | 1880 | if ($nindent > $indent) { |
1663 | WARN("trailing semicolon indicates no statements, indent implies otherwise\n" . | 1881 | WARN("TRAILING_SEMICOLON", |
1882 | "trailing semicolon indicates no statements, indent implies otherwise\n" . | ||
1664 | "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); | 1883 | "$here\n$ctx\n$rawlines[$ctx_ln - 1]\n"); |
1665 | } | 1884 | } |
1666 | } | 1885 | } |
@@ -1748,7 +1967,8 @@ sub process { | |||
1748 | 1967 | ||
1749 | if ($check && (($sindent % 8) != 0 || | 1968 | if ($check && (($sindent % 8) != 0 || |
1750 | ($sindent <= $indent && $s ne ''))) { | 1969 | ($sindent <= $indent && $s ne ''))) { |
1751 | 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"); | ||
1752 | } | 1972 | } |
1753 | } | 1973 | } |
1754 | 1974 | ||
@@ -1771,18 +1991,22 @@ sub process { | |||
1771 | # TEST: allow direct testing of the type matcher. | 1991 | # TEST: allow direct testing of the type matcher. |
1772 | if ($dbg_type) { | 1992 | if ($dbg_type) { |
1773 | if ($line =~ /^.\s*$Declare\s*$/) { | 1993 | if ($line =~ /^.\s*$Declare\s*$/) { |
1774 | ERROR("TEST: is type\n" . $herecurr); | 1994 | ERROR("TEST_TYPE", |
1995 | "TEST: is type\n" . $herecurr); | ||
1775 | } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) { | 1996 | } elsif ($dbg_type > 1 && $line =~ /^.+($Declare)/) { |
1776 | ERROR("TEST: is not type ($1 is)\n". $herecurr); | 1997 | ERROR("TEST_NOT_TYPE", |
1998 | "TEST: is not type ($1 is)\n". $herecurr); | ||
1777 | } | 1999 | } |
1778 | next; | 2000 | next; |
1779 | } | 2001 | } |
1780 | # TEST: allow direct testing of the attribute matcher. | 2002 | # TEST: allow direct testing of the attribute matcher. |
1781 | if ($dbg_attr) { | 2003 | if ($dbg_attr) { |
1782 | if ($line =~ /^.\s*$Modifier\s*$/) { | 2004 | if ($line =~ /^.\s*$Modifier\s*$/) { |
1783 | ERROR("TEST: is attr\n" . $herecurr); | 2005 | ERROR("TEST_ATTR", |
2006 | "TEST: is attr\n" . $herecurr); | ||
1784 | } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) { | 2007 | } elsif ($dbg_attr > 1 && $line =~ /^.+($Modifier)/) { |
1785 | ERROR("TEST: is not attr ($1 is)\n". $herecurr); | 2008 | ERROR("TEST_NOT_ATTR", |
2009 | "TEST: is not attr ($1 is)\n". $herecurr); | ||
1786 | } | 2010 | } |
1787 | next; | 2011 | next; |
1788 | } | 2012 | } |
@@ -1790,7 +2014,8 @@ sub process { | |||
1790 | # check for initialisation to aggregates open brace on the next line | 2014 | # check for initialisation to aggregates open brace on the next line |
1791 | if ($line =~ /^.\s*{/ && | 2015 | if ($line =~ /^.\s*{/ && |
1792 | $prevline =~ /(?:^|[^=])=\s*$/) { | 2016 | $prevline =~ /(?:^|[^=])=\s*$/) { |
1793 | 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); | ||
1794 | } | 2019 | } |
1795 | 2020 | ||
1796 | # | 2021 | # |
@@ -1801,14 +2026,16 @@ sub process { | |||
1801 | if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) { | 2026 | if ($rawline =~ m{^.\s*\#\s*include\s+[<"](.*)[">]}) { |
1802 | my $path = $1; | 2027 | my $path = $1; |
1803 | if ($path =~ m{//}) { | 2028 | if ($path =~ m{//}) { |
1804 | ERROR("malformed #include filename\n" . | 2029 | ERROR("MALFORMED_INCLUDE", |
2030 | "malformed #include filename\n" . | ||
1805 | $herecurr); | 2031 | $herecurr); |
1806 | } | 2032 | } |
1807 | } | 2033 | } |
1808 | 2034 | ||
1809 | # no C99 // comments | 2035 | # no C99 // comments |
1810 | if ($line =~ m{//}) { | 2036 | if ($line =~ m{//}) { |
1811 | ERROR("do not use C99 // comments\n" . $herecurr); | 2037 | ERROR("C99_COMMENTS", |
2038 | "do not use C99 // comments\n" . $herecurr); | ||
1812 | } | 2039 | } |
1813 | # Remove C99 comments. | 2040 | # Remove C99 comments. |
1814 | $line =~ s@//.*@@; | 2041 | $line =~ s@//.*@@; |
@@ -1855,35 +2082,41 @@ sub process { | |||
1855 | } | 2082 | } |
1856 | if (defined $suppress_export{$linenr} && | 2083 | if (defined $suppress_export{$linenr} && |
1857 | $suppress_export{$linenr} == 2) { | 2084 | $suppress_export{$linenr} == 2) { |
1858 | 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); | ||
1859 | } | 2087 | } |
1860 | 2088 | ||
1861 | # check for global initialisers. | 2089 | # check for global initialisers. |
1862 | 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*;/) { |
1863 | ERROR("do not initialise globals to 0 or NULL\n" . | 2091 | ERROR("GLOBAL_INITIALISERS", |
2092 | "do not initialise globals to 0 or NULL\n" . | ||
1864 | $herecurr); | 2093 | $herecurr); |
1865 | } | 2094 | } |
1866 | # check for static initialisers. | 2095 | # check for static initialisers. |
1867 | if ($line =~ /\bstatic\s.*=\s*(0|NULL|false)\s*;/) { | 2096 | if ($line =~ /\bstatic\s.*=\s*(0|NULL|false)\s*;/) { |
1868 | ERROR("do not initialise statics to 0 or NULL\n" . | 2097 | ERROR("INITIALISED_STATIC", |
2098 | "do not initialise statics to 0 or NULL\n" . | ||
1869 | $herecurr); | 2099 | $herecurr); |
1870 | } | 2100 | } |
1871 | 2101 | ||
1872 | # check for static const char * arrays. | 2102 | # check for static const char * arrays. |
1873 | 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*/) { |
1874 | 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" . | ||
1875 | $herecurr); | 2106 | $herecurr); |
1876 | } | 2107 | } |
1877 | 2108 | ||
1878 | # check for static char foo[] = "bar" declarations. | 2109 | # check for static char foo[] = "bar" declarations. |
1879 | if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) { | 2110 | if ($line =~ /\bstatic\s+char\s+(\w+)\s*\[\s*\]\s*=\s*"/) { |
1880 | 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" . | ||
1881 | $herecurr); | 2113 | $herecurr); |
1882 | } | 2114 | } |
1883 | 2115 | ||
1884 | # check for declarations of struct pci_device_id | 2116 | # check for declarations of struct pci_device_id |
1885 | 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*\{/) { |
1886 | 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); | ||
1887 | } | 2120 | } |
1888 | 2121 | ||
1889 | # check for new typedefs, only function parameters and sparse annotations | 2122 | # check for new typedefs, only function parameters and sparse annotations |
@@ -1893,7 +2126,8 @@ sub process { | |||
1893 | $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && | 2126 | $line !~ /\btypedef\s+$Type\s+$Ident\s*\(/ && |
1894 | $line !~ /\b$typeTypedefs\b/ && | 2127 | $line !~ /\b$typeTypedefs\b/ && |
1895 | $line !~ /\b__bitwise(?:__|)\b/) { | 2128 | $line !~ /\b__bitwise(?:__|)\b/) { |
1896 | WARN("do not add new typedefs\n" . $herecurr); | 2129 | WARN("NEW_TYPEDEFS", |
2130 | "do not add new typedefs\n" . $herecurr); | ||
1897 | } | 2131 | } |
1898 | 2132 | ||
1899 | # * goes on variable not on type | 2133 | # * goes on variable not on type |
@@ -1911,7 +2145,8 @@ sub process { | |||
1911 | 2145 | ||
1912 | #print "from<$from> to<$to>\n"; | 2146 | #print "from<$from> to<$to>\n"; |
1913 | if ($from ne $to) { | 2147 | if ($from ne $to) { |
1914 | ERROR("\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr); | 2148 | ERROR("POINTER_LOCATION", |
2149 | "\"(foo$from)\" should be \"(foo$to)\"\n" . $herecurr); | ||
1915 | } | 2150 | } |
1916 | } elsif ($line =~ m{\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident)}) { | 2151 | } elsif ($line =~ m{\b$NonptrType(\s*(?:$Modifier\b\s*|\*\s*)+)($Ident)}) { |
1917 | my ($from, $to, $ident) = ($1, $1, $2); | 2152 | my ($from, $to, $ident) = ($1, $1, $2); |
@@ -1928,7 +2163,8 @@ sub process { | |||
1928 | 2163 | ||
1929 | #print "from<$from> to<$to> ident<$ident>\n"; | 2164 | #print "from<$from> to<$to> ident<$ident>\n"; |
1930 | if ($from ne $to && $ident !~ /^$Modifier$/) { | 2165 | if ($from ne $to && $ident !~ /^$Modifier$/) { |
1931 | 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); | ||
1932 | } | 2168 | } |
1933 | } | 2169 | } |
1934 | 2170 | ||
@@ -1940,12 +2176,14 @@ sub process { | |||
1940 | # } | 2176 | # } |
1941 | 2177 | ||
1942 | if ($line =~ /\bLINUX_VERSION_CODE\b/) { | 2178 | if ($line =~ /\bLINUX_VERSION_CODE\b/) { |
1943 | 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); | ||
1944 | } | 2181 | } |
1945 | 2182 | ||
1946 | # check for uses of printk_ratelimit | 2183 | # check for uses of printk_ratelimit |
1947 | if ($line =~ /\bprintk_ratelimit\s*\(/) { | 2184 | if ($line =~ /\bprintk_ratelimit\s*\(/) { |
1948 | 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); | ||
1949 | } | 2187 | } |
1950 | 2188 | ||
1951 | # 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 |
@@ -1967,7 +2205,8 @@ sub process { | |||
1967 | } | 2205 | } |
1968 | } | 2206 | } |
1969 | if ($ok == 0) { | 2207 | if ($ok == 0) { |
1970 | WARN("printk() should include KERN_ facility level\n" . $herecurr); | 2208 | WARN("PRINTK_WITHOUT_KERN_LEVEL", |
2209 | "printk() should include KERN_ facility level\n" . $herecurr); | ||
1971 | } | 2210 | } |
1972 | } | 2211 | } |
1973 | 2212 | ||
@@ -1975,18 +2214,21 @@ sub process { | |||
1975 | # or if closed on same line | 2214 | # or if closed on same line |
1976 | if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and | 2215 | if (($line=~/$Type\s*$Ident\(.*\).*\s{/) and |
1977 | !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) { | 2216 | !($line=~/\#\s*define.*do\s{/) and !($line=~/}/)) { |
1978 | 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); | ||
1979 | } | 2219 | } |
1980 | 2220 | ||
1981 | # 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. |
1982 | if ($line =~ /^.\s*{/ && | 2222 | if ($line =~ /^.\s*{/ && |
1983 | $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) { | 2223 | $prevline =~ /^.\s*(?:typedef\s+)?(enum|union|struct)(?:\s+$Ident)?\s*$/) { |
1984 | 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); | ||
1985 | } | 2226 | } |
1986 | 2227 | ||
1987 | # missing space after union, struct or enum definition | 2228 | # missing space after union, struct or enum definition |
1988 | 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)?[=\{]/) { |
1989 | WARN("missing space after $1 definition\n" . $herecurr); | 2230 | WARN("SPACING", |
2231 | "missing space after $1 definition\n" . $herecurr); | ||
1990 | } | 2232 | } |
1991 | 2233 | ||
1992 | # check for spacing round square brackets; allowed: | 2234 | # check for spacing round square brackets; allowed: |
@@ -1998,7 +2240,8 @@ sub process { | |||
1998 | if ($prefix !~ /$Type\s+$/ && | 2240 | if ($prefix !~ /$Type\s+$/ && |
1999 | ($where != 0 || $prefix !~ /^.\s+$/) && | 2241 | ($where != 0 || $prefix !~ /^.\s+$/) && |
2000 | $prefix !~ /{\s+$/) { | 2242 | $prefix !~ /{\s+$/) { |
2001 | ERROR("space prohibited before open square bracket '['\n" . $herecurr); | 2243 | ERROR("BRACKET_SPACE", |
2244 | "space prohibited before open square bracket '['\n" . $herecurr); | ||
2002 | } | 2245 | } |
2003 | } | 2246 | } |
2004 | 2247 | ||
@@ -2029,7 +2272,8 @@ sub process { | |||
2029 | } elsif ($ctx =~ /$Type$/) { | 2272 | } elsif ($ctx =~ /$Type$/) { |
2030 | 2273 | ||
2031 | } else { | 2274 | } else { |
2032 | 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); | ||
2033 | } | 2277 | } |
2034 | } | 2278 | } |
2035 | # Check operator spacing. | 2279 | # Check operator spacing. |
@@ -2103,7 +2347,8 @@ sub process { | |||
2103 | } elsif ($op eq ';') { | 2347 | } elsif ($op eq ';') { |
2104 | if ($ctx !~ /.x[WEBC]/ && | 2348 | if ($ctx !~ /.x[WEBC]/ && |
2105 | $cc !~ /^\\/ && $cc !~ /^;/) { | 2349 | $cc !~ /^\\/ && $cc !~ /^;/) { |
2106 | ERROR("space required after that '$op' $at\n" . $hereptr); | 2350 | ERROR("SPACING", |
2351 | "space required after that '$op' $at\n" . $hereptr); | ||
2107 | } | 2352 | } |
2108 | 2353 | ||
2109 | # // is a comment | 2354 | # // is a comment |
@@ -2114,13 +2359,15 @@ sub process { | |||
2114 | # : when part of a bitfield | 2359 | # : when part of a bitfield |
2115 | } elsif ($op eq '->' || $opv eq ':B') { | 2360 | } elsif ($op eq '->' || $opv eq ':B') { |
2116 | if ($ctx =~ /Wx.|.xW/) { | 2361 | if ($ctx =~ /Wx.|.xW/) { |
2117 | ERROR("spaces prohibited around that '$op' $at\n" . $hereptr); | 2362 | ERROR("SPACING", |
2363 | "spaces prohibited around that '$op' $at\n" . $hereptr); | ||
2118 | } | 2364 | } |
2119 | 2365 | ||
2120 | # , must have a space on the right. | 2366 | # , must have a space on the right. |
2121 | } elsif ($op eq ',') { | 2367 | } elsif ($op eq ',') { |
2122 | if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) { | 2368 | if ($ctx !~ /.x[WEC]/ && $cc !~ /^}/) { |
2123 | ERROR("space required after that '$op' $at\n" . $hereptr); | 2369 | ERROR("SPACING", |
2370 | "space required after that '$op' $at\n" . $hereptr); | ||
2124 | } | 2371 | } |
2125 | 2372 | ||
2126 | # '*' as part of a type definition -- reported already. | 2373 | # '*' as part of a type definition -- reported already. |
@@ -2134,26 +2381,31 @@ sub process { | |||
2134 | $opv eq '*U' || $opv eq '-U' || | 2381 | $opv eq '*U' || $opv eq '-U' || |
2135 | $opv eq '&U' || $opv eq '&&U') { | 2382 | $opv eq '&U' || $opv eq '&&U') { |
2136 | if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { | 2383 | if ($ctx !~ /[WEBC]x./ && $ca !~ /(?:\)|!|~|\*|-|\&|\||\+\+|\-\-|\{)$/) { |
2137 | ERROR("space required before that '$op' $at\n" . $hereptr); | 2384 | ERROR("SPACING", |
2385 | "space required before that '$op' $at\n" . $hereptr); | ||
2138 | } | 2386 | } |
2139 | if ($op eq '*' && $cc =~/\s*$Modifier\b/) { | 2387 | if ($op eq '*' && $cc =~/\s*$Modifier\b/) { |
2140 | # A unary '*' may be const | 2388 | # A unary '*' may be const |
2141 | 2389 | ||
2142 | } elsif ($ctx =~ /.xW/) { | 2390 | } elsif ($ctx =~ /.xW/) { |
2143 | ERROR("space prohibited after that '$op' $at\n" . $hereptr); | 2391 | ERROR("SPACING", |
2392 | "space prohibited after that '$op' $at\n" . $hereptr); | ||
2144 | } | 2393 | } |
2145 | 2394 | ||
2146 | # unary ++ and unary -- are allowed no space on one side. | 2395 | # unary ++ and unary -- are allowed no space on one side. |
2147 | } elsif ($op eq '++' or $op eq '--') { | 2396 | } elsif ($op eq '++' or $op eq '--') { |
2148 | if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) { | 2397 | if ($ctx !~ /[WEOBC]x[^W]/ && $ctx !~ /[^W]x[WOBEC]/) { |
2149 | 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); | ||
2150 | } | 2400 | } |
2151 | if ($ctx =~ /Wx[BE]/ || | 2401 | if ($ctx =~ /Wx[BE]/ || |
2152 | ($ctx =~ /Wx./ && $cc =~ /^;/)) { | 2402 | ($ctx =~ /Wx./ && $cc =~ /^;/)) { |
2153 | ERROR("space prohibited before that '$op' $at\n" . $hereptr); | 2403 | ERROR("SPACING", |
2404 | "space prohibited before that '$op' $at\n" . $hereptr); | ||
2154 | } | 2405 | } |
2155 | if ($ctx =~ /ExW/) { | 2406 | if ($ctx =~ /ExW/) { |
2156 | ERROR("space prohibited after that '$op' $at\n" . $hereptr); | 2407 | ERROR("SPACING", |
2408 | "space prohibited after that '$op' $at\n" . $hereptr); | ||
2157 | } | 2409 | } |
2158 | 2410 | ||
2159 | 2411 | ||
@@ -2165,7 +2417,8 @@ sub process { | |||
2165 | $op eq '%') | 2417 | $op eq '%') |
2166 | { | 2418 | { |
2167 | if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) { | 2419 | if ($ctx =~ /Wx[^WCE]|[^WCE]xW/) { |
2168 | ERROR("need consistent spacing around '$op' $at\n" . | 2420 | ERROR("SPACING", |
2421 | "need consistent spacing around '$op' $at\n" . | ||
2169 | $hereptr); | 2422 | $hereptr); |
2170 | } | 2423 | } |
2171 | 2424 | ||
@@ -2173,7 +2426,8 @@ sub process { | |||
2173 | # terminating a case value or a label. | 2426 | # terminating a case value or a label. |
2174 | } elsif ($opv eq ':C' || $opv eq ':L') { | 2427 | } elsif ($opv eq ':C' || $opv eq ':L') { |
2175 | if ($ctx =~ /Wx./) { | 2428 | if ($ctx =~ /Wx./) { |
2176 | ERROR("space prohibited before that '$op' $at\n" . $hereptr); | 2429 | ERROR("SPACING", |
2430 | "space prohibited before that '$op' $at\n" . $hereptr); | ||
2177 | } | 2431 | } |
2178 | 2432 | ||
2179 | # All the others need spaces both sides. | 2433 | # All the others need spaces both sides. |
@@ -2196,7 +2450,8 @@ sub process { | |||
2196 | } | 2450 | } |
2197 | 2451 | ||
2198 | if ($ok == 0) { | 2452 | if ($ok == 0) { |
2199 | ERROR("spaces required around that '$op' $at\n" . $hereptr); | 2453 | ERROR("SPACING", |
2454 | "spaces required around that '$op' $at\n" . $hereptr); | ||
2200 | } | 2455 | } |
2201 | } | 2456 | } |
2202 | $off += length($elements[$n + 1]); | 2457 | $off += length($elements[$n + 1]); |
@@ -2205,7 +2460,8 @@ sub process { | |||
2205 | 2460 | ||
2206 | # check for multiple assignments | 2461 | # check for multiple assignments |
2207 | if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) { | 2462 | if ($line =~ /^.\s*$Lval\s*=\s*$Lval\s*=(?!=)/) { |
2208 | CHK("multiple assignments should be avoided\n" . $herecurr); | 2463 | CHK("MULTIPLE_ASSIGNMENTS", |
2464 | "multiple assignments should be avoided\n" . $herecurr); | ||
2209 | } | 2465 | } |
2210 | 2466 | ||
2211 | ## # check for multiple declarations, allowing for a function declaration | 2467 | ## # check for multiple declarations, allowing for a function declaration |
@@ -2219,45 +2475,53 @@ sub process { | |||
2219 | ## while ($ln =~ s/\([^\(\)]*\)//g) { | 2475 | ## while ($ln =~ s/\([^\(\)]*\)//g) { |
2220 | ## } | 2476 | ## } |
2221 | ## if ($ln =~ /,/) { | 2477 | ## if ($ln =~ /,/) { |
2222 | ## WARN("declaring multiple variables together should be avoided\n" . $herecurr); | 2478 | ## WARN("MULTIPLE_DECLARATION", |
2479 | ## "declaring multiple variables together should be avoided\n" . $herecurr); | ||
2223 | ## } | 2480 | ## } |
2224 | ## } | 2481 | ## } |
2225 | 2482 | ||
2226 | #need space before brace following if, while, etc | 2483 | #need space before brace following if, while, etc |
2227 | if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || | 2484 | if (($line =~ /\(.*\){/ && $line !~ /\($Type\){/) || |
2228 | $line =~ /do{/) { | 2485 | $line =~ /do{/) { |
2229 | ERROR("space required before the open brace '{'\n" . $herecurr); | 2486 | ERROR("SPACING", |
2487 | "space required before the open brace '{'\n" . $herecurr); | ||
2230 | } | 2488 | } |
2231 | 2489 | ||
2232 | # 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 |
2233 | # on the line | 2491 | # on the line |
2234 | if ($line =~ /}(?!(?:,|;|\)))\S/) { | 2492 | if ($line =~ /}(?!(?:,|;|\)))\S/) { |
2235 | ERROR("space required after that close brace '}'\n" . $herecurr); | 2493 | ERROR("SPACING", |
2494 | "space required after that close brace '}'\n" . $herecurr); | ||
2236 | } | 2495 | } |
2237 | 2496 | ||
2238 | # check spacing on square brackets | 2497 | # check spacing on square brackets |
2239 | if ($line =~ /\[\s/ && $line !~ /\[\s*$/) { | 2498 | if ($line =~ /\[\s/ && $line !~ /\[\s*$/) { |
2240 | ERROR("space prohibited after that open square bracket '['\n" . $herecurr); | 2499 | ERROR("SPACING", |
2500 | "space prohibited after that open square bracket '['\n" . $herecurr); | ||
2241 | } | 2501 | } |
2242 | if ($line =~ /\s\]/) { | 2502 | if ($line =~ /\s\]/) { |
2243 | ERROR("space prohibited before that close square bracket ']'\n" . $herecurr); | 2503 | ERROR("SPACING", |
2504 | "space prohibited before that close square bracket ']'\n" . $herecurr); | ||
2244 | } | 2505 | } |
2245 | 2506 | ||
2246 | # check spacing on parentheses | 2507 | # check spacing on parentheses |
2247 | if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ && | 2508 | if ($line =~ /\(\s/ && $line !~ /\(\s*(?:\\)?$/ && |
2248 | $line !~ /for\s*\(\s+;/) { | 2509 | $line !~ /for\s*\(\s+;/) { |
2249 | ERROR("space prohibited after that open parenthesis '('\n" . $herecurr); | 2510 | ERROR("SPACING", |
2511 | "space prohibited after that open parenthesis '('\n" . $herecurr); | ||
2250 | } | 2512 | } |
2251 | if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ && | 2513 | if ($line =~ /(\s+)\)/ && $line !~ /^.\s*\)/ && |
2252 | $line !~ /for\s*\(.*;\s+\)/ && | 2514 | $line !~ /for\s*\(.*;\s+\)/ && |
2253 | $line !~ /:\s+\)/) { | 2515 | $line !~ /:\s+\)/) { |
2254 | ERROR("space prohibited before that close parenthesis ')'\n" . $herecurr); | 2516 | ERROR("SPACING", |
2517 | "space prohibited before that close parenthesis ')'\n" . $herecurr); | ||
2255 | } | 2518 | } |
2256 | 2519 | ||
2257 | #goto labels aren't indented, allow a single space however | 2520 | #goto labels aren't indented, allow a single space however |
2258 | if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and | 2521 | if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and |
2259 | !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { | 2522 | !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { |
2260 | WARN("labels should not be indented\n" . $herecurr); | 2523 | WARN("INDENTED_LABEL", |
2524 | "labels should not be indented\n" . $herecurr); | ||
2261 | } | 2525 | } |
2262 | 2526 | ||
2263 | # Return is not a function. | 2527 | # Return is not a function. |
@@ -2276,23 +2540,47 @@ sub process { | |||
2276 | } | 2540 | } |
2277 | #print "value<$value>\n"; | 2541 | #print "value<$value>\n"; |
2278 | if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) { | 2542 | if ($value =~ /^\s*(?:$Ident|-?$Constant)\s*$/) { |
2279 | 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); | ||
2280 | 2545 | ||
2281 | } elsif ($spacing !~ /\s+/) { | 2546 | } elsif ($spacing !~ /\s+/) { |
2282 | ERROR("space required before the open parenthesis '('\n" . $herecurr); | 2547 | ERROR("SPACING", |
2548 | "space required before the open parenthesis '('\n" . $herecurr); | ||
2283 | } | 2549 | } |
2284 | } | 2550 | } |
2285 | # 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 |
2286 | if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { | 2552 | if ($line =~ /^.\s*return\s*(E[A-Z]*)\s*;/) { |
2287 | my $name = $1; | 2553 | my $name = $1; |
2288 | if ($name ne 'EOF' && $name ne 'ERROR') { | 2554 | if ($name ne 'EOF' && $name ne 'ERROR') { |
2289 | 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); | ||
2557 | } | ||
2558 | } | ||
2559 | |||
2560 | # typecasts on min/max could be min_t/max_t | ||
2561 | if ($line =~ /^\+(?:.*?)\b(min|max)\s*\($Typecast{0,1}($LvalOrFunc)\s*,\s*$Typecast{0,1}($LvalOrFunc)\s*\)/) { | ||
2562 | if (defined $2 || defined $8) { | ||
2563 | my $call = $1; | ||
2564 | my $cast1 = deparenthesize($2); | ||
2565 | my $arg1 = $3; | ||
2566 | my $cast2 = deparenthesize($8); | ||
2567 | my $arg2 = $9; | ||
2568 | my $cast; | ||
2569 | |||
2570 | if ($cast1 ne "" && $cast2 ne "") { | ||
2571 | $cast = "$cast1 or $cast2"; | ||
2572 | } elsif ($cast1 ne "") { | ||
2573 | $cast = $cast1; | ||
2574 | } else { | ||
2575 | $cast = $cast2; | ||
2576 | } | ||
2577 | WARN("$call() should probably be ${call}_t($cast, $arg1, $arg2)\n" . $herecurr); | ||
2290 | } | 2578 | } |
2291 | } | 2579 | } |
2292 | 2580 | ||
2293 | # Need a space before open parenthesis after if, while etc | 2581 | # Need a space before open parenthesis after if, while etc |
2294 | if ($line=~/\b(if|while|for|switch)\(/) { | 2582 | if ($line=~/\b(if|while|for|switch)\(/) { |
2295 | ERROR("space required before the open parenthesis '('\n" . $herecurr); | 2583 | ERROR("SPACING", "space required before the open parenthesis '('\n" . $herecurr); |
2296 | } | 2584 | } |
2297 | 2585 | ||
2298 | # Check for illegal assignment in if conditional -- and check for trailing | 2586 | # Check for illegal assignment in if conditional -- and check for trailing |
@@ -2320,7 +2608,8 @@ sub process { | |||
2320 | my ($s, $c) = ($stat, $cond); | 2608 | my ($s, $c) = ($stat, $cond); |
2321 | 2609 | ||
2322 | if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) { | 2610 | if ($c =~ /\bif\s*\(.*[^<>!=]=[^=].*/s) { |
2323 | 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); | ||
2324 | } | 2613 | } |
2325 | 2614 | ||
2326 | # 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 |
@@ -2342,7 +2631,8 @@ sub process { | |||
2342 | $stat_real = "[...]\n$stat_real"; | 2631 | $stat_real = "[...]\n$stat_real"; |
2343 | } | 2632 | } |
2344 | 2633 | ||
2345 | 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); | ||
2346 | } | 2636 | } |
2347 | } | 2637 | } |
2348 | 2638 | ||
@@ -2358,7 +2648,8 @@ sub process { | |||
2358 | (?:\&\&|\|\||\)|\]) | 2648 | (?:\&\&|\|\||\)|\]) |
2359 | )/x) | 2649 | )/x) |
2360 | { | 2650 | { |
2361 | 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); | ||
2362 | } | 2653 | } |
2363 | 2654 | ||
2364 | # if and else should not have general statements after it | 2655 | # if and else should not have general statements after it |
@@ -2366,12 +2657,14 @@ sub process { | |||
2366 | my $s = $1; | 2657 | my $s = $1; |
2367 | $s =~ s/$;//g; # Remove any comments | 2658 | $s =~ s/$;//g; # Remove any comments |
2368 | if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) { | 2659 | if ($s !~ /^\s*(?:\sif|(?:{|)\s*\\?\s*$)/) { |
2369 | ERROR("trailing statements should be on next line\n" . $herecurr); | 2660 | ERROR("TRAILING_STATEMENTS", |
2661 | "trailing statements should be on next line\n" . $herecurr); | ||
2370 | } | 2662 | } |
2371 | } | 2663 | } |
2372 | # if should not continue a brace | 2664 | # if should not continue a brace |
2373 | if ($line =~ /}\s*if\b/) { | 2665 | if ($line =~ /}\s*if\b/) { |
2374 | ERROR("trailing statements should be on next line\n" . | 2666 | ERROR("TRAILING_STATEMENTS", |
2667 | "trailing statements should be on next line\n" . | ||
2375 | $herecurr); | 2668 | $herecurr); |
2376 | } | 2669 | } |
2377 | # case and default should not have general statements after them | 2670 | # case and default should not have general statements after them |
@@ -2381,14 +2674,16 @@ sub process { | |||
2381 | \s*return\s+ | 2674 | \s*return\s+ |
2382 | )/xg) | 2675 | )/xg) |
2383 | { | 2676 | { |
2384 | ERROR("trailing statements should be on next line\n" . $herecurr); | 2677 | ERROR("TRAILING_STATEMENTS", |
2678 | "trailing statements should be on next line\n" . $herecurr); | ||
2385 | } | 2679 | } |
2386 | 2680 | ||
2387 | # Check for }<nl>else {, these must be at the same | 2681 | # Check for }<nl>else {, these must be at the same |
2388 | # indent level to be relevant to each other. | 2682 | # indent level to be relevant to each other. |
2389 | if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and | 2683 | if ($prevline=~/}\s*$/ and $line=~/^.\s*else\s*/ and |
2390 | $previndent == $indent) { | 2684 | $previndent == $indent) { |
2391 | ERROR("else should follow close brace '}'\n" . $hereprev); | 2685 | ERROR("ELSE_AFTER_BRACE", |
2686 | "else should follow close brace '}'\n" . $hereprev); | ||
2392 | } | 2687 | } |
2393 | 2688 | ||
2394 | if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and | 2689 | if ($prevline=~/}\s*$/ and $line=~/^.\s*while\s*/ and |
@@ -2401,7 +2696,8 @@ sub process { | |||
2401 | $s =~ s/\n.*//g; | 2696 | $s =~ s/\n.*//g; |
2402 | 2697 | ||
2403 | if ($s =~ /^\s*;/) { | 2698 | if ($s =~ /^\s*;/) { |
2404 | ERROR("while should follow close brace '}'\n" . $hereprev); | 2699 | ERROR("WHILE_AFTER_BRACE", |
2700 | "while should follow close brace '}'\n" . $hereprev); | ||
2405 | } | 2701 | } |
2406 | } | 2702 | } |
2407 | 2703 | ||
@@ -2414,7 +2710,8 @@ sub process { | |||
2414 | 2710 | ||
2415 | #no spaces allowed after \ in define | 2711 | #no spaces allowed after \ in define |
2416 | if ($line=~/\#\s*define.*\\\s$/) { | 2712 | if ($line=~/\#\s*define.*\\\s$/) { |
2417 | WARN("Whitepspace after \\ makes next lines useless\n" . $herecurr); | 2713 | WARN("WHITESPACE_AFTER_LINE_CONTINUATION", |
2714 | "Whitepspace after \\ makes next lines useless\n" . $herecurr); | ||
2418 | } | 2715 | } |
2419 | 2716 | ||
2420 | #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) |
@@ -2426,9 +2723,11 @@ sub process { | |||
2426 | $1 !~ /$allowed_asm_includes/) | 2723 | $1 !~ /$allowed_asm_includes/) |
2427 | { | 2724 | { |
2428 | if ($realfile =~ m{^arch/}) { | 2725 | if ($realfile =~ m{^arch/}) { |
2429 | 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); | ||
2430 | } else { | 2728 | } else { |
2431 | 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); | ||
2432 | } | 2731 | } |
2433 | } | 2732 | } |
2434 | } | 2733 | } |
@@ -2512,7 +2811,8 @@ sub process { | |||
2512 | if ($rest !~ /while\s*\(/ && | 2811 | if ($rest !~ /while\s*\(/ && |
2513 | $dstat !~ /$exceptions/) | 2812 | $dstat !~ /$exceptions/) |
2514 | { | 2813 | { |
2515 | 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"); | ||
2516 | } | 2816 | } |
2517 | 2817 | ||
2518 | } elsif ($ctx !~ /;/) { | 2818 | } elsif ($ctx !~ /;/) { |
@@ -2522,7 +2822,8 @@ sub process { | |||
2522 | $dstat !~ /^\.$Ident\s*=/ && | 2822 | $dstat !~ /^\.$Ident\s*=/ && |
2523 | $dstat =~ /$Operators/) | 2823 | $dstat =~ /$Operators/) |
2524 | { | 2824 | { |
2525 | 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"); | ||
2526 | } | 2827 | } |
2527 | } | 2828 | } |
2528 | } | 2829 | } |
@@ -2533,7 +2834,8 @@ sub process { | |||
2533 | # ALIGN(...) | 2834 | # ALIGN(...) |
2534 | # VMLINUX_SYMBOL(...) | 2835 | # VMLINUX_SYMBOL(...) |
2535 | 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|$))/) { |
2536 | 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); | ||
2537 | } | 2839 | } |
2538 | 2840 | ||
2539 | # check for redundant bracing round if etc | 2841 | # check for redundant bracing round if etc |
@@ -2581,7 +2883,8 @@ sub process { | |||
2581 | } | 2883 | } |
2582 | } | 2884 | } |
2583 | if ($seen && !$allowed) { | 2885 | if ($seen && !$allowed) { |
2584 | 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); | ||
2585 | } | 2888 | } |
2586 | } | 2889 | } |
2587 | } | 2890 | } |
@@ -2635,33 +2938,38 @@ sub process { | |||
2635 | $herectx .= raw_line($linenr, $n) . "\n";; | 2938 | $herectx .= raw_line($linenr, $n) . "\n";; |
2636 | } | 2939 | } |
2637 | 2940 | ||
2638 | 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); | ||
2639 | } | 2943 | } |
2640 | } | 2944 | } |
2641 | 2945 | ||
2642 | # don't include deprecated include files (uses RAW line) | 2946 | # don't include deprecated include files (uses RAW line) |
2643 | for my $inc (@dep_includes) { | 2947 | for my $inc (@dep_includes) { |
2644 | if ($rawline =~ m@^.\s*\#\s*include\s*\<$inc>@) { | 2948 | if ($rawline =~ m@^.\s*\#\s*include\s*\<$inc>@) { |
2645 | 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); | ||
2646 | } | 2951 | } |
2647 | } | 2952 | } |
2648 | 2953 | ||
2649 | # don't use deprecated functions | 2954 | # don't use deprecated functions |
2650 | for my $func (@dep_functions) { | 2955 | for my $func (@dep_functions) { |
2651 | if ($line =~ /\b$func\b/) { | 2956 | if ($line =~ /\b$func\b/) { |
2652 | 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); | ||
2653 | } | 2959 | } |
2654 | } | 2960 | } |
2655 | 2961 | ||
2656 | # no volatiles please | 2962 | # no volatiles please |
2657 | my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; | 2963 | my $asm_volatile = qr{\b(__asm__|asm)\s+(__volatile__|volatile)\b}; |
2658 | if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { | 2964 | if ($line =~ /\bvolatile\b/ && $line !~ /$asm_volatile/) { |
2659 | 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); | ||
2660 | } | 2967 | } |
2661 | 2968 | ||
2662 | # warn about #if 0 | 2969 | # warn about #if 0 |
2663 | if ($line =~ /^.\s*\#\s*if\s+0\b/) { | 2970 | if ($line =~ /^.\s*\#\s*if\s+0\b/) { |
2664 | CHK("if this code is redundant consider removing it\n" . | 2971 | CHK("REDUNDANT_CODE", |
2972 | "if this code is redundant consider removing it\n" . | ||
2665 | $herecurr); | 2973 | $herecurr); |
2666 | } | 2974 | } |
2667 | 2975 | ||
@@ -2669,14 +2977,16 @@ sub process { | |||
2669 | if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { | 2977 | if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { |
2670 | my $expr = $1; | 2978 | my $expr = $1; |
2671 | if ($line =~ /\bkfree\(\Q$expr\E\);/) { | 2979 | if ($line =~ /\bkfree\(\Q$expr\E\);/) { |
2672 | 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); | ||
2673 | } | 2982 | } |
2674 | } | 2983 | } |
2675 | # check for needless usb_free_urb() checks | 2984 | # check for needless usb_free_urb() checks |
2676 | if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { | 2985 | if ($prevline =~ /\bif\s*\(([^\)]*)\)/) { |
2677 | my $expr = $1; | 2986 | my $expr = $1; |
2678 | if ($line =~ /\busb_free_urb\(\Q$expr\E\);/) { | 2987 | if ($line =~ /\busb_free_urb\(\Q$expr\E\);/) { |
2679 | 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); | ||
2680 | } | 2990 | } |
2681 | } | 2991 | } |
2682 | 2992 | ||
@@ -2684,14 +2994,16 @@ sub process { | |||
2684 | if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) { | 2994 | if ($line =~ /\budelay\s*\(\s*(\w+)\s*\)/) { |
2685 | # ignore udelay's < 10, however | 2995 | # ignore udelay's < 10, however |
2686 | if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) { | 2996 | if (! (($1 =~ /(\d+)/) && ($1 < 10)) ) { |
2687 | 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); | ||
2688 | } | 2999 | } |
2689 | } | 3000 | } |
2690 | 3001 | ||
2691 | # warn about unexpectedly long msleep's | 3002 | # warn about unexpectedly long msleep's |
2692 | if ($line =~ /\bmsleep\s*\((\d+)\);/) { | 3003 | if ($line =~ /\bmsleep\s*\((\d+)\);/) { |
2693 | if ($1 < 20) { | 3004 | if ($1 < 20) { |
2694 | 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); | ||
2695 | } | 3007 | } |
2696 | } | 3008 | } |
2697 | 3009 | ||
@@ -2704,7 +3016,8 @@ sub process { | |||
2704 | 3016 | ||
2705 | # warn about spacing in #ifdefs | 3017 | # warn about spacing in #ifdefs |
2706 | if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) { | 3018 | if ($line =~ /^.\s*\#\s*(ifdef|ifndef|elif)\s\s+/) { |
2707 | ERROR("exactly one space required after that #$1\n" . $herecurr); | 3019 | ERROR("SPACING", |
3020 | "exactly one space required after that #$1\n" . $herecurr); | ||
2708 | } | 3021 | } |
2709 | 3022 | ||
2710 | # check for spinlock_t definitions without a comment. | 3023 | # check for spinlock_t definitions without a comment. |
@@ -2712,50 +3025,65 @@ sub process { | |||
2712 | $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) { | 3025 | $line =~ /^.\s*(DEFINE_MUTEX)\s*\(/) { |
2713 | my $which = $1; | 3026 | my $which = $1; |
2714 | if (!ctx_has_comment($first_line, $linenr)) { | 3027 | if (!ctx_has_comment($first_line, $linenr)) { |
2715 | CHK("$1 definition without comment\n" . $herecurr); | 3028 | CHK("UNCOMMENTED_DEFINITION", |
3029 | "$1 definition without comment\n" . $herecurr); | ||
2716 | } | 3030 | } |
2717 | } | 3031 | } |
2718 | # check for memory barriers without a comment. | 3032 | # check for memory barriers without a comment. |
2719 | 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)\(/) { |
2720 | if (!ctx_has_comment($first_line, $linenr)) { | 3034 | if (!ctx_has_comment($first_line, $linenr)) { |
2721 | CHK("memory barrier without comment\n" . $herecurr); | 3035 | CHK("MEMORY_BARRIER", |
3036 | "memory barrier without comment\n" . $herecurr); | ||
2722 | } | 3037 | } |
2723 | } | 3038 | } |
2724 | # check of hardware specific defines | 3039 | # check of hardware specific defines |
2725 | 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-@) { |
2726 | CHK("architecture specific defines should be avoided\n" . $herecurr); | 3041 | CHK("ARCH_DEFINES", |
3042 | "architecture specific defines should be avoided\n" . $herecurr); | ||
2727 | } | 3043 | } |
2728 | 3044 | ||
2729 | # 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 |
2730 | if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) { | 3046 | if ($line =~ /\b$Storage\b/ && $line !~ /^.\s*$Storage\b/) { |
2731 | 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) | ||
2732 | } | 3049 | } |
2733 | 3050 | ||
2734 | # check the location of the inline attribute, that it is between | 3051 | # check the location of the inline attribute, that it is between |
2735 | # storage class and type. | 3052 | # storage class and type. |
2736 | if ($line =~ /\b$Type\s+$Inline\b/ || | 3053 | if ($line =~ /\b$Type\s+$Inline\b/ || |
2737 | $line =~ /\b$Inline\s+$Storage\b/) { | 3054 | $line =~ /\b$Inline\s+$Storage\b/) { |
2738 | 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); | ||
2739 | } | 3057 | } |
2740 | 3058 | ||
2741 | # Check for __inline__ and __inline, prefer inline | 3059 | # Check for __inline__ and __inline, prefer inline |
2742 | if ($line =~ /\b(__inline__|__inline)\b/) { | 3060 | if ($line =~ /\b(__inline__|__inline)\b/) { |
2743 | WARN("plain inline is preferred over $1\n" . $herecurr); | 3061 | WARN("INLINE", |
3062 | "plain inline is preferred over $1\n" . $herecurr); | ||
2744 | } | 3063 | } |
2745 | 3064 | ||
2746 | # Check for __attribute__ packed, prefer __packed | 3065 | # Check for __attribute__ packed, prefer __packed |
2747 | if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) { | 3066 | if ($line =~ /\b__attribute__\s*\(\s*\(.*\bpacked\b/) { |
2748 | WARN("__packed is preferred over __attribute__((packed))\n" . $herecurr); | 3067 | WARN("PREFER_PACKED", |
3068 | "__packed is preferred over __attribute__((packed))\n" . $herecurr); | ||
3069 | } | ||
3070 | |||
3071 | # Check for __attribute__ aligned, prefer __aligned | ||
3072 | if ($line =~ /\b__attribute__\s*\(\s*\(.*aligned/) { | ||
3073 | WARN("PREFER_ALIGNED", | ||
3074 | "__aligned(size) is preferred over __attribute__((aligned(size)))\n" . $herecurr); | ||
2749 | } | 3075 | } |
2750 | 3076 | ||
2751 | # check for sizeof(&) | 3077 | # check for sizeof(&) |
2752 | if ($line =~ /\bsizeof\s*\(\s*\&/) { | 3078 | if ($line =~ /\bsizeof\s*\(\s*\&/) { |
2753 | WARN("sizeof(& should be avoided\n" . $herecurr); | 3079 | WARN("SIZEOF_ADDRESS", |
3080 | "sizeof(& should be avoided\n" . $herecurr); | ||
2754 | } | 3081 | } |
2755 | 3082 | ||
2756 | # check for line continuations in quoted strings with odd counts of " | 3083 | # check for line continuations in quoted strings with odd counts of " |
2757 | if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) { | 3084 | if ($rawline =~ /\\$/ && $rawline =~ tr/"/"/ % 2) { |
2758 | WARN("Avoid line continuations in quoted strings\n" . $herecurr); | 3085 | WARN("LINE_CONTINUATIONS", |
3086 | "Avoid line continuations in quoted strings\n" . $herecurr); | ||
2759 | } | 3087 | } |
2760 | 3088 | ||
2761 | # check for new externs in .c files. | 3089 | # check for new externs in .c files. |
@@ -2772,17 +3100,20 @@ sub process { | |||
2772 | if ($s =~ /^\s*;/ && | 3100 | if ($s =~ /^\s*;/ && |
2773 | $function_name ne 'uninitialized_var') | 3101 | $function_name ne 'uninitialized_var') |
2774 | { | 3102 | { |
2775 | WARN("externs should be avoided in .c files\n" . $herecurr); | 3103 | WARN("AVOID_EXTERNS", |
3104 | "externs should be avoided in .c files\n" . $herecurr); | ||
2776 | } | 3105 | } |
2777 | 3106 | ||
2778 | if ($paren_space =~ /\n/) { | 3107 | if ($paren_space =~ /\n/) { |
2779 | WARN("arguments for function declarations should follow identifier\n" . $herecurr); | 3108 | WARN("FUNCTION_ARGUMENTS", |
3109 | "arguments for function declarations should follow identifier\n" . $herecurr); | ||
2780 | } | 3110 | } |
2781 | 3111 | ||
2782 | } elsif ($realfile =~ /\.c$/ && defined $stat && | 3112 | } elsif ($realfile =~ /\.c$/ && defined $stat && |
2783 | $stat =~ /^.\s*extern\s+/) | 3113 | $stat =~ /^.\s*extern\s+/) |
2784 | { | 3114 | { |
2785 | WARN("externs should be avoided in .c files\n" . $herecurr); | 3115 | WARN("AVOID_EXTERNS", |
3116 | "externs should be avoided in .c files\n" . $herecurr); | ||
2786 | } | 3117 | } |
2787 | 3118 | ||
2788 | # checks for new __setup's | 3119 | # checks for new __setup's |
@@ -2790,37 +3121,44 @@ sub process { | |||
2790 | my $name = $1; | 3121 | my $name = $1; |
2791 | 3122 | ||
2792 | if (!grep(/$name/, @setup_docs)) { | 3123 | if (!grep(/$name/, @setup_docs)) { |
2793 | 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); | ||
2794 | } | 3126 | } |
2795 | } | 3127 | } |
2796 | 3128 | ||
2797 | # check for pointless casting of kmalloc return | 3129 | # check for pointless casting of kmalloc return |
2798 | if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) { | 3130 | if ($line =~ /\*\s*\)\s*[kv][czm]alloc(_node){0,1}\b/) { |
2799 | 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); | ||
2800 | } | 3133 | } |
2801 | 3134 | ||
2802 | # check for multiple semicolons | 3135 | # check for multiple semicolons |
2803 | if ($line =~ /;\s*;\s*$/) { | 3136 | if ($line =~ /;\s*;\s*$/) { |
2804 | WARN("Statements terminations use 1 semicolon\n" . $herecurr); | 3137 | WARN("ONE_SEMICOLON", |
3138 | "Statements terminations use 1 semicolon\n" . $herecurr); | ||
2805 | } | 3139 | } |
2806 | 3140 | ||
2807 | # check for gcc specific __FUNCTION__ | 3141 | # check for gcc specific __FUNCTION__ |
2808 | if ($line =~ /__FUNCTION__/) { | 3142 | if ($line =~ /__FUNCTION__/) { |
2809 | 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); | ||
2810 | } | 3145 | } |
2811 | 3146 | ||
2812 | # check for semaphores initialized locked | 3147 | # check for semaphores initialized locked |
2813 | if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) { | 3148 | if ($line =~ /^.\s*sema_init.+,\W?0\W?\)/) { |
2814 | WARN("consider using a completion\n" . $herecurr); | 3149 | WARN("CONSIDER_COMPLETION", |
3150 | "consider using a completion\n" . $herecurr); | ||
2815 | 3151 | ||
2816 | } | 3152 | } |
2817 | # recommend kstrto* over simple_strto* | 3153 | # recommend kstrto* over simple_strto* |
2818 | if ($line =~ /\bsimple_(strto.*?)\s*\(/) { | 3154 | if ($line =~ /\bsimple_(strto.*?)\s*\(/) { |
2819 | 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); | ||
2820 | } | 3157 | } |
2821 | # check for __initcall(), use device_initcall() explicitly please | 3158 | # check for __initcall(), use device_initcall() explicitly please |
2822 | if ($line =~ /^.\s*__initcall\s*\(/) { | 3159 | if ($line =~ /^.\s*__initcall\s*\(/) { |
2823 | 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); | ||
2824 | } | 3162 | } |
2825 | # check for various ops structs, ensure they are const. | 3163 | # check for various ops structs, ensure they are const. |
2826 | my $struct_ops = qr{acpi_dock_ops| | 3164 | my $struct_ops = qr{acpi_dock_ops| |
@@ -2862,7 +3200,8 @@ sub process { | |||
2862 | wd_ops}x; | 3200 | wd_ops}x; |
2863 | if ($line !~ /\bconst\b/ && | 3201 | if ($line !~ /\bconst\b/ && |
2864 | $line =~ /\bstruct\s+($struct_ops)\b/) { | 3202 | $line =~ /\bstruct\s+($struct_ops)\b/) { |
2865 | WARN("struct $1 should normally be const\n" . | 3203 | WARN("CONST_STRUCT", |
3204 | "struct $1 should normally be const\n" . | ||
2866 | $herecurr); | 3205 | $herecurr); |
2867 | } | 3206 | } |
2868 | 3207 | ||
@@ -2875,7 +3214,8 @@ sub process { | |||
2875 | $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ && | 3214 | $line !~ /\[[^\]]*\.\.\.[^\]]*NR_CPUS[^\]]*\]/ && |
2876 | $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/) | 3215 | $line !~ /\[[^\]]*NR_CPUS[^\]]*\.\.\.[^\]]*\]/) |
2877 | { | 3216 | { |
2878 | 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); | ||
2879 | } | 3219 | } |
2880 | 3220 | ||
2881 | # check for %L{u,d,i} in strings | 3221 | # check for %L{u,d,i} in strings |
@@ -2884,7 +3224,8 @@ sub process { | |||
2884 | $string = substr($rawline, $-[1], $+[1] - $-[1]); | 3224 | $string = substr($rawline, $-[1], $+[1] - $-[1]); |
2885 | $string =~ s/%%/__/g; | 3225 | $string =~ s/%%/__/g; |
2886 | if ($string =~ /(?<!%)%L[udi]/) { | 3226 | if ($string =~ /(?<!%)%L[udi]/) { |
2887 | 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); | ||
2888 | last; | 3229 | last; |
2889 | } | 3230 | } |
2890 | } | 3231 | } |
@@ -2892,9 +3233,11 @@ sub process { | |||
2892 | # whine mightly about in_atomic | 3233 | # whine mightly about in_atomic |
2893 | if ($line =~ /\bin_atomic\s*\(/) { | 3234 | if ($line =~ /\bin_atomic\s*\(/) { |
2894 | if ($realfile =~ m@^drivers/@) { | 3235 | if ($realfile =~ m@^drivers/@) { |
2895 | ERROR("do not use in_atomic in drivers\n" . $herecurr); | 3236 | ERROR("IN_ATOMIC", |
3237 | "do not use in_atomic in drivers\n" . $herecurr); | ||
2896 | } elsif ($realfile !~ m@^kernel/@) { | 3238 | } elsif ($realfile !~ m@^kernel/@) { |
2897 | 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); | ||
2898 | } | 3241 | } |
2899 | } | 3242 | } |
2900 | 3243 | ||
@@ -2904,18 +3247,21 @@ sub process { | |||
2904 | if ($realfile !~ m@^kernel/lockdep@ && | 3247 | if ($realfile !~ m@^kernel/lockdep@ && |
2905 | $realfile !~ m@^include/linux/lockdep@ && | 3248 | $realfile !~ m@^include/linux/lockdep@ && |
2906 | $realfile !~ m@^drivers/base/core@) { | 3249 | $realfile !~ m@^drivers/base/core@) { |
2907 | 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); | ||
2908 | } | 3252 | } |
2909 | } | 3253 | } |
2910 | 3254 | ||
2911 | if ($line =~ /debugfs_create_file.*S_IWUGO/ || | 3255 | if ($line =~ /debugfs_create_file.*S_IWUGO/ || |
2912 | $line =~ /DEVICE_ATTR.*S_IWUGO/ ) { | 3256 | $line =~ /DEVICE_ATTR.*S_IWUGO/ ) { |
2913 | 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); | ||
2914 | } | 3259 | } |
2915 | 3260 | ||
2916 | # Check for memset with swapped arguments | 3261 | # Check for memset with swapped arguments |
2917 | if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) { | 3262 | if ($line =~ /memset.*\,(\ |)(0x|)0(\ |0|)\);/) { |
2918 | 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); | ||
2919 | } | 3265 | } |
2920 | } | 3266 | } |
2921 | 3267 | ||
@@ -2938,10 +3284,12 @@ sub process { | |||
2938 | } | 3284 | } |
2939 | 3285 | ||
2940 | if (!$is_patch) { | 3286 | if (!$is_patch) { |
2941 | 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"); | ||
2942 | } | 3289 | } |
2943 | if ($is_patch && $chk_signoff && $signoff == 0) { | 3290 | if ($is_patch && $chk_signoff && $signoff == 0) { |
2944 | ERROR("Missing Signed-off-by: line(s)\n"); | 3291 | ERROR("MISSING_SIGN_OFF", |
3292 | "Missing Signed-off-by: line(s)\n"); | ||
2945 | } | 3293 | } |
2946 | 3294 | ||
2947 | print report_dump(); | 3295 | print report_dump(); |
@@ -2963,13 +3311,25 @@ sub process { | |||
2963 | } | 3311 | } |
2964 | } | 3312 | } |
2965 | 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 | |||
2966 | if ($clean == 1 && $quiet == 0) { | 3323 | if ($clean == 1 && $quiet == 0) { |
2967 | 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" |
2968 | } | 3325 | } |
2969 | if ($clean == 0 && $quiet == 0) { | 3326 | if ($clean == 0 && $quiet == 0) { |
2970 | print "$vname has style problems, please review. If any of these errors\n"; | 3327 | print << "EOM"; |
2971 | print "are false positives report them to the maintainer, see\n"; | 3328 | $vname has style problems, please review. |
2972 | print "CHECKPATCH in MAINTAINERS.\n"; | 3329 | |
3330 | If any of these errors are false positives, please report | ||
3331 | them to the maintainer, see CHECKPATCH in MAINTAINERS. | ||
3332 | EOM | ||
2973 | } | 3333 | } |
2974 | 3334 | ||
2975 | return $clean; | 3335 | return $clean; |