diff options
author | Joe Perches <joe@perches.com> | 2017-05-08 18:55:57 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-05-08 20:15:11 -0400 |
commit | 1b4a2ed4c8773524cc7890c4cd57d58b39c049eb (patch) | |
tree | 626671fa831a57cbf9f55653eba2284fe5343c45 /scripts | |
parent | e882dbfc248cf28d6afd6fc6d8db8be58a824158 (diff) |
checkpatch: improve k.alloc with multiplication and sizeof test
Find multi-line uses of k.alloc by using the $stat variable and not the
$line variable. This can still --fix only the single line variant
though.
Link: http://lkml.kernel.org/r/3f4b23d37cd4c7d8628eefc25afe83ba8fb3ab55.1493167076.git.joe@perches.com
Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/checkpatch.pl | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index b1befa2cec26..d2c074feaa7d 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl | |||
@@ -5922,7 +5922,8 @@ sub process { | |||
5922 | 5922 | ||
5923 | # check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc | 5923 | # check for k[mz]alloc with multiplies that could be kmalloc_array/kcalloc |
5924 | if ($^V && $^V ge 5.10.0 && | 5924 | if ($^V && $^V ge 5.10.0 && |
5925 | $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) { | 5925 | defined $stat && |
5926 | $stat =~ /^\+\s*($Lval)\s*\=\s*(?:$balanced_parens)?\s*(k[mz]alloc)\s*\(\s*($FuncArg)\s*\*\s*($FuncArg)\s*,/) { | ||
5926 | my $oldfunc = $3; | 5927 | my $oldfunc = $3; |
5927 | my $a1 = $4; | 5928 | my $a1 = $4; |
5928 | my $a2 = $10; | 5929 | my $a2 = $10; |
@@ -5936,11 +5937,17 @@ sub process { | |||
5936 | } | 5937 | } |
5937 | if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ && | 5938 | if ($r1 !~ /^sizeof\b/ && $r2 =~ /^sizeof\s*\S/ && |
5938 | !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) { | 5939 | !($r1 =~ /^$Constant$/ || $r1 =~ /^[A-Z_][A-Z0-9_]*$/)) { |
5940 | my $ctx = ''; | ||
5941 | my $herectx = $here . "\n"; | ||
5942 | my $cnt = statement_rawlines($stat); | ||
5943 | for (my $n = 0; $n < $cnt; $n++) { | ||
5944 | $herectx .= raw_line($linenr, $n) . "\n"; | ||
5945 | } | ||
5939 | if (WARN("ALLOC_WITH_MULTIPLY", | 5946 | if (WARN("ALLOC_WITH_MULTIPLY", |
5940 | "Prefer $newfunc over $oldfunc with multiply\n" . $herecurr) && | 5947 | "Prefer $newfunc over $oldfunc with multiply\n" . $herectx) && |
5948 | $cnt == 1 && | ||
5941 | $fix) { | 5949 | $fix) { |
5942 | $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; | 5950 | $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; |
5943 | |||
5944 | } | 5951 | } |
5945 | } | 5952 | } |
5946 | } | 5953 | } |