mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Nitin Kuppelur <nitinkuppelur@gmail.com>
To: Joe Perches <joe@perches.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 17:08:21 +0200	[thread overview]
Message-ID: <540F17E5.1020701@gmail.com> (raw)
In-Reply-To: <1410277380.12560.38.camel@joe-AO725>

Hi Joe,

Thanks for feedback.

The idea of adding new warning came from the review comments from
one of my PATCH, where it was suggested by few reviewers to remove such
"Do-Nothing" labels. But current checkpatch.pl does not warn about that.

[PATCH]
http://www.mail-archive.com/linux-kernel@vger.kernel.org/msg720639.html


Regards,
Nitin

On 09/09/2014 05:43 PM, Joe Perches wrote:
> 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))
> 
> 
> 

      reply	other threads:[~2014-09-09 16:41 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
2014-09-09 15:08   ` Nitin Kuppelur [this message]

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=540F17E5.1020701@gmail.com \
    --to=nitinkuppelur@gmail.com \
    --cc=akpm@linux-foundation.org \
    --cc=joe@perches.com \
    --cc=josh@joshtriplett.org \
    --cc=linux-kernel@vger.kernel.org \
    --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

Powered by JetHome