From: Joe Perches Date: Wed, 20 Mar 2013 04:07:45 +0000 (+1100) Subject: checkpatch: add check for reuse of krealloc arg X-Git-Tag: next-20130320~2^2~277 X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=8aa4e94a607468e60b6b3fb91a4754b83ea6c796;p=karo-tx-linux.git 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 Tested-by: Guenter Roeck Acked-by: Guenter Roeck Cc: David Woodhouse Cc: Andy Whitcroft Cc: Jean Delvare Signed-off-by: Andrew Morton --- 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",