linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RFC] err.h: document that PTR_ERR should only be used if IS_ERR returns true
@ 2018-10-14 20:28 Uwe Kleine-König
  2018-10-15  9:37 ` Alessandro Rubini
  0 siblings, 1 reply; 6+ messages in thread
From: Uwe Kleine-König @ 2018-10-14 20:28 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Alessandro Rubini, Jonathan Corbet
  Cc: linux-kernel, Thierry Reding, Vokáč Michal,
	Andrew Morton, kernel

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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-10-16 20:10 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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).