Commit 972fdea2 authored by Joe Perches's avatar Joe Perches Committed by Linus Torvalds
Browse files

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: default avatarJoe Perches <>
Tested-by: default avatarGuenter Roeck <>
Acked-by: default avatarGuenter Roeck <>
Cc: David Woodhouse <>
Cc: Andy Whitcroft <>
Cc: Jean Delvare <>
Signed-off-by: default avatarAndrew Morton <>
Signed-off-by: default avatarLinus Torvalds <>
parent 2e0fb404
......@@ -3477,6 +3477,13 @@ sub process {
"unnecessary cast may hide bugs, see\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*,/) {
"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/) {
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment