Skip to content

Commit 73f1d07

Browse files
checkpatch: add new alloc functions to alloc with multiplies check
kvmalloc() and kvzalloc() functions have now 2-factor multiplication argument forms kvmalloc_array() and kvcalloc(), correspondingly. Add alloc-with-multiplies checks for these new functions. Link: KSPP#187 Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.org>
1 parent ce522ba commit 73f1d07

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

scripts/checkpatch.pl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7033,14 +7033,16 @@ sub process {
70337033
"Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr);
70347034
}
70357035

7036-
# check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc
7036+
# check for (kv|k)[mz]alloc with multiplies that could be kmalloc_array/kvmalloc_array/kvcalloc/kcalloc
70377037
if ($perl_version_ok &&
70387038
defined $stat &&
7039-
$stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
7039+
$stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*((?:kv|k)[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) {
70407040
my $oldfunc = $3;
70417041
my $a1 = $4;
70427042
my $a2 = $10;
70437043
my $newfunc = "kmalloc_array";
7044+
$newfunc = "kvmalloc_array" if ($oldfunc eq "kvmalloc");
7045+
$newfunc = "kvcalloc" if ($oldfunc eq "kvzalloc");
70447046
$newfunc = "kcalloc" if ($oldfunc eq "kzalloc");
70457047
my $r1 = $a1;
70467048
my $r2 = $a2;
@@ -7057,7 +7059,7 @@ sub process {
70577059
"Prefer $newfunc over $oldfunc with multiply\n" . $herectx) &&
70587060
$cnt == 1 &&
70597061
$fix) {
7060-
$fixed[$fixlinenr] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e;
7062+
$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;
70617063
}
70627064
}
70637065
}

0 commit comments

Comments
 (0)