xref: /openbsd/sys/dev/pci/drm/include/linux/err.h (revision a24c48f0)
1 /* Public domain. */
2 
3 #ifndef _LINUX_ERR_H
4 #define _LINUX_ERR_H
5 
6 #include <sys/errno.h>
7 #include <linux/compiler.h>
8 
9 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-ELAST)
10 
11 static inline void *
ERR_PTR(long error)12 ERR_PTR(long error)
13 {
14 	return (void *) error;
15 }
16 
17 static inline long
PTR_ERR(const void * ptr)18 PTR_ERR(const void *ptr)
19 {
20 	return (long) ptr;
21 }
22 
23 static inline bool
IS_ERR(const void * ptr)24 IS_ERR(const void *ptr)
25 {
26         return IS_ERR_VALUE((unsigned long)ptr);
27 }
28 
29 static inline bool
IS_ERR_OR_NULL(const void * ptr)30 IS_ERR_OR_NULL(const void *ptr)
31 {
32         return !ptr || IS_ERR_VALUE((unsigned long)ptr);
33 }
34 
35 static inline void *
ERR_CAST(const void * ptr)36 ERR_CAST(const void *ptr)
37 {
38 	return (void *)ptr;
39 }
40 
41 static inline int
PTR_ERR_OR_ZERO(const void * ptr)42 PTR_ERR_OR_ZERO(const void *ptr)
43 {
44 	return IS_ERR(ptr)? PTR_ERR(ptr) : 0;
45 }
46 
47 #endif
48