linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alessandro Rubini <rubini@gnudd.com>
To: u.kleine-koenig@pengutronix.de
Cc: viro@ZenIV.linux.org.uk, Michal.Vokac@ysoft.com, corbet@lwn.net,
	gregkh@linuxfoundation.org, linux-kernel@vger.kernel.org,
	thierry.reding@gmail.com, kernel@pengutronix.de,
	akpm@linux-foundation.org
Subject: Re: [PATCH RFC] err.h: document that PTR_ERR should only be used if IS_ERR returns true
Date: Tue, 16 Oct 2018 22:10:28 +0200	[thread overview]
Message-ID: <20181016201028.GA3257@mail.gnudd.com> (raw)
In-Reply-To: <20181016192928.pinjwxfors4reigh@pengutronix.de>

Me:
>> > OTOH I admit you can compare any value with -EINVAL, after PTR_ERR.
>> > But in general you first detect the error condition and then split
>> > among error (or print a message according to the exact value.

Al Viro:
>> 
>> 	if (IS_ERR(p) && PTR_ERR(p) == -ENOENT)
>> instead of
>> 	if (p == ERR_PTR(-ENOENT))
>> 
>> is ugly, obfuscating what's going on for no good reason and I'm going
>> to keep killing those every time I run into one...

Sure. I was talking about selecting among errors in the error path,
after you left the fast path jumping away with IS_ERR().

(in short, I agree).

Uwe kleine-koenig

> And what do you do if you see a
> 
> 	p = somefunc(...);
> 	if (PTR_ERR(p) == -ENOENT)
> 
> without first checking for IS_ERR(p)?

I see no problem. The original suggestion (only use if IS_ERR), which
was mine, refers to doing error management in error cases. Sure
if you know the return value is valid or -ENOENT you don't need to verify
it is negative before comparing with -2.

Both PTR_ERR and ERR_PTR are just a cast to prevent a warning
(and tell the reader that you convert from err to ptr or vv), so
I think the two are equivalent. Al's version above is maybe cleaner,
but we are bikeshedding, IMHO.

best
/alessandro

      parent reply	other threads:[~2018-10-16 20:10 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-14 20:28 [PATCH RFC] err.h: document that PTR_ERR should only be used if IS_ERR returns true Uwe Kleine-König
2018-10-15  9:37 ` Alessandro Rubini
2018-10-15  9:46   ` Uwe Kleine-König
2018-10-16 18:06   ` Al Viro
2018-10-16 19:29     ` Uwe Kleine-König
2018-10-16 20:10     ` Alessandro Rubini [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=20181016201028.GA3257@mail.gnudd.com \
    --to=rubini@gnudd.com \
    --cc=Michal.Vokac@ysoft.com \
    --cc=akpm@linux-foundation.org \
    --cc=corbet@lwn.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel@pengutronix.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=thierry.reding@gmail.com \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=viro@ZenIV.linux.org.uk \
    /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;
as well as URLs for NNTP newsgroup(s).