From: Joe Perches <joe@perches.com>
To: pheragu@codeaurora.org
Cc: apw@canonical.com, linux-kernel@vger.kernel.org,
ckadabi@codeaurora.org, tsoni@codeaurora.org,
bryanh@codeaurora.org, Patrick Pannuto <ppannuto@codeaurora.org>,
Stepan Moskovchenko <stepanm@codeaurora.org>
Subject: Re: [PATCH] checkpatch: Check for illegal return codes
Date: Tue, 03 Jul 2018 12:37:24 -0700 [thread overview]
Message-ID: <4c9b77cb32c022c93851e8a812e4c076dfd30e5f.camel@perches.com> (raw)
In-Reply-To: <f6498bb90c5da1ea1765412bd78071a7@codeaurora.org>
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>'"
prev parent reply other threads:[~2018-07-03 19:37 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-03 18:09 Prakruthi Deepak Heragu
2018-07-03 18:19 ` Joe Perches
2018-07-03 19:07 ` pheragu
2018-07-03 19:37 ` 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=4c9b77cb32c022c93851e8a812e4c076dfd30e5f.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®