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