diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2008-08-11 09:59:01 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2008-08-13 16:41:22 +0200 |
commit | 8b9dd936e893901ef7fcb32a3936af6d9e0eb665 (patch) | |
tree | c5f263bcbcae3cb27d95f50c2ac7805fe39c1611 /include/linux | |
parent | 31cb2f0347e5484ae79d543dae6a887b6530bce6 (diff) | |
download | barebox-8b9dd936e893901ef7fcb32a3936af6d9e0eb665.tar.gz barebox-8b9dd936e893901ef7fcb32a3936af6d9e0eb665.tar.xz |
Add include/linux/err.h from Kernel
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/err.h | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/include/linux/err.h b/include/linux/err.h new file mode 100644 index 0000000000..e0d8d2d33a --- /dev/null +++ b/include/linux/err.h @@ -0,0 +1,52 @@ +#ifndef _LINUX_ERR_H +#define _LINUX_ERR_H + +#include <linux/compiler.h> + +#include <asm-generic/errno.h> + +/* + * Kernel pointers have redundant information, so we can use a + * scheme where we can return either an error code or a dentry + * pointer with the same return value. + * + * This should be a per-architecture thing, to allow different + * error and pointer decisions. + */ +#define MAX_ERRNO 4095 + +#ifndef __ASSEMBLY__ + +#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) + +static inline void *ERR_PTR(long error) +{ + return (void *) error; +} + +static inline long PTR_ERR(const void *ptr) +{ + return (long) ptr; +} + +static inline long IS_ERR(const void *ptr) +{ + return IS_ERR_VALUE((unsigned long)ptr); +} + +/** + * ERR_CAST - Explicitly cast an error-valued pointer to another pointer type + * @ptr: The pointer to cast. + * + * 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) +{ + /* cast away the const */ + return (void *) ptr; +} + +#endif + +#endif /* _LINUX_ERR_H */ |