aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl61
1 files changed, 43 insertions, 18 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 2287a0bca863..dd2c262aebbf 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -145,7 +145,8 @@ sub list_types {
145 close($script); 145 close($script);
146 146
147 my @types = (); 147 my @types = ();
148 for ($text =~ /\b(?:(?:CHK|WARN|ERROR)\s*\(\s*"([^"]+)")/g) { 148 # Also catch when type or level is passed through a variable
149 for ($text =~ /(?:(?:\bCHK|\bWARN|\bERROR|&\{\$msg_level})\s*\(|\$msg_type\s*=)\s*"([^"]+)"/g) {
149 push (@types, $_); 150 push (@types, $_);
150 } 151 }
151 @types = sort(uniq(@types)); 152 @types = sort(uniq(@types));
@@ -2715,10 +2716,10 @@ sub process {
2715 my $typo_fix = $spelling_fix{lc($typo)}; 2716 my $typo_fix = $spelling_fix{lc($typo)};
2716 $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/); 2717 $typo_fix = ucfirst($typo_fix) if ($typo =~ /^[A-Z]/);
2717 $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/); 2718 $typo_fix = uc($typo_fix) if ($typo =~ /^[A-Z]+$/);
2718 my $msg_type = \&WARN; 2719 my $msg_level = \&WARN;
2719 $msg_type = \&CHK if ($file); 2720 $msg_level = \&CHK if ($file);
2720 if (&{$msg_type}("TYPO_SPELLING", 2721 if (&{$msg_level}("TYPO_SPELLING",
2721 "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $herecurr) && 2722 "'$typo' may be misspelled - perhaps '$typo_fix'?\n" . $herecurr) &&
2722 $fix) { 2723 $fix) {
2723 $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/; 2724 $fixed[$fixlinenr] =~ s/(^|[^A-Za-z@])($typo)($|[^A-Za-z@])/$1$typo_fix$3/;
2724 } 2725 }
@@ -2753,10 +2754,10 @@ sub process {
2753 $rawline =~ /\b59\s+Temple\s+Pl/i || 2754 $rawline =~ /\b59\s+Temple\s+Pl/i ||
2754 $rawline =~ /\b51\s+Franklin\s+St/i) { 2755 $rawline =~ /\b51\s+Franklin\s+St/i) {
2755 my $herevet = "$here\n" . cat_vet($rawline) . "\n"; 2756 my $herevet = "$here\n" . cat_vet($rawline) . "\n";
2756 my $msg_type = \&ERROR; 2757 my $msg_level = \&ERROR;
2757 $msg_type = \&CHK if ($file); 2758 $msg_level = \&CHK if ($file);
2758 &{$msg_type}("FSF_MAILING_ADDRESS", 2759 &{$msg_level}("FSF_MAILING_ADDRESS",
2759 "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet) 2760 "Do not include the paragraph about writing to the Free Software Foundation's mailing address from the sample GPL notice. The FSF has changed addresses in the past, and may do so again. Linux already includes a copy of the GPL.\n" . $herevet)
2760 } 2761 }
2761 2762
2762# check for Kconfig help text having a real description 2763# check for Kconfig help text having a real description
@@ -2875,7 +2876,7 @@ sub process {
2875# #defines that are a single string 2876# #defines that are a single string
2876# 2877#
2877# There are 3 different line length message types: 2878# There are 3 different line length message types:
2878# LONG_LINE_COMMENT a comment starts before but extends beyond $max_linelength 2879# LONG_LINE_COMMENT a comment starts before but extends beyond $max_line_length
2879# LONG_LINE_STRING a string starts before but extends beyond $max_line_length 2880# LONG_LINE_STRING a string starts before but extends beyond $max_line_length
2880# LONG_LINE all other lines longer than $max_line_length 2881# LONG_LINE all other lines longer than $max_line_length
2881# 2882#
@@ -3810,10 +3811,10 @@ sub process {
3810 3811
3811# avoid BUG() or BUG_ON() 3812# avoid BUG() or BUG_ON()
3812 if ($line =~ /\b(?:BUG|BUG_ON)\b/) { 3813 if ($line =~ /\b(?:BUG|BUG_ON)\b/) {
3813 my $msg_type = \&WARN; 3814 my $msg_level = \&WARN;
3814 $msg_type = \&CHK if ($file); 3815 $msg_level = \&CHK if ($file);
3815 &{$msg_type}("AVOID_BUG", 3816 &{$msg_level}("AVOID_BUG",
3816 "Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()\n" . $herecurr); 3817 "Avoid crashing the kernel - try using WARN_ON & recovery code rather than BUG() or BUG_ON()\n" . $herecurr);
3817 } 3818 }
3818 3819
3819# avoid LINUX_VERSION_CODE 3820# avoid LINUX_VERSION_CODE
@@ -4339,11 +4340,11 @@ sub process {
4339 4340
4340 # messages are ERROR, but ?: are CHK 4341 # messages are ERROR, but ?: are CHK
4341 if ($ok == 0) { 4342 if ($ok == 0) {
4342 my $msg_type = \&ERROR; 4343 my $msg_level = \&ERROR;
4343 $msg_type = \&CHK if (($op eq '?:' || $op eq '?' || $op eq ':') && $ctx =~ /VxV/); 4344 $msg_level = \&CHK if (($op eq '?:' || $op eq '?' || $op eq ':') && $ctx =~ /VxV/);
4344 4345
4345 if (&{$msg_type}("SPACING", 4346 if (&{$msg_level}("SPACING",
4346 "spaces required around that '$op' $at\n" . $hereptr)) { 4347 "spaces required around that '$op' $at\n" . $hereptr)) {
4347 $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " "; 4348 $good = rtrim($fix_elements[$n]) . " " . trim($fix_elements[$n + 1]) . " ";
4348 if (defined $fix_elements[$n + 2]) { 4349 if (defined $fix_elements[$n + 2]) {
4349 $fix_elements[$n + 2] =~ s/^\s+//; 4350 $fix_elements[$n + 2] =~ s/^\s+//;
@@ -4496,6 +4497,30 @@ sub process {
4496 } 4497 }
4497 } 4498 }
4498 4499
4500# check for unnecessary parentheses around comparisons in if uses
4501 if ($^V && $^V ge 5.10.0 && defined($stat) &&
4502 $stat =~ /(^.\s*if\s*($balanced_parens))/) {
4503 my $if_stat = $1;
4504 my $test = substr($2, 1, -1);
4505 my $herectx;
4506 while ($test =~ /(?:^|[^\w\&\!\~])+\s*\(\s*([\&\!\~]?\s*$Lval\s*(?:$Compare\s*$FuncArg)?)\s*\)/g) {
4507 my $match = $1;
4508 # avoid parentheses around potential macro args
4509 next if ($match =~ /^\s*\w+\s*$/);
4510 if (!defined($herectx)) {
4511 $herectx = $here . "\n";
4512 my $cnt = statement_rawlines($if_stat);
4513 for (my $n = 0; $n < $cnt; $n++) {
4514 my $rl = raw_line($linenr, $n);
4515 $herectx .= $rl . "\n";
4516 last if $rl =~ /^[ \+].*\{/;
4517 }
4518 }
4519 CHK("UNNECESSARY_PARENTHESES",
4520 "Unnecessary parentheses around '$match'\n" . $herectx);
4521 }
4522 }
4523
4499#goto labels aren't indented, allow a single space however 4524#goto labels aren't indented, allow a single space however
4500 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and 4525 if ($line=~/^.\s+[A-Za-z\d_]+:(?![0-9]+)/ and
4501 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) { 4526 !($line=~/^. [A-Za-z\d_]+:/) and !($line=~/^.\s+default:/)) {