Rusty Russell | 61d0b5a | 2013-03-18 13:22:19 +1030 | [diff] [blame] | 1 | #ifndef ERR_H |
| 2 | #define ERR_H |
| 3 | #define MAX_ERRNO 4095 |
| 4 | |
| 5 | #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) |
| 6 | |
| 7 | static inline void * __must_check ERR_PTR(long error) |
| 8 | { |
| 9 | return (void *) error; |
| 10 | } |
| 11 | |
| 12 | static inline long __must_check PTR_ERR(const void *ptr) |
| 13 | { |
| 14 | return (long) ptr; |
| 15 | } |
| 16 | |
| 17 | static inline long __must_check IS_ERR(const void *ptr) |
| 18 | { |
| 19 | return IS_ERR_VALUE((unsigned long)ptr); |
| 20 | } |
| 21 | |
| 22 | static inline long __must_check IS_ERR_OR_NULL(const void *ptr) |
| 23 | { |
| 24 | return !ptr || IS_ERR_VALUE((unsigned long)ptr); |
| 25 | } |
| 26 | #endif /* ERR_H */ |