mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Prakruthi Deepak Heragu <pheragu@codeaurora.org>, apw@canonical.com
Cc: linux-kernel@vger.kernel.org, ckadabi@codeaurora.org,
	bryanh@codeaurora.org, tsoni@codeaurora.org,
	Patrick Pannuto <ppannuto@codeaurora.org>,
	Stepan Moskovchenko <stepanm@codeaurora.org>
Subject: Re: [PATCH v1] checkpatch: Check for invalid return codes
Date: Tue, 03 Jul 2018 18:40:54 -0700	[thread overview]
Message-ID: <907f271cbeabec61b796ed220d425eb2ce2499db.camel@perches.com> (raw)
In-Reply-To: <1530661305-11959-1-git-send-email-pheragu@codeaurora.org>

On Tue, 2018-07-03 at 16:41 -0700, Prakruthi Deepak Heragu wrote:
> The only valid integer return is 0, anything else
> following "return" should be -ERRCODE or a function.

Integer return values can be positive constant and correct.

So perhaps better:

Negative integer return codes should prefer to use #define -<ERRNO>
values instead of negative numbers.

> Also, display context
> so that the user knows where the return value is incorrect.
> 
> 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.

This bit is superfluous and if you are going to quote
someone in a patch commit, it's nice to cc: them.

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

Does it really take 3 people to sign-off on this patch?

> ---
> Changes in v1:
> - Use CHK instead of ERROR
> - Rephrase the warning message
> - Provide the file name and line number where return value is incorrect
> 
>  scripts/checkpatch.pl | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/scripts/checkpatch.pl b/scripts/checkpatch.pl
> index a9c0550..2808c27 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+/) {
> +			CHK("NO_ERROR_CODE",

NO_ERROR_CODE isn't very obvious to me.
How about NEGATIVE_ERRNO or APPROPRIATE_ERRNO

> +			      "invalid return value, please return -<APPROPRIATE_ERRNO>\n" . $herecurr);
> +		}
> +
>  # check for gcc specific __FUNCTION__
>  		if ($line =~ /\b__FUNCTION__\b/) {
>  			if (WARN("USE_FUNC",

      reply	other threads:[~2018-07-04  1:41 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-03 23:41 Prakruthi Deepak Heragu
2018-07-04  1:40 ` Joe Perches [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=907f271cbeabec61b796ed220d425eb2ce2499db.camel@perches.com \
    --to=joe@perches.com \
    --cc=apw@canonical.com \
    --cc=bryanh@codeaurora.org \
    --cc=ckadabi@codeaurora.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pheragu@codeaurora.org \
    --cc=ppannuto@codeaurora.org \
    --cc=stepanm@codeaurora.org \
    --cc=tsoni@codeaurora.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®