From 9819cf252a0fad1bf46aac8a051cf30426e073ee Mon Sep 17 00:00:00 2001 From: Joe Perches Date: Wed, 4 Jun 2014 16:12:09 -0700 Subject: [PATCH] checkpatch: warn on unnecessary void function return statements void function lines that use a single tab then "return;" are generally unnecessary. Signed-off-by: Joe Perches Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- scripts/checkpatch.pl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl index 862cc7a740e2..f354ae619da0 100755 --- a/scripts/checkpatch.pl +++ b/scripts/checkpatch.pl @@ -3470,6 +3470,13 @@ sub process { } } +# unnecessary return in a void function? (a single leading tab, then return;) + if ($sline =~ /^\+\treturn\s*;\s*$/ && + $prevline =~ /^\+/) { + WARN("RETURN_VOID", + "void function return statements are not generally useful\n" . $herecurr); + } + # if statements using unnecessary parentheses - ie: if ((foo == bar)) if ($^V && $^V ge 5.10.0 && $line =~ /\bif\s*((?:\(\s*){2,})/) {