That last one doesn't work if the krealloc has a cast like foo = (struct bar *)krealloc(foo, 1, GFP_KERNEL) Maybe this one is better... --- scripts/checkpatch.pl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-)
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 91308be..43914c3 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -4275,9 +4275,20 @@ sub process { # check for krealloc arg reuse if ($^V && $^V ge 5.10.0 && - $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) { - WARN("KREALLOC_ARG_REUSE", - "Reusing the krealloc arg is almost always a bug\n" . $herecurr); + $line =~ /($Lval)\s*\=\s*($balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) { + my $cast = $2; + my $cast_count = 0; + my @line_lvals = $line =~ m/$Lval/g; + if (defined $cast) { + $cast_count++ while ($cast =~ /$Lval/g); + } + for my $index (1 + $cast_count .. $#line_lvals - 1) { + if ($line_lvals[$index] eq "krealloc" && + $line_lvals[$index - 1 - $cast_count] eq $line_lvals[$index + 1]) { + WARN("KREALLOC_ARG_REUSE", + "Reusing the krealloc arg is almost always a bug\n" . $herecurr); + } + } } # check for alloc argument mismatch -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/