lkml.org 
[lkml]   [2014]   [Sep]   [9]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
SubjectRe: [PATCH] scripts: checkpatch.pl add warning for dummy label
From
Date
On Tue, 2014-09-09 at 15:54 +0200, Nitin Kuppelur wrote:
> Added new warning DUMMY_LABEL in checkpatch.pl. This warns
> if return statement is encountered just after goto label target
> like "out:". In such scenario it is best to call "return;" directly
> instead of "goto out;"

I'm not sure this is desired/correct.

There are many functions written like:

return_type foo(...)
{
[some initialization...]

err = some_test(...);
if (err)
goto out;

[...]

out:
[some cleanup...]
return err;
}

In many cases, a void function is a simple
variant of a non-void function and many people
like to see the same code "shape" in functions,
just without the init and cleanup bits.

> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> @@ -3798,10 +3798,14 @@ sub process {
> if ($sline =~ /^[ \+]}\s*$/ &&
> $prevline =~ /^\+\treturn\s*;\s*$/ &&
> $linenr >= 3 &&
> - $lines[$linenr - 3] =~ /^[ +]/ &&
> - $lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
> - WARN("RETURN_VOID",
> - "void function return statements are not generally useful\n" . $hereprev);
> + $lines[$linenr - 3] =~ /^[ +]/) {
> + if ($lines[$linenr - 3] !~ /^[ +]\s*$Ident\s*:/) {
> + WARN("RETURN_VOID",
> + "void function return statements are not generally useful\n" . $hereprev);
> + } elsif ($lines[$linenr - 3] =~ /^[ +]\s*$Ident\s*:/) {
> + WARN("DUMMY_LABEL",
> + "labels doing nothing are not generally useful\n" . $hereprev);
> + }
> }
>
> # if statements using unnecessary parentheses - ie: if ((foo == bar))





\
 
 \ /
  Last update: 2014-09-09 18:21    [W:0.034 / U:0.200 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site