diff options
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-x | scripts/checkpatch.pl | 73 |
1 files changed, 43 insertions, 30 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 9ada45c..8fda3b3 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -16,7 +16,6 @@ use Getopt::Long qw(:config no_auto_abbrev); my $quiet = 0; my $tree = 1; -my $chk_subject = 1; my $chk_signoff = 1; my $chk_patch = 1; my $tst_only; @@ -99,7 +98,6 @@ if (-f $conf) { GetOptions( 'q|quiet+' => \$quiet, 'tree!' => \$tree, - 'subject!' => \$chk_subject, 'signoff!' => \$chk_signoff, 'patch!' => \$chk_patch, 'emacs!' => \$emacs, @@ -242,9 +240,8 @@ our $NonptrType; our $Type; our $Declare; -our $UTF8 = qr { - [\x09\x0A\x0D\x20-\x7E] # ASCII - | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte +our $NON_ASCII_UTF8 = qr{ + [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates @@ -253,6 +250,11 @@ our $UTF8 = qr { | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 }x; +our $UTF8 = qr{ + [\x09\x0A\x0D\x20-\x7E] # ASCII + | $NON_ASCII_UTF8 +}x; + our $typeTypedefs = qr{(?x: (?:__)?(?:u|s|be|le)(?:8|16|32|64)| atomic_t @@ -342,7 +344,6 @@ sub deparenthesize { return $string; } -$chk_subject = 0 if ($file); $chk_signoff = 0 if ($file); my @dep_includes = (); @@ -1333,6 +1334,9 @@ sub process { my $signoff = 0; my $is_patch = 0; + my $in_header_lines = 1; + my $in_commit_log = 0; #Scanning lines before patch + our @report = (); our $cnt_lines = 0; our $cnt_error = 0; @@ -1500,7 +1504,6 @@ sub process { if ($line =~ /^diff --git.*?(\S+)$/) { $realfile = $1; $realfile =~ s@^([^/]*)/@@; - } elsif ($line =~ /^\+\+\+\s+(\S+)/) { $realfile = $1; $realfile =~ s@^([^/]*)/@@; @@ -1536,29 +1539,10 @@ sub process { } } -# Check for subject: - if ($chk_subject && $line =~ /^Subject: \[PATCH\] (\s*)(\[.*\])?/i) { - my $space_before = $1; - my $brace_usage = $2; - if (defined $space_before && $space_before ne "") { - WARN("BAD_SUBJECT", - "Remove leading whitespace on subject\n" . $herecurr); - } - if (defined $brace_usage && $brace_usage ne "") { - WARN("BAD_SUBJECT", - "Avoid using '[xxx]' on subject. Use 'xxx:' instead\n" . $herecurr); - } - if ($lines[$linenr] !~ /^$/) { - ERROR("MISSING_BLANK_LINE_AFTER_SUBJECT", - "Missing blank line after Subject: line\n" . $herecurr); - } - } - - #($line =~ /^Subject:/i) && ? 1 : 0; - # Check the patch for a signoff: if ($line =~ /^\s*signed-off-by:/i) { $signoff++; + $in_commit_log = 0; } # Check signature styles @@ -1636,6 +1620,21 @@ sub process { "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr); } +# Check if it's the start of a commit log +# (not a header line and we haven't seen the patch filename) + if ($in_header_lines && $realfile =~ /^$/ && + $rawline !~ /^(commit\b|from\b|\w+:).+$/i) { + $in_header_lines = 0; + $in_commit_log = 1; + } + +# Still not yet in a patch, check for any UTF-8 + if ($in_commit_log && $realfile =~ /^$/ && + $rawline =~ /$NON_ASCII_UTF8/) { + CHK("UTF8_BEFORE_PATCH", + "8-bit UTF-8 used in possible commit log\n" . $herecurr); + } + # ignore non-hunk lines and lines being removed next if (!$hunk_line || $line =~ /^-/); @@ -1684,6 +1683,20 @@ sub process { #print "is_end<$is_end> length<$length>\n"; } + if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) && + ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) { + my $flag = $1; + my $replacement = { + 'EXTRA_AFLAGS' => 'asflags-y', + 'EXTRA_CFLAGS' => 'ccflags-y', + 'EXTRA_CPPFLAGS' => 'cppflags-y', + 'EXTRA_LDFLAGS' => 'ldflags-y', + }; + + WARN("DEPRECATED_VARIABLE", + "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag}); + } + # check we are in a valid source file if not then ignore this hunk next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); @@ -3174,10 +3187,10 @@ sub process { "consider using a completion\n" . $herecurr); } -# recommend kstrto* over simple_strto* - if ($line =~ /\bsimple_(strto.*?)\s*\(/) { +# recommend kstrto* over simple_strto* and strict_strto* + if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) { WARN("CONSIDER_KSTRTO", - "consider using kstrto* in preference to simple_$1\n" . $herecurr); + "$1 is obsolete, use k$3 instead\n" . $herecurr); } # check for __initcall(), use device_initcall() explicitly please if ($line =~ /^.\s*__initcall\s*\(/) { |