diff options
author | David Henningsson <david.henningsson@canonical.com> | 2014-09-23 09:04:50 +0200 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2014-09-23 09:43:57 +0200 |
commit | 35da2ccf5624ead46c1d6b85391b15dd4f44bb51 (patch) | |
tree | 971fa1b6cc3605572a1dd856c822a67f6d52f5f6 | |
parent | 0165d62d97d6863d7aea2cf7bb7f3bdb64839cb9 (diff) | |
download | hda-emu-35da2ccf5624ead46c1d6b85391b15dd4f44bb51.tar.gz |
add include/linux/err.h
We recently started using it on the kernel side.
Signed-off-by: David Henningsson <david.henningsson@canonical.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r-- | include/linux/err.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/include/linux/err.h b/include/linux/err.h new file mode 100644 index 0000000..627729d --- /dev/null +++ b/include/linux/err.h @@ -0,0 +1,64 @@ +#ifndef _LINUX_ERR_H +#define _LINUX_ERR_H + +/* + * Kernel pointers have redundant information, so we can use a + * scheme where we can return either an error code or a normal + * pointer with the same return value. + * + * This should be a per-architecture thing, to allow different + * error and pointer decisions. + */ +#define MAX_ERRNO 4095 + +#define __must_check +#define __force +#define unlikely(x) x + +#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) + +static inline void * __must_check ERR_PTR(long error) +{ + return (void *) error; +} + +static inline long __must_check PTR_ERR(__force const void *ptr) +{ + return (long) ptr; +} + +static inline bool __must_check IS_ERR(__force const void *ptr) +{ + return IS_ERR_VALUE((unsigned long)ptr); +} + +static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr) +{ + return !ptr || 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 * __must_check ERR_CAST(__force const void *ptr) +{ + /* cast away the const */ + return (void *) ptr; +} + +static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr) +{ + if (IS_ERR(ptr)) + return PTR_ERR(ptr); + else + return 0; +} + +/* Deprecated */ +#define PTR_RET(p) PTR_ERR_OR_ZERO(p) + +#endif /* _LINUX_ERR_H */ |