@@ -834,6 +834,16 @@ sub find_standard_signature {
834
834
# Create a search pattern for all these strings to speed up a loop below
835
835
our $deprecated_apis_search = ' (?:' . join (' |' , keys %deprecated_apis ) . ' )' ;
836
836
837
+ our %alloc_with_multiply_apis = (
838
+ " kmalloc" => " kmalloc_array" ,
839
+ " kvmalloc" => " kvmalloc_array" ,
840
+ " vmalloc" => " vmalloc_array" ,
841
+ " kvzalloc" => " kvcalloc" ,
842
+ " kzalloc" => " kcalloc" ,
843
+ " vzalloc" => " vcalloc" ,
844
+ );
845
+ our $alloc_with_multiply_search = ' (?:' . join (' |' , keys %alloc_with_multiply_apis ) . ' )' ;
846
+
837
847
our $mode_perms_world_writable = qr {
838
848
S_IWUGO |
839
849
S_IWOTH |
@@ -7187,17 +7197,14 @@ sub process {
7187
7197
" Prefer $3 (sizeof(*$1 )...) over $3 ($4 ...)\n " . $herecurr );
7188
7198
}
7189
7199
7190
- # check for (kv|k)[mz]alloc with multiplies that could be kmalloc_array/kvmalloc_array/kvcalloc/kcalloc
7200
+ # check for various allocs with multiplies that should use safer functions
7191
7201
if ($perl_version_ok &&
7192
7202
defined $stat &&
7193
- $stat =~ / ^\+\s *($Lval )\s *\=\s *(?:$balanced_parens )?\s *((?:kv|k)[mz]alloc )\s *\(\s *($FuncArg )\s *\*\s *($FuncArg )\s *,/ ) {
7203
+ $stat =~ / ^\+\s *($Lval )\s *\=\s *(?:$balanced_parens )?\s *($alloc_with_multiply_search )\s *\(\s *($FuncArg )\s *\*\s *($FuncArg )\s *,/ ) {
7194
7204
my $oldfunc = $3 ;
7205
+ my $newfunc = $alloc_with_multiply_apis {$oldfunc };
7195
7206
my $a1 = $4 ;
7196
7207
my $a2 = $10 ;
7197
- my $newfunc = " kmalloc_array" ;
7198
- $newfunc = " kvmalloc_array" if ($oldfunc eq " kvmalloc" );
7199
- $newfunc = " kvcalloc" if ($oldfunc eq " kvzalloc" );
7200
- $newfunc = " kcalloc" if ($oldfunc eq " kzalloc" );
7201
7208
my $r1 = $a1 ;
7202
7209
my $r2 = $a2 ;
7203
7210
if ($a1 =~ / ^sizeof\s *\S / ) {
@@ -7213,7 +7220,7 @@ sub process {
7213
7220
" Prefer $newfunc over $oldfunc with multiply\n " . $herectx ) &&
7214
7221
$cnt == 1 &&
7215
7222
$fix ) {
7216
- $fixed [$fixlinenr ] =~ s /\b ($Lval)\s *\=\s *(?:$balanced_parens)?\s *((?:kv|k)[mz]alloc )\s *\(\s *($FuncArg)\s *\*\s *($FuncArg)/ $1 . ' = ' . "$newfunc (" . trim($r1 ) . ', ' . trim($r2 )/ e ;
7223
+ $fixed [$fixlinenr ] =~ s /\b ($Lval)\s *\=\s *(?:$balanced_parens)?\s *($oldfunc )\s *\(\s *($FuncArg)\s *\*\s *($FuncArg)/ $1 . ' = ' . "$newfunc (" . trim($r1 ) . ', ' . trim($r2 )/ e ;
7217
7224
}
7218
7225
}
7219
7226
}
0 commit comments