summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2013-03-20 15:07:45 +1100
committerStephen Rothwell <sfr@canb.auug.org.au>2013-03-21 16:34:04 +1100
commit5fc7f49b5d1d7aabcd25596b18f115f76c45676b (patch)
treec4dafe7ce2b272612318e8876776b253c578d3ce /scripts
parent98dc5e345be094bd9ac347a5fa9e4b2142e7a4f3 (diff)
checkpatch: add check for reuse of krealloc arg
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> Tested-by: Guenter Roeck <linux@roeck-us.net> Acked-by: Guenter Roeck <linux@roeck-us.net> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Andy Whitcroft <apw@canonical.com> Cc: Jean Delvare <khali@linux-fr.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/checkpatch.pl7
1 files changed, 7 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b28cc384a5bc..7ef2b4bd0145 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",