public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] checkpatch: Check for illegal return codes
@ 2018-07-03 18:09 Prakruthi Deepak Heragu
  2018-07-03 18:19 ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Prakruthi Deepak Heragu @ 2018-07-03 18:09 UTC (permalink / raw)
  To: apw, joe
  Cc: linux-kernel, ckadabi, tsoni, bryanh, Patrick Pannuto,
	Stepan Moskovchenko, Prakruthi Deepak Heragu

The only legal integer return is 0, anything else
following "return" should be -ERRCODE or a function.

http://lkml.org/lkml/2010/7/23/318
  There's lots of "return -1;" statements in this patch - it's obscene
  that this is used to indicate "some error occurred" in kernel space
  rather than a real errno value - even when an existing function
  (eg, request_irq) gave you an error code already.

Signed-off-by: Patrick Pannuto <ppannuto@codeaurora.org>
Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
Signed-off-by: Prakruthi Deepak Heragu <pheragu@codeaurora.org>
---
 scripts/checkpatch.pl | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
index a9c0550..260d252 100755
--- a/scripts/checkpatch.pl
+++ b/scripts/checkpatch.pl
@@ -6197,6 +6197,12 @@ sub process {
 			     "switch default: should use break\n" . $herectx);
 		}
 
+# check for return codes on error paths
+		if ($line =~ /\breturn\s+-\d+/) {
+			ERROR("NO_ERROR_CODE",
+			      "illegal return value, please use an error code");
+		}
+
 # check for gcc specific __FUNCTION__
 		if ($line =~ /\b__FUNCTION__\b/) {
 			if (WARN("USE_FUNC",
-- 
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project


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

* Re: [PATCH] checkpatch: Check for illegal return codes
  2018-07-03 18:09 [PATCH] checkpatch: Check for illegal return codes Prakruthi Deepak Heragu
@ 2018-07-03 18:19 ` Joe Perches
  2018-07-03 19:07   ` pheragu
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2018-07-03 18:19 UTC (permalink / raw)
  To: Prakruthi Deepak Heragu, apw
  Cc: linux-kernel, ckadabi, tsoni, bryanh, Patrick Pannuto,
	Stepan Moskovchenko

On Tue, 2018-07-03 at 11:09 -0700, Prakruthi Deepak Heragu wrote:
> The only legal integer return is 0, anything else
> following "return" should be -ERRCODE or a function.
> 
> http://lkml.org/lkml/2010/7/23/318
>   There's lots of "return -1;" statements in this patch - it's obscene
>   that this is used to indicate "some error occurred" in kernel space
>   rather than a real errno value - even when an existing function
>   (eg, request_irq) gave you an error code already.
> 
> Signed-off-by: Patrick Pannuto <ppannuto@codeaurora.org>
> Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
> Signed-off-by: Prakruthi Deepak Heragu <pheragu@codeaurora.org>
> ---
>  scripts/checkpatch.pl | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index a9c0550..260d252 100755
> --- a/scripts/checkpatch.pl
> +++ b/scripts/checkpatch.pl
> @@ -6197,6 +6197,12 @@ sub process {
>  			     "switch default: should use break\n" . $herectx);
>  		}
>  
> +# check for return codes on error paths
> +		if ($line =~ /\breturn\s+-\d+/) {
> +			ERROR("NO_ERROR_CODE",
> +			      "illegal return value, please use an error code");
> +		}
> +

Substitute illegal to invalid as this wouldn't be illegal.
It might be invalid and this needs a newline and $herecurr

I'm not sure this is even useful.

There are _way_ too many of these already existing
and simple return identifiers can be OK.

$ git grep -P '\breturn\s*\-(?!0)\d+' | wc -l
10193

and

$ git grep -P '\breturn\s*\-(?!1)\d+' | wc -l
240


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

* Re: [PATCH] checkpatch: Check for illegal return codes
  2018-07-03 18:19 ` Joe Perches
@ 2018-07-03 19:07   ` pheragu
  2018-07-03 19:37     ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: pheragu @ 2018-07-03 19:07 UTC (permalink / raw)
  To: Joe Perches
  Cc: apw, linux-kernel, ckadabi, tsoni, bryanh, Patrick Pannuto,
	Stepan Moskovchenko

On 2018-07-03 11:19, Joe Perches wrote:
> On Tue, 2018-07-03 at 11:09 -0700, Prakruthi Deepak Heragu wrote:
>> The only legal integer return is 0, anything else
>> following "return" should be -ERRCODE or a function.
>> 
>> http://lkml.org/lkml/2010/7/23/318
>>   There's lots of "return -1;" statements in this patch - it's obscene
>>   that this is used to indicate "some error occurred" in kernel space
>>   rather than a real errno value - even when an existing function
>>   (eg, request_irq) gave you an error code already.
>> 
>> Signed-off-by: Patrick Pannuto <ppannuto@codeaurora.org>
>> Signed-off-by: Stepan Moskovchenko <stepanm@codeaurora.org>
>> Signed-off-by: Prakruthi Deepak Heragu <pheragu@codeaurora.org>
>> ---
>>  scripts/checkpatch.pl | 6 ++++++
>>  1 file changed, 6 insertions(+)
>> 
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index a9c0550..260d252 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -6197,6 +6197,12 @@ sub process {
>>  			     "switch default: should use break\n" . $herectx);
>>  		}
>> 
>> +# check for return codes on error paths
>> +		if ($line =~ /\breturn\s+-\d+/) {
>> +			ERROR("NO_ERROR_CODE",
>> +			      "illegal return value, please use an error code");
>> +		}
>> +
> 
> Substitute illegal to invalid as this wouldn't be illegal.
> It might be invalid and this needs a newline and $herecurr
> 
> I'm not sure this is even useful.
> 
> There are _way_ too many of these already existing
> and simple return identifiers can be OK.
> 
> $ git grep -P '\breturn\s*\-(?!0)\d+' | wc -l
> 10193
> 
> and
> 
> $ git grep -P '\breturn\s*\-(?!1)\d+' | wc -l
> 240
True. However, this would be helpful to avoid usage of such return 
statements in the future.

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

* Re: [PATCH] checkpatch: Check for illegal return codes
  2018-07-03 19:07   ` pheragu
@ 2018-07-03 19:37     ` Joe Perches
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2018-07-03 19:37 UTC (permalink / raw)
  To: pheragu
  Cc: apw, linux-kernel, ckadabi, tsoni, bryanh, Patrick Pannuto,
	Stepan Moskovchenko

On Tue, 2018-07-03 at 12:07 -0700, pheragu@codeaurora.org wrote:
> On 2018-07-03 11:19, Joe Perches wrote:
> > On Tue, 2018-07-03 at 11:09 -0700, Prakruthi Deepak Heragu wrote:
> > > The only legal integer return is 0, anything else
> > > following "return" should be -ERRCODE or a function.
> > > 
> > > http://lkml.org/lkml/2010/7/23/318
> > >   There's lots of "return -1;" statements in this patch - it's obscene
> > >   that this is used to indicate "some error occurred" in kernel space
> > >   rather than a real errno value - even when an existing function
> > >   (eg, request_irq) gave you an error code already.
[]
> > > diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
[]
> > @@ -6197,6 +6197,12 @@ sub process {
> > >  			     "switch default: should use break\n" . $herectx);
> > >  		}
> > > 
> > > +# check for return codes on error paths
> > > +		if ($line =~ /\breturn\s+-\d+/) {
> > > +			ERROR("NO_ERROR_CODE",
> > > +			      "illegal return value, please use an error code");
> > > +		}
> > > +
> > 
> > Substitute illegal to invalid as this wouldn't be illegal.
> > It might be invalid and this needs a newline and $herecurr
> > 
> > I'm not sure this is even useful.
> > 
> > There are _way_ too many of these already existing
> > and simple return identifiers can be OK.
> > 
> > $ git grep -P '\breturn\s*\-(?!0)\d+' | wc -l
> > 10193
> > 
> > and
> > 
> > $ git grep -P '\breturn\s*\-(?!1)\d+' | wc -l
> > 240
> 
> True. However, this would be helpful to avoid usage of such return 
> statements in the future.

Maybe use CHK and not ERROR and maybe the output message
could be something like "Prefer 'return -<APPROPRIATE_ERRNO>'"


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

end of thread, other threads:[~2018-07-03 19:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-07-03 18:09 [PATCH] checkpatch: Check for illegal return codes Prakruthi Deepak Heragu
2018-07-03 18:19 ` Joe Perches
2018-07-03 19:07   ` pheragu
2018-07-03 19:37     ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox