* [PATCH] err.h: add __must_check to error pointer handlers
@ 2010-03-12 13:45 Jani Nikula
2010-03-12 18:40 ` Alexey Dobriyan
0 siblings, 1 reply; 3+ messages in thread
From: Jani Nikula @ 2010-03-12 13:45 UTC (permalink / raw)
To: akpm; +Cc: linux-kernel, ext-phil.2.carmody, ext-jani.1.nikula
Add __must_check to error pointer handlers to have the compiler warn
about mistakes like:
if (err)
ERR_PTR(err);
Signed-off-by: Jani Nikula <ext-jani.1.nikula@nokia.com>
---
include/linux/err.h | 10 +++++-----
1 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/include/linux/err.h b/include/linux/err.h
index 1b12642..448afc1 100644
--- a/include/linux/err.h
+++ b/include/linux/err.h
@@ -19,22 +19,22 @@
#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
-static inline void *ERR_PTR(long error)
+static inline void * __must_check ERR_PTR(long error)
{
return (void *) error;
}
-static inline long PTR_ERR(const void *ptr)
+static inline long __must_check PTR_ERR(const void *ptr)
{
return (long) ptr;
}
-static inline long IS_ERR(const void *ptr)
+static inline long __must_check IS_ERR(const void *ptr)
{
return IS_ERR_VALUE((unsigned long)ptr);
}
-static inline long IS_ERR_OR_NULL(const void *ptr)
+static inline long __must_check IS_ERR_OR_NULL(const void *ptr)
{
return !ptr || IS_ERR_VALUE((unsigned long)ptr);
}
@@ -46,7 +46,7 @@ static inline long IS_ERR_OR_NULL(const void *ptr)
* Explicitly cast an error-valued pointer to another pointer type in such a
* way as to make it clear that's what's going on.
*/
-static inline void *ERR_CAST(const void *ptr)
+static inline void * __must_check ERR_CAST(const void *ptr)
{
/* cast away the const */
return (void *) ptr;
--
1.6.5.2
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] err.h: add __must_check to error pointer handlers
2010-03-12 13:45 [PATCH] err.h: add __must_check to error pointer handlers Jani Nikula
@ 2010-03-12 18:40 ` Alexey Dobriyan
2010-03-12 19:45 ` Phil Carmody
0 siblings, 1 reply; 3+ messages in thread
From: Alexey Dobriyan @ 2010-03-12 18:40 UTC (permalink / raw)
To: Jani Nikula; +Cc: akpm, linux-kernel, ext-phil.2.carmody
On Fri, Mar 12, 2010 at 03:45:40PM +0200, Jani Nikula wrote:
> Add __must_check to error pointer handlers to have the compiler warn
> about mistakes like:
>
> if (err)
> ERR_PTR(err);
> -static inline void *ERR_PTR(long error)
> +static inline void * __must_check ERR_PTR(long error)
We had bugs like that?
Pretty much every non-void function should be marked then.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] err.h: add __must_check to error pointer handlers
2010-03-12 18:40 ` Alexey Dobriyan
@ 2010-03-12 19:45 ` Phil Carmody
0 siblings, 0 replies; 3+ messages in thread
From: Phil Carmody @ 2010-03-12 19:45 UTC (permalink / raw)
To: ext Alexey Dobriyan; +Cc: Nikula Jani.1 (EXT-Nixu/Helsinki), akpm, linux-kernel
On 12/03/10 19:40 +0100, ext Alexey Dobriyan wrote:
> On Fri, Mar 12, 2010 at 03:45:40PM +0200, Jani Nikula wrote:
> > Add __must_check to error pointer handlers to have the compiler warn
> > about mistakes like:
> >
> > if (err)
> > ERR_PTR(err);
>
> > -static inline void *ERR_PTR(long error)
> > +static inline void * __must_check ERR_PTR(long error)
>
> We had bugs like that?
Two popped out immediately. Patches have been sent to appropriate
maintainers. Grepping my inbox:
Mar 12 Nikula Jani [PATCH] enclosure: fix error path - actually return ERR_PTR() on error
Mar 12 Nikula Jani [PATCH] sunrpc: fix error path - actually return ERR_PTR() on error
There's a slim chance that there may be others (grep doesn't find any
more obvious ones), but as allmodconfig seems broken currently, there
may be others which are as yet undiscovered.
> Pretty much every non-void function should be marked then.
All functions where it makes no sense ignore the return value. You
really wouldn't be doing an ERR_PTR unless you wanted to use the result.
Note that __must_check doesn't actually require 'checking', merely
'using' the return value, which includes just storing it in a variable,
and then later ignoring it.
An alternative static code analysis method could be used to detect such
things. Coverity Prevent uses a heuristic algorithm to detect missing
checks of return values using a popularity contest. Most people check
it - then everyone should probably check it.
Phil
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2010-03-12 19:45 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-03-12 13:45 [PATCH] err.h: add __must_check to error pointer handlers Jani Nikula
2010-03-12 18:40 ` Alexey Dobriyan
2010-03-12 19:45 ` Phil Carmody
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome