Skip to content

Commit eaa8fc4

Browse files
GustavoARSilvaintel-lab-lkp
authored andcommitted
checkpatch: add a couple new alloc functions to alloc with multiplies check
vmalloc() and vzalloc() functions have now 2-factor multiplication argument forms vmalloc_array() and vcalloc(), correspondingly. Add alloc-with-multiplies checks for these new functions. Link: KSPP#342 Signed-off-by: Gustavo A. R. Silva <[email protected]>
1 parent a747acc commit eaa8fc4

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

scripts/checkpatch.pl

+5-3
Original file line numberDiff line numberDiff line change
@@ -7207,17 +7207,19 @@ sub process {
72077207
"Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
72087208
}
72097209

7210-
# check for (kv|k)[mz]alloc with multiplies that could be kmalloc_array/kvmalloc_array/kvcalloc/kcalloc
7210+
# check for (kv|k|v)[mz]alloc with multiplies that could be kmalloc_array/kvmalloc_array/vmalloc_array/kvcalloc/kcalloc/vcalloc
72117211
if ($perl_version_ok &&
72127212
defined $stat &&
7213-
$stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
7213+
$stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k|v)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,?/) {
72147214
my $oldfunc = $3;
72157215
my $a1 = $4;
72167216
my $a2 = $10;
72177217
my $newfunc = "kmalloc_array";
72187218
$newfunc = "kvmalloc_array" if ($oldfunc eq "kvmalloc");
7219+
$newfunc = "vmalloc_array" if ($oldfunc eq "vmalloc");
72197220
$newfunc = "kvcalloc" if ($oldfunc eq "kvzalloc");
72207221
$newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
7222+
$newfunc = "vcalloc" if ($oldfunc eq "vzalloc");
72217223
my $r1 = $a1;
72227224
my $r2 = $a2;
72237225
if ($a1 =~ /^sizeof\s*\S/) {
@@ -7233,7 +7235,7 @@ sub process {
72337235
"Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
72347236
$cnt == 1 &&
72357237
$fix) {
7236-
$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;
7238+
$fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k|v)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
72377239
}
72387240
}
72397241
}

0 commit comments

Comments
 (0)