mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Lars-Peter Clausen <lars@metafoo.de>
Cc: Andy Whitcroft <apw@shadowen.org>,
	Fengguang Wu <fengguang.wu@intel.com>,
	Jonathan Cameron <jic23@kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [iio:togreg 3/3] WARNING: Reusing the krealloc arg is almost always a bug
Date: Sun, 02 Mar 2014 05:35:19 -0800	[thread overview]
Message-ID: <1393767319.13719.23.camel@joe-AO722> (raw)
In-Reply-To: <1393762005.13719.13.camel@joe-AO722>

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



      reply	other threads:[~2014-03-02 13:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <53124ca5.kw+3caZ7enyrhSmq%fengguang.wu@intel.com>
     [not found] ` <20140302022404.GA16141@localhost>
2014-03-02  9:11   ` Lars-Peter Clausen
2014-03-02 12:06     ` Joe Perches
2014-03-02 13:35       ` Joe Perches [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1393767319.13719.23.camel@joe-AO722 \
    --to=joe@perches.com \
    --cc=apw@shadowen.org \
    --cc=fengguang.wu@intel.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®