Skip to content

Commit

Permalink
err.h: add __must_check to error pointer handlers
Browse files Browse the repository at this point in the history
Add __must_check to error pointer handlers to have the compiler warn about
mistakes like:

	if (err)
		ERR_PTR(err);

It found two bugs:

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

Signed-off-by: Jani Nikula <ext-jani.1.nikula@nokia.com>
Cc: Phil Carmody <ext-phil.2.carmody@nokia.com>
Cc: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
  • Loading branch information
Jani Nikula authored and Linus Torvalds committed May 25, 2010
1 parent 1f85f87 commit e47103b
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions include/linux/err.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down

0 comments on commit e47103b

Please sign in to comment.