From: Joe Perches <joe@perches.com>
To: Nitin Kuppelur <nitinkuppelur@gmail.com>
Cc: akpm@linux-foundation.org, josh@joshtriplett.org,
robh@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scripts: checkpatch.pl add warning for dummy label
Date: Tue, 09 Sep 2014 08:43:00 -0700 [thread overview]
Message-ID: <1410277380.12560.38.camel@joe-AO725> (raw)
In-Reply-To: <1410270855-6639-1-git-send-email-nitinkuppelur@gmail.com>
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))
next prev parent reply other threads:[~2014-09-09 15:43 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-09 13:54 Nitin Kuppelur
2014-09-09 15:43 ` Joe Perches [this message]
2014-09-09 15:08 ` Nitin Kuppelur
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1410277380.12560.38.camel@joe-AO725 \
--to=joe@perches.com \
--cc=akpm@linux-foundation.org \
--cc=josh@joshtriplett.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nitinkuppelur@gmail.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®