diff options
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index e7ff52a39ec9..77740252bbed 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -4378,6 +4378,30 @@ sub process { | |||
4378 | "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr); | 4378 | "Prefer $3(sizeof(*$1)...) over $3($4...)\n" . $herecurr); |
4379 | } | 4379 | } |
4380 | 4380 | ||
4381 | # check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc | ||
4382 | if ($^V && $^V ge 5.10.0 && | ||
4383 | $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/) { | ||
4384 | my $oldfunc = $3; | ||
4385 | my $a1 = $4; | ||
4386 | my $a2 = $10; | ||
4387 | my $newfunc = "kmalloc_array"; | ||
4388 | $newfunc = "kcalloc" if ($oldfunc eq "kzalloc"); | ||
4389 | if ($a1 =~ /^sizeof\s*\S/ || $a2 =~ /^sizeof\s*\S/) { | ||
4390 | if (WARN("ALLOC_WITH_MULTIPLY", | ||
4391 | "Prefer $newfunc over $oldfunc with multiply\n" . $herecurr) && | ||
4392 | $fix) { | ||
4393 | my $r1 = $a1; | ||
4394 | my $r2 = $a2; | ||
4395 | if ($a1 =~ /^sizeof\s*\S/) { | ||
4396 | $r1 = $a2; | ||
4397 | $r2 = $a1; | ||
4398 | } | ||
4399 | $fixed[$linenr - 1] =~ s/\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)/$1 . ' = ' . "$newfunc(" . trim($r1) . ', ' . trim($r2)/e; | ||
4400 | |||
4401 | } | ||
4402 | } | ||
4403 | } | ||
4404 | |||
4381 | # check for krealloc arg reuse | 4405 | # check for krealloc arg reuse |
4382 | if ($^V && $^V ge 5.10.0 && | 4406 | if ($^V && $^V ge 5.10.0 && |
4383 | $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) { | 4407 | $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) { |