diff options
Diffstat (limited to 'scripts/checkpatch.pl')
| -rwxr-xr-x | scripts/checkpatch.pl | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 0b3e35c9ef08..8fda3b3f7be8 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
| @@ -240,9 +240,8 @@ our $NonptrType; | |||
| 240 | our $Type; | 240 | our $Type; |
| 241 | our $Declare; | 241 | our $Declare; |
| 242 | 242 | ||
| 243 | our $UTF8 = qr { | 243 | our $NON_ASCII_UTF8 = qr{ |
| 244 | [\x09\x0A\x0D\x20-\x7E] # ASCII | 244 | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte |
| 245 | | [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte | ||
| 246 | | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs | 245 | | \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs |
| 247 | | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte | 246 | | [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte |
| 248 | | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates | 247 | | \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates |
| @@ -251,6 +250,11 @@ our $UTF8 = qr { | |||
| 251 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 | 250 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 252 | }x; | 251 | }x; |
| 253 | 252 | ||
| 253 | our $UTF8 = qr{ | ||
| 254 | [\x09\x0A\x0D\x20-\x7E] # ASCII | ||
| 255 | | $NON_ASCII_UTF8 | ||
| 256 | }x; | ||
| 257 | |||
| 254 | our $typeTypedefs = qr{(?x: | 258 | our $typeTypedefs = qr{(?x: |
| 255 | (?:__)?(?:u|s|be|le)(?:8|16|32|64)| | 259 | (?:__)?(?:u|s|be|le)(?:8|16|32|64)| |
| 256 | atomic_t | 260 | atomic_t |
| @@ -1330,6 +1334,9 @@ sub process { | |||
| 1330 | my $signoff = 0; | 1334 | my $signoff = 0; |
| 1331 | my $is_patch = 0; | 1335 | my $is_patch = 0; |
| 1332 | 1336 | ||
| 1337 | my $in_header_lines = 1; | ||
| 1338 | my $in_commit_log = 0; #Scanning lines before patch | ||
| 1339 | |||
| 1333 | our @report = (); | 1340 | our @report = (); |
| 1334 | our $cnt_lines = 0; | 1341 | our $cnt_lines = 0; |
| 1335 | our $cnt_error = 0; | 1342 | our $cnt_error = 0; |
| @@ -1497,7 +1504,6 @@ sub process { | |||
| 1497 | if ($line =~ /^diff --git.*?(\S+)$/) { | 1504 | if ($line =~ /^diff --git.*?(\S+)$/) { |
| 1498 | $realfile = $1; | 1505 | $realfile = $1; |
| 1499 | $realfile =~ s@^([^/]*)/@@; | 1506 | $realfile =~ s@^([^/]*)/@@; |
| 1500 | |||
| 1501 | } elsif ($line =~ /^\+\+\+\s+(\S+)/) { | 1507 | } elsif ($line =~ /^\+\+\+\s+(\S+)/) { |
| 1502 | $realfile = $1; | 1508 | $realfile = $1; |
| 1503 | $realfile =~ s@^([^/]*)/@@; | 1509 | $realfile =~ s@^([^/]*)/@@; |
| @@ -1536,6 +1542,7 @@ sub process { | |||
| 1536 | # Check the patch for a signoff: | 1542 | # Check the patch for a signoff: |
| 1537 | if ($line =~ /^\s*signed-off-by:/i) { | 1543 | if ($line =~ /^\s*signed-off-by:/i) { |
| 1538 | $signoff++; | 1544 | $signoff++; |
| 1545 | $in_commit_log = 0; | ||
| 1539 | } | 1546 | } |
| 1540 | 1547 | ||
| 1541 | # Check signature styles | 1548 | # Check signature styles |
| @@ -1613,6 +1620,21 @@ sub process { | |||
| 1613 | "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr); | 1620 | "Invalid UTF-8, patch and commit message should be encoded in UTF-8\n" . $hereptr); |
| 1614 | } | 1621 | } |
| 1615 | 1622 | ||
| 1623 | # Check if it's the start of a commit log | ||
| 1624 | # (not a header line and we haven't seen the patch filename) | ||
| 1625 | if ($in_header_lines && $realfile =~ /^$/ && | ||
| 1626 | $rawline !~ /^(commit\b|from\b|\w+:).+$/i) { | ||
| 1627 | $in_header_lines = 0; | ||
| 1628 | $in_commit_log = 1; | ||
| 1629 | } | ||
| 1630 | |||
| 1631 | # Still not yet in a patch, check for any UTF-8 | ||
| 1632 | if ($in_commit_log && $realfile =~ /^$/ && | ||
| 1633 | $rawline =~ /$NON_ASCII_UTF8/) { | ||
| 1634 | CHK("UTF8_BEFORE_PATCH", | ||
| 1635 | "8-bit UTF-8 used in possible commit log\n" . $herecurr); | ||
| 1636 | } | ||
| 1637 | |||
| 1616 | # ignore non-hunk lines and lines being removed | 1638 | # ignore non-hunk lines and lines being removed |
| 1617 | next if (!$hunk_line || $line =~ /^-/); | 1639 | next if (!$hunk_line || $line =~ /^-/); |
| 1618 | 1640 | ||
| @@ -1661,6 +1683,20 @@ sub process { | |||
| 1661 | #print "is_end<$is_end> length<$length>\n"; | 1683 | #print "is_end<$is_end> length<$length>\n"; |
| 1662 | } | 1684 | } |
| 1663 | 1685 | ||
| 1686 | if (($realfile =~ /Makefile.*/ || $realfile =~ /Kbuild.*/) && | ||
| 1687 | ($line =~ /\+(EXTRA_[A-Z]+FLAGS).*/)) { | ||
| 1688 | my $flag = $1; | ||
| 1689 | my $replacement = { | ||
| 1690 | 'EXTRA_AFLAGS' => 'asflags-y', | ||
| 1691 | 'EXTRA_CFLAGS' => 'ccflags-y', | ||
| 1692 | 'EXTRA_CPPFLAGS' => 'cppflags-y', | ||
| 1693 | 'EXTRA_LDFLAGS' => 'ldflags-y', | ||
| 1694 | }; | ||
| 1695 | |||
| 1696 | WARN("DEPRECATED_VARIABLE", | ||
| 1697 | "Use of $flag is deprecated, please use \`$replacement->{$flag} instead.\n" . $herecurr) if ($replacement->{$flag}); | ||
| 1698 | } | ||
| 1699 | |||
| 1664 | # check we are in a valid source file if not then ignore this hunk | 1700 | # check we are in a valid source file if not then ignore this hunk |
| 1665 | next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); | 1701 | next if ($realfile !~ /\.(h|c|s|S|pl|sh)$/); |
| 1666 | 1702 | ||
| @@ -3151,10 +3187,10 @@ sub process { | |||
| 3151 | "consider using a completion\n" . $herecurr); | 3187 | "consider using a completion\n" . $herecurr); |
| 3152 | 3188 | ||
| 3153 | } | 3189 | } |
| 3154 | # recommend kstrto* over simple_strto* | 3190 | # recommend kstrto* over simple_strto* and strict_strto* |
| 3155 | if ($line =~ /\bsimple_(strto.*?)\s*\(/) { | 3191 | if ($line =~ /\b((simple|strict)_(strto(l|ll|ul|ull)))\s*\(/) { |
| 3156 | WARN("CONSIDER_KSTRTO", | 3192 | WARN("CONSIDER_KSTRTO", |
| 3157 | "consider using kstrto* in preference to simple_$1\n" . $herecurr); | 3193 | "$1 is obsolete, use k$3 instead\n" . $herecurr); |
| 3158 | } | 3194 | } |
| 3159 | # check for __initcall(), use device_initcall() explicitly please | 3195 | # check for __initcall(), use device_initcall() explicitly please |
| 3160 | if ($line =~ /^.\s*__initcall\s*\(/) { | 3196 | if ($line =~ /^.\s*__initcall\s*\(/) { |
