Skip to content

Commit 972fdea

Browse files
JoePerchestorvalds
authored andcommitted
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 <[email protected]> Tested-by: Guenter Roeck <[email protected]> Acked-by: Guenter Roeck <[email protected]> Cc: David Woodhouse <[email protected]> Cc: Andy Whitcroft <[email protected]> Cc: Jean Delvare <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent 2e0fb40 commit 972fdea

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

scripts/checkpatch.pl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,6 +3477,13 @@ sub process {
34773477
"unnecessary cast may hide bugs, see http://c-faq.com/malloc/mallocnocast.html\n" . $herecurr);
34783478
}
34793479

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+
34803487
# check for alloc argument mismatch
34813488
if ($line =~ /\b(kcalloc|kmalloc_array)\s*\(\s*sizeof\b/) {
34823489
WARN("ALLOC_ARRAY_ARGS",

0 commit comments

Comments
 (0)