]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
checkpatch: warn on unnecessary void function return statements
authorJoe Perches <joe@perches.com>
Wed, 4 Jun 2014 23:12:09 +0000 (16:12 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 4 Jun 2014 23:54:20 +0000 (16:54 -0700)
void function lines that use a single tab then "return;" are generally
unnecessary.

Signed-off-by: Joe Perches <joe@perches.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
scripts/checkpatch.pl

index 862cc7a740e23dfa59c7fe3187b5f4452b26d6f0..f354ae619da06df0242c32a45380e105fe061343 100755 (executable)
@@ -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,})/) {