public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Nishanth Menon <nm@ti.com>
To: Joe Perches <joe@perches.com>, Andy Whitcroft <apw@canonical.com>
Cc: <linux-kernel@vger.kernel.org>, <afd@ti.com>,
	Andrew Morton <akpm@linux-foundation.org>
Subject: Re: [PATCH V2] checkpatch: Flag code that returns a negative number less than 1
Date: Fri, 3 Jun 2016 15:46:00 -0500	[thread overview]
Message-ID: <5751EC88.4020300@ti.com> (raw)
In-Reply-To: <1464986529.11800.24.camel@perches.com>

On 06/03/2016 03:42 PM, Joe Perches wrote:
> On Fri, 2016-06-03 at 15:02 -0500, Nishanth Menon wrote:
>> In some functions, returning a -ve decimal value is actually a valid
>> return condition when the function is returning a value, however, it
>> can also be misused for returning an error value that should ideally
>> be a valid error code defined in include/uapi/asm-generic/errno-base.h
>> or include/uapi/asm-generic/errno.h. The notable exception is "-1"
>> which has quiet a history of usage as pointed out by Joe Perches.
>>
>> Considering typical error of doing the following:
>> int fn(void)
>> {
>> 	/* ... error condition ... */
>> 	return -2;
>> }
>>
>> void fn1(void)
>> {
>> 	/* some code */
>> 	if (fn() < 0) {
>> 		pr_err("Error occurred\n");
>> 		return;
>> 	}
>> 	/* other cases... */
>> }
>>
>> Flag this as a check case for developer verification.
>>
>> The check is done for negative values less than 1 and tools
>> directory is exempt from this requirement based on Joe Perches'
>> suggestion.
>>
>> Suggested-by: Joe Perches <joe@perches.com>
> 
> No, I didn't suggest this.

Sorry, I had hoped to give you credit for the recommended regex
optimization and recommendations you gave.

> I'm not at all sure it's even a good idea.

OK. I can drop this if we'd not want to go down this road. we can
catch stuff in review as much as possible, I was hoping we can catch
the easy ones by forcing a relook by developers.

> 
>> Signed-off-by: Nishanth Menon <nm@ti.com>
>> ---
>> Changes in V2:
>> 	- change in regex for check for check for less than 1
>> 	- Update in commit message to the effect
>> 	- Added Suggested-by for Joe's recommendation on regex.
>>
>> V1: https://patchwork.kernel.org/patch/9153345/
>>
>>  scripts/checkpatch.pl | 6 ++++++
>>  1 file changed, 6 insertions(+)
>>
>> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
>> index 4904ced676d4..a2e677b5fd78 100755
>> --- a/scripts/checkpatch.pl
>> +++ b/scripts/checkpatch.pl
>> @@ -4351,6 +4351,12 @@ sub process {
>>  			}
>>  		}
>>  
>> +# return with a value is not usually a good sign, unless the function is supposed to return a value
>> +		if ($realfile !~ /^tools/ && defined($stat) && $stat =~ /^.\s*return\s*-\s*(?!1\b)\d+\s*;/s) {
> 
> I think
> 	if ($realfile != /^tools/ && $line =~ /\breturn\s*-\s*(?!1\b)\d+\s*;/
> would be better as it would catch return -2 in a macro or a
> multi-line statement like
> 	if (<foo>) return -2;
> 
Nice.

>> +			CHK("RETURN_NUMBER",
>> +			    "Suspect error return with a value, If this is error value, refer to include/uapi/asm-generic/errno-base.h  and include/uapi/asm-generic/errno.h\n" . $herecurr);
> 
> That's an awfully long message.
> 
> Maybe something like:
> 	"Perhaps better to use standard ERRNO system error symbols"
> 

Fair enough. Will hold off a respin based on direction we would like
to take.


-- 
Regards,
Nishanth Menon

      reply	other threads:[~2016-06-03 20:46 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-03 15:25 [PATCH] checkpatch: Flag code that returns a negative number Nishanth Menon
2016-06-03 15:41 ` Joe Perches
2016-06-03 15:49   ` Andrew F. Davis
2016-06-03 16:01     ` Joe Perches
2016-06-03 16:07       ` Nishanth Menon
2016-06-03 16:16         ` Joe Perches
2016-06-03 20:02 ` [PATCH V2] checkpatch: Flag code that returns a negative number less than 1 Nishanth Menon
2016-06-03 20:42   ` Joe Perches
2016-06-03 20:46     ` Nishanth Menon [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=5751EC88.4020300@ti.com \
    --to=nm@ti.com \
    --cc=afd@ti.com \
    --cc=akpm@linux-foundation.org \
    --cc=apw@canonical.com \
    --cc=joe@perches.com \
    --cc=linux-kernel@vger.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