aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2018-08-22 00:57:33 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2018-08-22 13:52:48 -0400
commit5b57980de6b228696dfaf70ad50a8550fbb14fc7 (patch)
tree31287b2ad89ad2b9860b0b02d013f7d5db5255b4 /scripts
parent79682c0c00893c683678d85a402392b75e90311d (diff)
checkpatch: improve runtime execution speed a little
checkpatch repeatedly uses a runtime minimum version check that validates the minimum perl version required for a regex match by using a "$^V ge 5.10.0" runtime string match. Only perform that minimum version test once and store the result to reduce string matching time. This reduces runtime execution time for patches or files with high line counts. An example runtime improvement: new: $ time ./scripts/checkpatch.pl -f drivers/net/ethernet/intel/i40e/i40e_main.c > /dev/null real 0m11.856s user 0m11.831s sys 0m0.025s old: $ time ./scripts/checkpatch.pl -f drivers/net/ethernet/intel/i40e/i40e_main.c > /dev/null real 0m13.330s user 0m13.282s sys 0m0.049s Link: http://lkml.kernel.org/r/db21aa9703833bad65ab70cc4e8a78da5b399138.camel@perches.com Signed-off-by: Joe Perches <joe@perches.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl66
1 files changed, 33 insertions, 33 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index f2e00dc0ae89..0f9788ab988b 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -240,11 +240,11 @@ $check_orig = $check;
240 240
241my $exit = 0; 241my $exit = 0;
242 242
243my $perl_version_ok = 1;
243if ($^V && $^V lt $minimum_perl_version) { 244if ($^V && $^V lt $minimum_perl_version) {
245 $perl_version_ok = 0;
244 printf "$P: requires at least perl version %vd\n", $minimum_perl_version; 246 printf "$P: requires at least perl version %vd\n", $minimum_perl_version;
245 if (!$ignore_perl_version) { 247 exit(1) if (!$ignore_perl_version);
246 exit(1);
247 }
248} 248}
249 249
250#if no filenames are given, push '-' to read patch from stdin 250#if no filenames are given, push '-' to read patch from stdin
@@ -1026,11 +1026,11 @@ if (!$quiet) {
1026 hash_show_words(\%use_type, "Used"); 1026 hash_show_words(\%use_type, "Used");
1027 hash_show_words(\%ignore_type, "Ignored"); 1027 hash_show_words(\%ignore_type, "Ignored");
1028 1028
1029 if ($^V lt 5.10.0) { 1029 if (!$perl_version_ok) {
1030 print << "EOM" 1030 print << "EOM"
1031 1031
1032NOTE: perl $^V is not modern enough to detect all possible issues. 1032NOTE: perl $^V is not modern enough to detect all possible issues.
1033 An upgrade to at least perl v5.10.0 is suggested. 1033 An upgrade to at least perl $minimum_perl_version is suggested.
1034EOM 1034EOM
1035 } 1035 }
1036 if ($exit) { 1036 if ($exit) {
@@ -3079,7 +3079,7 @@ sub process {
3079 } 3079 }
3080 3080
3081# check indentation starts on a tab stop 3081# check indentation starts on a tab stop
3082 if ($^V && $^V ge 5.10.0 && 3082 if ($perl_version_ok &&
3083 $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;=])/) { 3083 $sline =~ /^\+\t+( +)(?:$c90_Keywords\b|\{\s*$|\}\s*(?:else\b|while\b|\s*$)|$Declare\s*$Ident\s*[;=])/) {
3084 my $indent = length($1); 3084 my $indent = length($1);
3085 if ($indent % 8) { 3085 if ($indent % 8) {
@@ -3092,7 +3092,7 @@ sub process {
3092 } 3092 }
3093 3093
3094# check multi-line statement indentation matches previous line 3094# check multi-line statement indentation matches previous line
3095 if ($^V && $^V ge 5.10.0 && 3095 if ($perl_version_ok &&
3096 $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|(?:\*\s*)*$Lval\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) { 3096 $prevline =~ /^\+([ \t]*)((?:$c90_Keywords(?:\s+if)\s*)|(?:$Declare\s*)?(?:$Ident|\(\s*\*\s*$Ident\s*\))\s*|(?:\*\s*)*$Lval\s*=\s*$Ident\s*)\(.*(\&\&|\|\||,)\s*$/) {
3097 $prevline =~ /^\+(\t*)(.*)$/; 3097 $prevline =~ /^\+(\t*)(.*)$/;
3098 my $oldindent = $1; 3098 my $oldindent = $1;
@@ -3967,7 +3967,7 @@ sub process {
3967 3967
3968# function brace can't be on same line, except for #defines of do while, 3968# function brace can't be on same line, except for #defines of do while,
3969# or if closed on same line 3969# or if closed on same line
3970 if ($^V && $^V ge 5.10.0 && 3970 if ($perl_version_ok &&
3971 $sline =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ && 3971 $sline =~ /$Type\s*$Ident\s*$balanced_parens\s*\{/ &&
3972 $sline !~ /\#\s*define\b.*do\s*\{/ && 3972 $sline !~ /\#\s*define\b.*do\s*\{/ &&
3973 $sline !~ /}/) { 3973 $sline !~ /}/) {
@@ -4578,7 +4578,7 @@ sub process {
4578# check for unnecessary parentheses around comparisons in if uses 4578# check for unnecessary parentheses around comparisons in if uses
4579# when !drivers/staging or command-line uses --strict 4579# when !drivers/staging or command-line uses --strict
4580 if (($realfile !~ m@^(?:drivers/staging/)@ || $check_orig) && 4580 if (($realfile !~ m@^(?:drivers/staging/)@ || $check_orig) &&
4581 $^V && $^V ge 5.10.0 && defined($stat) && 4581 $perl_version_ok && defined($stat) &&
4582 $stat =~ /(^.\s*if\s*($balanced_parens))/) { 4582 $stat =~ /(^.\s*if\s*($balanced_parens))/) {
4583 my $if_stat = $1; 4583 my $if_stat = $1;
4584 my $test = substr($2, 1, -1); 4584 my $test = substr($2, 1, -1);
@@ -4615,7 +4615,7 @@ sub process {
4615# return is not a function 4615# return is not a function
4616 if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) { 4616 if (defined($stat) && $stat =~ /^.\s*return(\s*)\(/s) {
4617 my $spacing = $1; 4617 my $spacing = $1;
4618 if ($^V && $^V ge 5.10.0 && 4618 if ($perl_version_ok &&
4619 $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) { 4619 $stat =~ /^.\s*return\s*($balanced_parens)\s*;\s*$/) {
4620 my $value = $1; 4620 my $value = $1;
4621 $value = deparenthesize($value); 4621 $value = deparenthesize($value);
@@ -4642,7 +4642,7 @@ sub process {
4642 } 4642 }
4643 4643
4644# if statements using unnecessary parentheses - ie: if ((foo == bar)) 4644# if statements using unnecessary parentheses - ie: if ((foo == bar))
4645 if ($^V && $^V ge 5.10.0 && 4645 if ($perl_version_ok &&
4646 $line =~ /\bif\s*((?:\(\s*){2,})/) { 4646 $line =~ /\bif\s*((?:\(\s*){2,})/) {
4647 my $openparens = $1; 4647 my $openparens = $1;
4648 my $count = $openparens =~ tr@\(@\(@; 4648 my $count = $openparens =~ tr@\(@\(@;
@@ -4659,7 +4659,7 @@ sub process {
4659# avoid cases like "foo + BAR < baz" 4659# avoid cases like "foo + BAR < baz"
4660# only fix matches surrounded by parentheses to avoid incorrect 4660# only fix matches surrounded by parentheses to avoid incorrect
4661# conversions like "FOO < baz() + 5" being "misfixed" to "baz() > FOO + 5" 4661# conversions like "FOO < baz() + 5" being "misfixed" to "baz() > FOO + 5"
4662 if ($^V && $^V ge 5.10.0 && 4662 if ($perl_version_ok &&
4663 $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) { 4663 $line =~ /^\+(.*)\b($Constant|[A-Z_][A-Z0-9_]*)\s*($Compare)\s*($LvalOrFunc)/) {
4664 my $lead = $1; 4664 my $lead = $1;
4665 my $const = $2; 4665 my $const = $2;
@@ -5084,7 +5084,7 @@ sub process {
5084# do {} while (0) macro tests: 5084# do {} while (0) macro tests:
5085# single-statement macros do not need to be enclosed in do while (0) loop, 5085# single-statement macros do not need to be enclosed in do while (0) loop,
5086# macro should not end with a semicolon 5086# macro should not end with a semicolon
5087 if ($^V && $^V ge 5.10.0 && 5087 if ($perl_version_ok &&
5088 $realfile !~ m@/vmlinux.lds.h$@ && 5088 $realfile !~ m@/vmlinux.lds.h$@ &&
5089 $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) { 5089 $line =~ /^.\s*\#\s*define\s+$Ident(\()?/) {
5090 my $ln = $linenr; 5090 my $ln = $linenr;
@@ -5460,7 +5460,7 @@ sub process {
5460 } 5460 }
5461 5461
5462# check for mask then right shift without a parentheses 5462# check for mask then right shift without a parentheses
5463 if ($^V && $^V ge 5.10.0 && 5463 if ($perl_version_ok &&
5464 $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ && 5464 $line =~ /$LvalOrFunc\s*\&\s*($LvalOrFunc)\s*>>/ &&
5465 $4 !~ /^\&/) { # $LvalOrFunc may be &foo, ignore if so 5465 $4 !~ /^\&/) { # $LvalOrFunc may be &foo, ignore if so
5466 WARN("MASK_THEN_SHIFT", 5466 WARN("MASK_THEN_SHIFT",
@@ -5468,7 +5468,7 @@ sub process {
5468 } 5468 }
5469 5469
5470# check for pointer comparisons to NULL 5470# check for pointer comparisons to NULL
5471 if ($^V && $^V ge 5.10.0) { 5471 if ($perl_version_ok) {
5472 while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) { 5472 while ($line =~ /\b$LvalOrFunc\s*(==|\!=)\s*NULL\b/g) {
5473 my $val = $1; 5473 my $val = $1;
5474 my $equal = "!"; 5474 my $equal = "!";
@@ -5740,7 +5740,7 @@ sub process {
5740 } 5740 }
5741 5741
5742# Check for __attribute__ weak, or __weak declarations (may have link issues) 5742# Check for __attribute__ weak, or __weak declarations (may have link issues)
5743 if ($^V && $^V ge 5.10.0 && 5743 if ($perl_version_ok &&
5744 $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ && 5744 $line =~ /(?:$Declare|$DeclareMisordered)\s*$Ident\s*$balanced_parens\s*(?:$Attribute)?\s*;/ &&
5745 ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ || 5745 ($line =~ /\b__attribute__\s*\(\s*\(.*\bweak\b/ ||
5746 $line =~ /\b__weak\b/)) { 5746 $line =~ /\b__weak\b/)) {
@@ -5822,7 +5822,7 @@ sub process {
5822 } 5822 }
5823 5823
5824# check for vsprintf extension %p<foo> misuses 5824# check for vsprintf extension %p<foo> misuses
5825 if ($^V && $^V ge 5.10.0 && 5825 if ($perl_version_ok &&
5826 defined $stat && 5826 defined $stat &&
5827 $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s && 5827 $stat =~ /^\+(?![^\{]*\{\s*).*\b(\w+)\s*\(.*$String\s*,/s &&
5828 $1 !~ /^_*volatile_*$/) { 5828 $1 !~ /^_*volatile_*$/) {
@@ -5869,7 +5869,7 @@ sub process {
5869 } 5869 }
5870 5870
5871# Check for misused memsets 5871# Check for misused memsets
5872 if ($^V && $^V ge 5.10.0 && 5872 if ($perl_version_ok &&
5873 defined $stat && 5873 defined $stat &&
5874 $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/) { 5874 $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*$FuncArg\s*\)/) {
5875 5875
@@ -5887,7 +5887,7 @@ sub process {
5887 } 5887 }
5888 5888
5889# Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar) 5889# Check for memcpy(foo, bar, ETH_ALEN) that could be ether_addr_copy(foo, bar)
5890# if ($^V && $^V ge 5.10.0 && 5890# if ($perl_version_ok &&
5891# defined $stat &&