]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
checkpatch: add check for reuse of krealloc arg
authorJoe Perches <joe@perches.com>
Wed, 20 Mar 2013 04:07:45 +0000 (15:07 +1100)
committerStephen Rothwell <sfr@canb.auug.org.au>
Wed, 20 Mar 2013 04:23:01 +0000 (15:23 +1100)
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>
scripts/checkpatch.pl

index b28cc384a5bcf30952f66d7da5b349978e39b49a..7ef2b4bd0145a7c463bc3732e7909eb8cbe326a7 100755 (executable)
@@ -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",