linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Uwe Kleine-König" <uwe@kleine-koenig.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Alessandro Rubini <rubini@gnudd.com>,
	Jonathan Corbet <corbet@lwn.net>
Cc: linux-kernel@vger.kernel.org,
	"Thierry Reding" <thierry.reding@gmail.com>,
	"Vokáč Michal" <Michal.Vokac@ysoft.com>,
	"Andrew Morton" <akpm@linux-foundation.org>,
	kernel@pengutronix.de
Subject: [PATCH RFC] err.h: document that PTR_ERR should only be used if IS_ERR returns true
Date: Sun, 14 Oct 2018 22:28:07 +0200	[thread overview]
Message-ID: <20181014202807.16412-1-uwe@kleine-koenig.org> (raw)

I have no idea about the rationale, but that's what LDD3 recommends.

Signed-off-by: Uwe Kleine-König <uwe@kleine-koenig.org>
---
Hello,

during a review I claimed that PTR_ERR should only be used if IS_ERR was
already checked. The rationale isn't obvious though and Thierry
suggested to keep the code as is and not introduce an IS_ERR check.

I found in Linux Device Drivers 3[1]:

	You should use PTR_ERR only on a value for which IS_ERR returns
	a true value; any other value is a valid pointer

I wonder if there is a relevant reason that LDD3 suggests to check
IS_ERR first, maybe something like "On an Alpha it is important because
not doing it results in a bus error there." There are no details
mentioned there however. If there is a reason, this patch should be
adapted such that the comment includes it.

Any ideas?

Best regards
Uwe

[1] https://static.lwn.net/images/pdf/LDD3/ch11.pdf, on page 295

 include/linux/err.h | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/include/linux/err.h b/include/linux/err.h
index 87be24350e91..8f052983108e 100644
--- a/include/linux/err.h
+++ b/include/linux/err.h
@@ -26,6 +26,9 @@ static inline void * __must_check ERR_PTR(long error)
 	return (void *) error;
 }
 
+/*
+ * You should use PTR_ERR only on a value for which IS_ERR returns a true value.
+ */
 static inline long __must_check PTR_ERR(__force const void *ptr)
 {
 	return (long) ptr;
-- 
2.19.1


             reply	other threads:[~2018-10-14 20:28 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-14 20:28 Uwe Kleine-König [this message]
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

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=20181014202807.16412-1-uwe@kleine-koenig.org \
    --to=uwe@kleine-koenig.org \
    --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=rubini@gnudd.com \
    --cc=thierry.reding@gmail.com \
    --subject='Re: [PATCH RFC] err.h: document that PTR_ERR should only be used if IS_ERR returns true' \
    /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

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