@@ -240,11 +240,11 @@ sub list_types {
240
240
241
241
my $exit = 0;
242
242
243
+ my $perl_version_ok = 1;
243
244
if ($^V && $^V lt $minimum_perl_version ) {
245
+ $perl_version_ok = 0;
244
246
printf " $P : requires at least perl version %vd \n " , $minimum_perl_version ;
245
- if (!$ignore_perl_version ) {
246
- exit (1);
247
- }
247
+ exit (1) if (!$ignore_perl_version );
248
248
}
249
249
250
250
# if no filenames are given, push '-' to read patch from stdin
@@ -1026,11 +1026,11 @@ sub git_commit_info {
1026
1026
hash_show_words(\%use_type , " Used" );
1027
1027
hash_show_words(\%ignore_type , " Ignored" );
1028
1028
1029
- if ($^V lt 5.10.0 ) {
1029
+ if (! $perl_version_ok ) {
1030
1030
print << "EOM"
1031
1031
1032
1032
NOTE: 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.
1034
1034
EOM
1035
1035
}
1036
1036
if ($exit ) {
@@ -3079,7 +3079,7 @@ sub process {
3079
3079
}
3080
3080
3081
3081
# check indentation starts on a tab stop
3082
- if ($^V && $^V ge 5.10.0 &&
3082
+ if ($perl_version_ok &&
3083
3083
$sline =~ / ^\+\t +( +)(?:$c90_Keywords \b |\{\s *$| \}\s *(?:else\b |while\b |\s *$) |$Declare \s *$Ident \s *[;=])/ ) {
3084
3084
my $indent = length ($1 );
3085
3085
if ($indent % 8) {
@@ -3092,7 +3092,7 @@ sub process {
3092
3092
}
3093
3093
3094
3094
# check multi-line statement indentation matches previous line
3095
- if ($^V && $^V ge 5.10.0 &&
3095
+ if ($perl_version_ok &&
3096
3096
$prevline =~ / ^\+ ([ \t ]*)((?:$c90_Keywords (?:\s +if)\s *)|(?:$Declare \s *)?(?:$Ident |\(\s *\*\s *$Ident \s *\) )\s *|(?:\*\s *)*$Lval \s *=\s *$Ident \s *)\( .*(\&\& |\|\| |,)\s *$ / ) {
3097
3097
$prevline =~ / ^\+ (\t *)(.*)$ / ;
3098
3098
my $oldindent = $1 ;
@@ -3967,7 +3967,7 @@ sub process {
3967
3967
3968
3968
# function brace can't be on same line, except for #defines of do while,
3969
3969
# or if closed on same line
3970
- if ($^V && $^V ge 5.10.0 &&
3970
+ if ($perl_version_ok &&
3971
3971
$sline =~ / $Type \s *$Ident \s *$balanced_parens \s *\{ / &&
3972
3972
$sline !~ / \#\s *define\b .*do\s *\{ / &&
3973
3973
$sline !~ / }/ ) {
@@ -4578,7 +4578,7 @@ sub process {
4578
4578
# check for unnecessary parentheses around comparisons in if uses
4579
4579
# when !drivers/staging or command-line uses --strict
4580
4580
if (($realfile !~ m @ ^(?:drivers/staging/)@ || $check_orig ) &&
4581
- $^V && $^V ge 5.10.0 && defined ($stat ) &&
4581
+ $perl_version_ok && defined ($stat ) &&
4582
4582
$stat =~ / (^.\s *if\s *($balanced_parens ))/ ) {
4583
4583
my $if_stat = $1 ;
4584
4584
my $test = substr ($2 , 1, -1);
@@ -4615,7 +4615,7 @@ sub process {
4615
4615
# return is not a function
4616
4616
if (defined ($stat ) && $stat =~ / ^.\s *return(\s *)\( /s ) {
4617
4617
my $spacing = $1 ;
4618
- if ($^V && $^V ge 5.10.0 &&
4618
+ if ($perl_version_ok &&
4619
4619
$stat =~ / ^.\s *return\s *($balanced_parens )\s *;\s *$ / ) {
4620
4620
my $value = $1 ;
4621
4621
$value = deparenthesize($value );
@@ -4642,7 +4642,7 @@ sub process {
4642
4642
}
4643
4643
4644
4644
# if statements using unnecessary parentheses - ie: if ((foo == bar))
4645
- if ($^V && $^V ge 5.10.0 &&
4645
+ if ($perl_version_ok &&
4646
4646
$line =~ / \b if\s *((?:\(\s *){2,})/ ) {
4647
4647
my $openparens = $1 ;
4648
4648
my $count = $openparens =~ tr @ \(@ \(@ ;
@@ -4659,7 +4659,7 @@ sub process {
4659
4659
# avoid cases like "foo + BAR < baz"
4660
4660
# only fix matches surrounded by parentheses to avoid incorrect
4661
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
4663
$line =~ / ^\+ (.*)\b ($Constant |[A-Z_][A-Z0-9_]*)\s *($Compare )\s *($LvalOrFunc )/ ) {
4664
4664
my $lead = $1 ;
4665
4665
my $const = $2 ;
@@ -5084,7 +5084,7 @@ sub process {
5084
5084
# do {} while (0) macro tests:
5085
5085
# single-statement macros do not need to be enclosed in do while (0) loop,
5086
5086
# macro should not end with a semicolon
5087
- if ($^V && $^V ge 5.10.0 &&
5087
+ if ($perl_version_ok &&
5088
5088
$realfile !~ m @ /vmlinux.lds.h$ @ &&
5089
5089
$line =~ / ^.\s *\#\s *define\s +$Ident (\( )?/ ) {
5090
5090
my $ln = $linenr ;
@@ -5460,15 +5460,15 @@ sub process {
5460
5460
}
5461
5461
5462
5462
# check for mask then right shift without a parentheses
5463
- if ($^V && $^V ge 5.10.0 &&
5463
+ if ($perl_version_ok &&
5464
5464
$line =~ / $LvalOrFunc \s *\&\s *($LvalOrFunc )\s *>>/ &&
5465
5465
$4 !~ / ^\& / ) { # $LvalOrFunc may be &foo, ignore if so
5466
5466
WARN(" MASK_THEN_SHIFT" ,
5467
5467
" Possible precedence defect with mask then right shift - may need parentheses\n " . $herecurr );
5468
5468
}
5469
5469
5470
5470
# check for pointer comparisons to NULL
5471
- if ($^V && $^V ge 5.10.0 ) {
5471
+ if ($perl_version_ok ) {
5472
5472
while ($line =~ / \b $LvalOrFunc \s *(==|\! =)\s *NULL\b /g ) {
5473
5473
my $val = $1 ;
5474
5474
my $equal = " !" ;
@@ -5740,7 +5740,7 @@ sub process {
5740
5740
}
5741
5741
5742
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
5744
$line =~ / (?:$Declare |$DeclareMisordered )\s *$Ident \s *$balanced_parens \s *(?:$Attribute )?\s *;/ &&
5745
5745
($line =~ / \b __attribute__\s *\(\s *\( .*\b weak\b / ||
5746
5746
$line =~ / \b __weak\b / )) {
@@ -5822,7 +5822,7 @@ sub process {
5822
5822
}
5823
5823
5824
5824
# check for vsprintf extension %p<foo> misuses
5825
- if ($^V && $^V ge 5.10.0 &&
5825
+ if ($perl_version_ok &&
5826
5826
defined $stat &&
5827
5827
$stat =~ / ^\+ (?![^\{ ]*\{\s *).*\b (\w +)\s *\( .*$String \s *,/s &&
5828
5828
$1 !~ / ^_*volatile_*$ / ) {
@@ -5869,7 +5869,7 @@ sub process {
5869
5869
}
5870
5870
5871
5871
# Check for misused memsets
5872
- if ($^V && $^V ge 5.10.0 &&
5872
+ if ($perl_version_ok &&
5873
5873
defined $stat &&
5874
5874
$stat =~ / ^\+ (?:.*?)\b memset\s *\(\s *$FuncArg \s *,\s *$FuncArg \s *\,\s *$FuncArg \s *\) / ) {
5875
5875
@@ -5887,7 +5887,7 @@ sub process {
5887
5887
}
5888
5888
5889
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
5891
# defined $stat &&
5892
5892
# $stat =~ /^\+(?:.*?)\bmemcpy\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
5893
5893
# if (WARN("PREFER_ETHER_ADDR_COPY",
@@ -5898,7 +5898,7 @@ sub process {
5898
5898
# }
5899
5899
5900
5900
# Check for memcmp(foo, bar, ETH_ALEN) that could be ether_addr_equal*(foo, bar)
5901
- # if ($^V && $^V ge 5.10.0 &&
5901
+ # if ($perl_version_ok &&
5902
5902
# defined $stat &&
5903
5903
# $stat =~ /^\+(?:.*?)\bmemcmp\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
5904
5904
# WARN("PREFER_ETHER_ADDR_EQUAL",
@@ -5907,7 +5907,7 @@ sub process {
5907
5907
5908
5908
# check for memset(foo, 0x0, ETH_ALEN) that could be eth_zero_addr
5909
5909
# check for memset(foo, 0xFF, ETH_ALEN) that could be eth_broadcast_addr
5910
- # if ($^V && $^V ge 5.10.0 &&
5910
+ # if ($perl_version_ok &&
5911
5911
# defined $stat &&
5912
5912
# $stat =~ /^\+(?:.*?)\bmemset\s*\(\s*$FuncArg\s*,\s*$FuncArg\s*\,\s*ETH_ALEN\s*\)/) {
5913
5913
#
@@ -5929,7 +5929,7 @@ sub process {
5929
5929
# }
5930
5930
5931
5931
# typecasts on min/max could be min_t/max_t
5932
- if ($^V && $^V ge 5.10.0 &&
5932
+ if ($perl_version_ok &&
5933
5933
defined $stat &&
5934
5934
$stat =~ / ^\+ (?:.*?)\b (min|max)\s *\(\s *$FuncArg \s *,\s *$FuncArg \s *\) / ) {
5935
5935
if (defined $2 || defined $7 ) {
@@ -5953,7 +5953,7 @@ sub process {
5953
5953
}
5954
5954
5955
5955
# check usleep_range arguments
5956
- if ($^V && $^V ge 5.10.0 &&
5956
+ if ($perl_version_ok &&
5957
5957
defined $stat &&
5958
5958
$stat =~ / ^\+ (?:.*?)\b usleep_range\s *\(\s *($FuncArg )\s *,\s *($FuncArg )\s *\) / ) {
5959
5959
my $min = $1 ;
@@ -5969,7 +5969,7 @@ sub process {
5969
5969
}
5970
5970
5971
5971
# check for naked sscanf
5972
- if ($^V && $^V ge 5.10.0 &&
5972
+ if ($perl_version_ok &&
5973
5973
defined $stat &&
5974
5974
$line =~ / \b sscanf\b / &&
5975
5975
($stat !~ / $Ident \s *=\s *sscanf\s *$balanced_parens / &&
@@ -5983,7 +5983,7 @@ sub process {
5983
5983
}
5984
5984
5985
5985
# check for simple sscanf that should be kstrto<foo>
5986
- if ($^V && $^V ge 5.10.0 &&
5986
+ if ($perl_version_ok &&
5987
5987
defined $stat &&
5988
5988
$line =~ / \b sscanf\b / ) {
5989
5989
my $lc = $stat =~ tr @ \n@@ ;
@@ -6055,7 +6055,7 @@ sub process {
6055
6055
}
6056
6056
6057
6057
# check for function definitions
6058
- if ($^V && $^V ge 5.10.0 &&
6058
+ if ($perl_version_ok &&
6059
6059
defined $stat &&
6060
6060
$stat =~ / ^.\s *(?:$Storage \s +)?$Type \s *($Ident )\s *$balanced_parens \s *{/s ) {
6061
6061
$context_function = $1 ;
@@ -6095,14 +6095,14 @@ sub process {
6095
6095
6096
6096
# alloc style
6097
6097
# p = alloc(sizeof(struct foo), ...) should be p = alloc(sizeof(*p), ...)
6098
- if ($^V && $^V ge 5.10.0 &&
6098
+ if ($perl_version_ok &&
6099
6099
$line =~ / \b ($Lval )\s *\=\s *(?:$balanced_parens )?\s *([kv][mz]alloc(?:_node)?)\s *\(\s *(sizeof\s *\(\s *struct\s +$Lval \s *\) )/ ) {
6100
6100
CHK(" ALLOC_SIZEOF_STRUCT" ,
6101
6101
" Prefer $3 (sizeof(*$1 )...) over $3 ($4 ...)\n " . $herecurr );
6102
6102
}
6103
6103
6104
6104
# check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc
6105
- if ($^V && $^V ge 5.10.0 &&
6105
+ if ($perl_version_ok &&
6106
6106
defined $stat &&
6107
6107
$stat =~ / ^\+\s *($Lval )\s *\=\s *(?:$balanced_parens )?\s *(k[mz]alloc)\s *\(\s *($FuncArg )\s *\*\s *($FuncArg )\s *,/ ) {
6108
6108
my $oldfunc = $3 ;
@@ -6131,7 +6131,7 @@ sub process {
6131
6131
}
6132
6132
6133
6133
# check for krealloc arg reuse
6134
- if ($^V && $^V ge 5.10.0 &&
6134
+ if ($perl_version_ok &&
6135
6135
$line =~ / \b ($Lval )\s *\=\s *(?:$balanced_parens )?\s *krealloc\s *\(\s *\1\s *,/ ) {
6136
6136
WARN(" KREALLOC_ARG_REUSE" ,
6137
6137
" Reusing the krealloc arg is almost always a bug\n " . $herecurr );
@@ -6200,7 +6200,7 @@ sub process {
6200
6200
}
6201
6201
6202
6202
# check for switch/default statements without a break;
6203
- if ($^V && $^V ge 5.10.0 &&
6203
+ if ($perl_version_ok &&
6204
6204
defined $stat &&
6205
6205
$stat =~ / ^\+ [$; \s ]*(?:case[$; \s ]+\w +[$; \s ]*:[$; \s ]*|)*[$; \s ]*\b default[$; \s ]*:[$; \s ]*;/g ) {
6206
6206
my $cnt = statement_rawlines($stat );
@@ -6317,7 +6317,7 @@ sub process {
6317
6317
}
6318
6318
6319
6319
# likely/unlikely comparisons similar to "(likely(foo) > 0)"
6320
- if ($^V && $^V ge 5.10.0 &&
6320
+ if ($perl_version_ok &&
6321
6321
$line =~ / \b ((?:un)?likely)\s *\(\s *$FuncArg \s *\)\s *$Compare / ) {
6322
6322
WARN(" LIKELY_MISUSE" ,
6323
6323
" Using $1 should generally have parentheses around the comparison\n " . $herecurr );
@@ -6360,7 +6360,7 @@ sub process {
6360
6360
# check for DEVICE_ATTR uses that could be DEVICE_ATTR_<FOO>
6361
6361
# and whether or not function naming is typical and if
6362
6362
# DEVICE_ATTR permissions uses are unusual too
6363
- if ($^V && $^V ge 5.10.0 &&
6363
+ if ($perl_version_ok &&
6364
6364
defined $stat &&
6365
6365
$stat =~ / \b DEVICE_ATTR\s *\(\s *(\w +)\s *,\s *\( ?\s *(\s *(?:${multi_mode_perms_string_search} |0[0-7]{3,3})\s *)\s *\) ?\s *,\s *(\w +)\s *,\s *(\w +)\s *\) / ) {
6366
6366
my $var = $1 ;
@@ -6420,7 +6420,7 @@ sub process {
6420
6420
# specific definition of not visible in sysfs.
6421
6421
# o Ignore proc_create*(...) uses with a decimal 0 permission as that means
6422
6422
# use the default permissions
6423
- if ($^V && $^V ge 5.10.0 &&
6423
+ if ($perl_version_ok &&
6424
6424
defined $stat &&
6425
6425
$line =~ / $mode_perms_search / ) {
6426
6426
foreach my $entry (@mode_permission_funcs ) {
0 commit comments