lkml.org 
[lkml]   [2014]   [Mar]   [2]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [iio:togreg 3/3] WARNING: Reusing the krealloc arg is almost always a bug
From
Date
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



\
 
 \ /
  Last update: 2014-03-02 15:01    [W:0.046 / U:0.884 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site