All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] scripts: checkpatch.pl add warning for dummy label
@ 2014-09-09 13:54 Nitin Kuppelur
  2014-09-09 15:43 ` Joe Perches
  0 siblings, 1 reply; 3+ messages in thread
From: Nitin Kuppelur @ 2014-09-09 13:54 UTC (permalink / raw)
  To: akpm, joe, josh, robh; +Cc: linux-kernel, Nitin Kuppelur

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;"

Signed-off-by: Nitin Kuppelur <nitinkuppelur@gmail.com>
---
 scripts/checkpatch.pl | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index b602ed2..399c2b5 100755
--- 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))
-- 
1.9.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts: checkpatch.pl add warning for dummy label
  2014-09-09 15:43 ` Joe Perches
@ 2014-09-09 15:08   ` Nitin Kuppelur
  0 siblings, 0 replies; 3+ messages in thread
From: Nitin Kuppelur @ 2014-09-09 15:08 UTC (permalink / raw)
  To: Joe Perches; +Cc: akpm, josh, robh, linux-kernel

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))
> 
> 
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] scripts: checkpatch.pl add warning for dummy label
  2014-09-09 13:54 [PATCH] scripts: checkpatch.pl add warning for dummy label Nitin Kuppelur
@ 2014-09-09 15:43 ` Joe Perches
  2014-09-09 15:08   ` Nitin Kuppelur
  0 siblings, 1 reply; 3+ messages in thread
From: Joe Perches @ 2014-09-09 15:43 UTC (permalink / raw)
  To: Nitin Kuppelur; +Cc: akpm, josh, robh, linux-kernel

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))




^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-09-09 16:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-09 13:54 [PATCH] scripts: checkpatch.pl add warning for dummy label Nitin Kuppelur
2014-09-09 15:43 ` Joe Perches
2014-09-09 15:08   ` Nitin Kuppelur

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.