0001
0002 #ifndef _LINUX_ERR_H
0003 #define _LINUX_ERR_H
0004
0005 #include <linux/compiler.h>
0006 #include <linux/types.h>
0007
0008 #include <asm/errno.h>
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #define MAX_ERRNO 4095
0019
0020 #ifndef __ASSEMBLY__
0021
0022 #define IS_ERR_VALUE(x) unlikely((unsigned long)(void *)(x) >= (unsigned long)-MAX_ERRNO)
0023
0024 static inline void * __must_check ERR_PTR(long error)
0025 {
0026 return (void *) error;
0027 }
0028
0029 static inline long __must_check PTR_ERR(__force const void *ptr)
0030 {
0031 return (long) ptr;
0032 }
0033
0034 static inline bool __must_check IS_ERR(__force const void *ptr)
0035 {
0036 return IS_ERR_VALUE((unsigned long)ptr);
0037 }
0038
0039 static inline bool __must_check IS_ERR_OR_NULL(__force const void *ptr)
0040 {
0041 return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr);
0042 }
0043
0044
0045
0046
0047
0048
0049
0050
0051 static inline void * __must_check ERR_CAST(__force const void *ptr)
0052 {
0053
0054 return (void *) ptr;
0055 }
0056
0057 static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
0058 {
0059 if (IS_ERR(ptr))
0060 return PTR_ERR(ptr);
0061 else
0062 return 0;
0063 }
0064
0065 #endif
0066
0067 #endif