aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/checkpatch.pl
diff options
context:
space:
mode:
authorJoe Perches <joe@perches.com>2013-04-29 19:18:12 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-04-29 21:28:19 -0400
commit972fdea2e6ece7578915d386a5447bc78d3fb8b8 (patch)
tree22c3cf9b8c078efc8d272df333416faca460914a /scripts/checkpatch.pl
parent2e0fb404c86d6c86dc33e284310eb5d28d192dcf (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> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'scripts/checkpatch.pl')
-rwxr-xr-xscripts/checkpatch.pl7
1 files changed, 7 insertions, 0 deletions
diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index 4de4bc48493b..a820249a3fce 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -3477,6 +3477,13 @@ sub process {
3477 "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr); 3477 "unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
3478 } 3478 }
3479 3479
3480# check for krealloc arg reuse
3481 if ($^V && $^V ge 5.10.0 &&
3482 $line =~ /\b($Lval)\s*\=\s*(?:$balanced_parens)?\s*krealloc\s*\(\s*\1\s*,/) {
3483 WARN("KREALLOC_ARG_REUSE",
3484 "Reusing the krealloc arg is almost always a bug\n" . $herecurr);
3485 }
3486
3480# check for alloc argument mismatch 3487# check for alloc argument mismatch
3481 if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) { 3488 if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
3482 WARN("ALLOC_ARRAY_ARGS", 3489 WARN("ALLOC_ARRAY_ARGS",