The patch titled Subject: checkpatch: add check for reuse of krealloc arg has been added to the -mm tree. Its filename is checkpatch-add-check-for-reuse-of-krealloc-arg.patch Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/SubmitChecklist when testing your code *** The -mm tree is included into linux-next and is updated there every 3-4 working days ------------------------------------------------------ From: Joe Perches <joe@xxxxxxxxxxx> Subject: 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@xxxxxxxxxxx> Tested-by: Guenter Roeck <linux@xxxxxxxxxxxx> Acked-by: Guenter Roeck <linux@xxxxxxxxxxxx> Cc: David Woodhouse <dwmw2@xxxxxxxxxxxxx> Cc: Andy Whitcroft <apw@xxxxxxxxxxxxx> Cc: Jean Delvare <khali@xxxxxxxxxxxx> Signed-off-by: Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> --- scripts/checkpatch.pl | 7 +++++++ 1 file changed, 7 insertions(+) diff -puN scripts/checkpatch.pl~checkpatch-add-check-for-reuse-of-krealloc-arg scripts/checkpatch.pl --- a/scripts/checkpatch.pl~checkpatch-add-check-for-reuse-of-krealloc-arg +++ a/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", _ Patches currently in -mm which might be from joe@xxxxxxxxxxx are origin.patch linux-next.patch get_maintainer-use-filename-only-regex-match-for-tegra.patch get_maintainer-use-filename-only-regex-match-for-tegra-fix.patch checkpatch-add-check-for-reuse-of-krealloc-arg.patch kexec-fix-wrong-types-of-some-local-variables.patch kexec-use-min_t-to-simplify-logic.patch kexec-use-min_t-to-simplify-logic-fix.patch -- To unsubscribe from this list: send the line "unsubscribe mm-commits" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html