From: Guenter Roeck <linux@roeck-us.net>
To: Joe Perches <joe@perches.com>
Cc: David Woodhouse <dwmw2@infradead.org>,
Andrew Morton <akpm@linux-foundation.org>,
Andy Whitcroft <apw@canonical.com>,
Jean Delvare <khali@linux-fr.org>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] checkpatch: Add check for reuse of krealloc arg
Date: Thu, 14 Mar 2013 09:39:04 -0700 [thread overview]
Message-ID: <20130314163904.GA11384@roeck-us.net> (raw)
In-Reply-To: <1363277885.2146.3.camel@joe-AO722>
On Thu, Mar 14, 2013 at 09:18:05AM -0700, Joe Perches wrote:
> On Thu, 2013-03-14 at 13:30 +0000, David Woodhouse wrote:
> > If krealloc() returns NULL, it *doesn't* free the original. So any code
> > of the form 'foo = krealloc(foo, …);' is almost certainly a bug.
>
> So add a check for it to checkpatch.
>
> Signed-off-by: Joe Perches <joe@perches.com>
Excellent idea.
Tested-by: Guenter Roeck <linux@roeck-us.net>
Acked-by: Guenter Roeck <linux@roeck-us.net>
> ---
> scripts/checkpatch.pl | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index b28cc38..7ef2b4b 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -3476,6 +3476,13 @@ sub process {
> "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
> }
>
> +# 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);
> + }
> +
> # check for alloc argument mismatch
> if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
> WARN("ALLOC_ARRAY_ARGS",
>
>
>
prev parent reply other threads:[~2013-03-14 16:39 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-14 13:30 [PATCH] hwmon: (pmbus) Fix krealloc() misuse in pmbus_add_attribute() David Woodhouse
2013-03-14 13:59 ` Guenter Roeck
2013-03-14 16:18 ` [PATCH] checkpatch: Add check for reuse of krealloc arg Joe Perches
2013-03-14 16:39 ` Guenter Roeck [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=20130314163904.GA11384@roeck-us.net \
--to=linux@roeck-us.net \
--cc=akpm@linux-foundation.org \
--cc=apw@canonical.com \
--cc=dwmw2@infradead.org \
--cc=joe@perches.com \
--cc=khali@linux-fr.org \
--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®