diff options
Diffstat (limited to 'scripts/checkpatch.pl')
| -rwxr-xr-x | scripts/checkpatch.pl | 29 |
1 files changed, 21 insertions, 8 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 24a08363995a..4de3cc42fc50 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -55,6 +55,7 @@ my $spelling_file = "$D/spelling.txt"; | |||
| 55 | my $codespell = 0; | 55 | my $codespell = 0; |
| 56 | my $codespellfile = "/usr/share/codespell/dictionary.txt"; | 56 | my $codespellfile = "/usr/share/codespell/dictionary.txt"; |
| 57 | my $color = 1; | 57 | my $color = 1; |
| 58 | my $allow_c99_comments = 1; | ||
| 58 | 59 | ||
| 59 | sub help { | 60 | sub help { |
| 60 | my ($exitcode) = @_; | 61 | my ($exitcode) = @_; |
| @@ -227,9 +228,9 @@ if ($^V && $^V lt $minimum_perl_version) { | |||
| 227 | } | 228 | } |
| 228 | } | 229 | } |
| 229 | 230 | ||
| 231 | #if no filenames are given, push '-' to read patch from stdin | ||
| 230 | if ($#ARGV < 0) { | 232 | if ($#ARGV < 0) { |
| 231 | print "$P: no input files\n"; | 233 | push(@ARGV, '-'); |
| 232 | exit(1); | ||
| 233 | } | 234 | } |
| 234 | 235 | ||
| 235 | sub hash_save_array_words { | 236 | sub hash_save_array_words { |
| @@ -1144,6 +1145,11 @@ sub sanitise_line { | |||
| 1144 | $res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@; | 1145 | $res =~ s@(\#\s*(?:error|warning)\s+).*@$1$clean@; |
| 1145 | } | 1146 | } |
| 1146 | 1147 | ||
| 1148 | if ($allow_c99_comments && $res =~ m@(//.*$)@) { | ||
| 1149 | my $match = $1; | ||
| 1150 | $res =~ s/\Q$match\E/"$;" x length($match)/e; | ||
| 1151 | } | ||
| 1152 | |||
| 1147 | return $res; | 1153 | return $res; |
| 1148 | } | 1154 | } |
| 1149 | 1155 | ||
| @@ -2063,6 +2069,7 @@ sub process { | |||
| 2063 | my $is_patch = 0; | 2069 | my $is_patch = 0; |
| 2064 | my $in_header_lines = $file ? 0 : 1; | 2070 | my $in_header_lines = $file ? 0 : 1; |
| 2065 | my $in_commit_log = 0; #Scanning lines before patch | 2071 | my $in_commit_log = 0; #Scanning lines before patch |
| 2072 | my $has_commit_log = 0; #Encountered lines before patch | ||
| 2066 | my $commit_log_possible_stack_dump = 0; | 2073 | my $commit_log_possible_stack_dump = 0; |
| 2067 | my $commit_log_long_line = 0; | 2074 | my $commit_log_long_line = 0; |
| 2068 | my $commit_log_has_diff = 0; | 2075 | my $commit_log_has_diff = 0; |
| @@ -2453,9 +2460,9 @@ sub process { | |||
| 2453 | 2460 | ||
| 2454 | # Check for git id commit length and improperly formed commit descriptions | 2461 | # Check for git id commit length and improperly formed commit descriptions |
| 2455 | if ($in_commit_log && !$commit_log_possible_stack_dump && | 2462 | if ($in_commit_log && !$commit_log_possible_stack_dump && |
| 2456 | $line !~ /^\s*(?:Link|Patchwork|http|BugLink):/i && | 2463 | $line !~ /^\s*(?:Link|Patchwork|http|https|BugLink):/i && |
| 2457 | ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i || | 2464 | ($line =~ /\bcommit\s+[0-9a-f]{5,}\b/i || |
| 2458 | ($line =~ /\b[0-9a-f]{12,40}\b/i && | 2465 | ($line =~ /(?:\s|^)[0-9a-f]{12,40}(?:[\s"'\(\[]|$)/i && |
| 2459 | $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i && | 2466 | $line !~ /[\<\[][0-9a-f]{12,40}[\>\]]/i && |
| 2460 | $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) { | 2467 | $line !~ /\bfixes:\s*[0-9a-f]{12,40}/i))) { |
| 2461 | my $init_char = "c"; | 2468 | my $init_char = "c"; |
| @@ -2560,6 +2567,7 @@ sub process { | |||
| 2560 | $rawline =~ /^(commit\b|from\b|[\w-]+:).*$/i)) { | 2567 | $rawline =~ /^(commit\b|from\b|[\w-]+:).*$/i)) { |
| 2561 | $in_header_lines = 0; | 2568 | $in_header_lines = 0; |
| 2562 | $in_commit_log = 1; | 2569 | $in_commit_log = 1; |
| 2570 | $has_commit_log = 1; | ||
| 2563 | } | 2571 | } |
| 2564 | 2572 | ||
| 2565 | # Check if there is UTF-8 in a commit log when a mail header has explicitly | 2573 | # Check if there is UTF-8 in a commit log when a mail header has explicitly |
| @@ -2763,6 +2771,10 @@ sub process { | |||
| 2763 | $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) { | 2771 | $line =~ /^\+\s*#\s*define\s+\w+\s+$String$/) { |
| 2764 | $msg_type = ""; | 2772 | $msg_type = ""; |
| 2765 | 2773 | ||
| 2774 | # EFI_GUID is another special case | ||
| 2775 | } elsif ($line =~ /^\+.*\bEFI_GUID\s*\(/) { | ||
| 2776 | $msg_type = ""; | ||
| 2777 | |||
| 2766 | # Otherwise set the alternate message types | 2778 | # Otherwise set the alternate message types |
| 2767 | 2779 | ||
| 2768 | # a comment starts before $max_line_length | 2780 | # a comment starts before $max_line_length |
| @@ -3337,7 +3349,7 @@ sub process { | |||
| 3337 | next if ($line =~ /^[^\+]/); | 3349 | next if ($line =~ /^[^\+]/); |
| 3338 | 3350 | ||
| 3339 | # check for declarations of signed or unsigned without int | 3351 | # check for declarations of signed or unsigned without int |
| 3340 | while ($line =~ m{($Declare)\s*(?!char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) { | 3352 | while ($line =~ m{\b($Declare)\s*(?!char\b|short\b|int\b|long\b)\s*($Ident)?\s*[=,;\[\)\(]}g) { |
| 3341 | my $type = $1; | 3353 | my $type = $1; |
| 3342 | my $var = $2; | 3354 | my $var = $2; |
| 3343 | $var = "" if (!defined $var); | 3355 | $var = "" if (!defined $var); |
| @@ -5722,8 +5734,9 @@ sub process { | |||
| 5722 | } | 5734 | } |
| 5723 | } | 5735 | } |
| 5724 | 5736 | ||
| 5725 | # check for #defines like: 1 << <digit> that could be BIT(digit) | 5737 | # check for #defines like: 1 << <digit> that could be BIT(digit), it is not exported to uapi |
| 5726 | if ($line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) { | 5738 | if ($realfile !~ m@^include/uapi/@ && |
| 5739 | $line =~ /#\s*define\s+\w+\s+\(?\s*1\s*([ulUL]*)\s*\<\<\s*(?:\d+|$Ident)\s*\)?/) { | ||
| 5727 | my $ull = ""; | 5740 | my $ull = ""; |
| 5728 | $ull = "_ULL" if (defined($1) && $1 =~ /ll/i); | 5741 | $ull = "_ULL" if (defined($1) && $1 =~ /ll/i); |
| 5729 | if (CHK("BIT_MACRO", | 5742 | if (CHK("BIT_MACRO", |
| @@ -6044,7 +6057,7 @@ sub process { | |||
| 6044 | ERROR("NOT_UNIFIED_DIFF", | 6057 | ERROR("NOT_UNIFIED_DIFF", |
| 6045 | "Does not appear to be a unified-diff format patch\n"); | 6058 | "Does not appear to be a unified-diff format patch\n"); |
| 6046 | } | 6059 | } |
| 6047 | if ($is_patch && $filename ne '-' && $chk_signoff && $signoff == 0) { | 6060 | if ($is_patch && $has_commit_log && $chk_signoff && $signoff == 0) { |
| 6048 | ERROR("MISSING_SIGN_OFF", | 6061 | ERROR("MISSING_SIGN_OFF", |
| 6049 | "Missing Signed-off-by: line(s)\n"); | 6062 | "Missing Signed-off-by: line(s)\n"); |
| 6050 | } | 6063 | } |
