Commit | Line | Data |
---|---|---|
002fe734 JA |
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 | ||
14 | #define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO) | |
15 | ||
16 | static inline void *ERR_PTR(long error) | |
17 | { | |
18 | return (void *) error; | |
19 | } | |
20 | ||
21 | static inline long PTR_ERR(const void *ptr) | |
22 | { | |
23 | return (long) ptr; | |
24 | } | |
25 | ||
26 | static inline long IS_ERR(const void *ptr) | |
27 | { | |
28 | return IS_ERR_VALUE((unsigned long)ptr); | |
29 | } | |
30 | ||
31 | static inline long IS_ERR_OR_NULL(const void *ptr) | |
32 | { | |
33 | return !ptr || IS_ERR_VALUE((unsigned long)ptr); | |
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 |