[PATCH 6/6] ERR_PTR: warn when ERR_PTR parameter is not errno value

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: LKML <linux-kernel@...>
Cc: Andrew Morton <akpm@...>, Al Viro <viro@...>, Christoph Hellwig <hch@...>
Date: Sunday, May 18, 2008 - 6:04 pm

Check at runtime whether error argument of ERR_PTR and ERR_OR_0_PTR
is valid. It can catch bugs which possibly lead to oops or panic earlier.

Currently there are > 600 calls of ERR_PTR with non-constant argument
in Linux kernel sources.

Signed-off-by: Marcin Slusarz <marcin.slusarz@gmail.com>
Cc: Andrew Morton <akpm@linux-foundation.org>
---
 include/linux/err.h |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/include/linux/err.h b/include/linux/err.h
index cdec8b6..51e2459 100644
--- a/include/linux/err.h
+++ b/include/linux/err.h
@@ -3,6 +3,7 @@
 
 #include <linux/compiler.h>
 
+#include <asm/bug.h>
 #include <asm/errno.h>
 
 /*
@@ -21,6 +22,7 @@
 
 static inline void *__ERR_PTR(long error)
 {
+	WARN_ON(!IS_ERR_VALUE(error));
 	return (void *) error;
 }
 
@@ -28,6 +30,7 @@ static inline void *__ERR_PTR(long error)
 
 static inline void *__ERR_OR_0_PTR(long error)
 {
+	WARN_ON(!IS_ERR_VALUE(error) && error);
 	return (void *) error;
 }
 
-- 
1.5.4.5

--
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[PATCH 6/6] ERR_PTR: warn when ERR_PTR parameter is not errn..., Marcin Slusarz, (Sun May 18, 6:04 pm)
[PATCH 5/6] vfs: fix ERR_PTR abuse in generic_readlink, Marcin Slusarz, (Sun May 18, 6:03 pm)
[PATCH 3/6] vfs: open_exec cleanup, Marcin Slusarz, (Sun May 18, 6:01 pm)
Re: [PATCH 3/6] vfs: open_exec cleanup, Christoph Hellwig, (Mon May 19, 1:53 am)
Re: [PATCH 3/6] vfs: open_exec cleanup, Marcin Slusarz, (Thu May 22, 11:57 am)
[PATCH 2/6] ERR_PTR: add ERR_OR_0_PTR, Marcin Slusarz, (Sun May 18, 6:01 pm)
Re: [PATCH 2/6] ERR_PTR: add ERR_OR_0_PTR, Christoph Hellwig, (Mon May 19, 1:55 am)
Re: [PATCH 2/6] ERR_PTR: add ERR_OR_0_PTR, Al Viro, (Mon May 19, 2:33 am)
Re: [PATCH 2/6] ERR_PTR: add ERR_OR_0_PTR, Johannes Weiner, (Sun May 18, 7:04 pm)
[PATCH 0/6] Sanity checks for ERR_PTR argument, Marcin Slusarz, (Sun May 18, 5:56 pm)