Jens Axboe | 002fe73 | 2014-02-11 08:31:13 -0700 | [diff] [blame] | 1 | #ifndef FIO_ERR_H |
| 2 | #define FIO_ERR_H |
| 3 | |
| 4 | /* |
| 5 | * Kernel pointers have redundant information, so we can use a |
| 6 | * scheme where we can return either an error code or a dentry |
| 7 | * pointer with the same return value. |
| 8 | * |
| 9 | * This should be a per-architecture thing, to allow different |
| 10 | * error and pointer decisions. |
| 11 | */ |
| 12 | #define MAX_ERRNO 4095 |
| 13 | |
Jens Axboe | e0739a7 | 2014-02-12 08:22:01 -0700 | [diff] [blame] | 14 | #define IS_ERR_VALUE(x) ((x) >= (uintptr_t)-MAX_ERRNO) |
Jens Axboe | 002fe73 | 2014-02-11 08:31:13 -0700 | [diff] [blame] | 15 | |
Jens Axboe | e0739a7 | 2014-02-12 08:22:01 -0700 | [diff] [blame] | 16 | static inline void *ERR_PTR(uintptr_t error) |
Jens Axboe | 002fe73 | 2014-02-11 08:31:13 -0700 | [diff] [blame] | 17 | { |
| 18 | return (void *) error; |
| 19 | } |
| 20 | |
Jens Axboe | e0739a7 | 2014-02-12 08:22:01 -0700 | [diff] [blame] | 21 | static inline uintptr_t PTR_ERR(const void *ptr) |
Jens Axboe | 002fe73 | 2014-02-11 08:31:13 -0700 | [diff] [blame] | 22 | { |
Jens Axboe | e0739a7 | 2014-02-12 08:22:01 -0700 | [diff] [blame] | 23 | return (uintptr_t) ptr; |
Jens Axboe | 002fe73 | 2014-02-11 08:31:13 -0700 | [diff] [blame] | 24 | } |
| 25 | |
Jens Axboe | e0739a7 | 2014-02-12 08:22:01 -0700 | [diff] [blame] | 26 | static inline uintptr_t IS_ERR(const void *ptr) |
Jens Axboe | 002fe73 | 2014-02-11 08:31:13 -0700 | [diff] [blame] | 27 | { |
Jens Axboe | e0739a7 | 2014-02-12 08:22:01 -0700 | [diff] [blame] | 28 | return IS_ERR_VALUE((uintptr_t)ptr); |
Jens Axboe | 002fe73 | 2014-02-11 08:31:13 -0700 | [diff] [blame] | 29 | } |
| 30 | |
Jens Axboe | e0739a7 | 2014-02-12 08:22:01 -0700 | [diff] [blame] | 31 | static inline uintptr_t IS_ERR_OR_NULL(const void *ptr) |
Jens Axboe | 002fe73 | 2014-02-11 08:31:13 -0700 | [diff] [blame] | 32 | { |
Jens Axboe | e0739a7 | 2014-02-12 08:22:01 -0700 | [diff] [blame] | 33 | return !ptr || IS_ERR_VALUE((uintptr_t)ptr); |
Jens Axboe | 002fe73 | 2014-02-11 08:31:13 -0700 | [diff] [blame] | 34 | } |
| 35 | |
| 36 | static inline int PTR_ERR_OR_ZERO(const void *ptr) |
| 37 | { |
| 38 | if (IS_ERR(ptr)) |
| 39 | return PTR_ERR(ptr); |
| 40 | else |
| 41 | return 0; |
| 42 | } |
| 43 | |
| 44 | #endif |