xref: /aosp_15_r20/external/bpftool/include/linux/err.h (revision 858ea5e570667251cdc31d3fe7b846b591105938)
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 
3 #ifndef __LINUX_ERR_H
4 #define __LINUX_ERR_H
5 
6 #include <linux/types.h>
7 #include <asm/errno.h>
8 
9 #define MAX_ERRNO       4095
10 
11 #define IS_ERR_VALUE(x) ((x) >= (unsigned long)-MAX_ERRNO)
12 
ERR_PTR(long error_)13 static inline void * ERR_PTR(long error_)
14 {
15 	return (void *) error_;
16 }
17 
PTR_ERR(const void * ptr)18 static inline long PTR_ERR(const void *ptr)
19 {
20 	return (long) ptr;
21 }
22 
IS_ERR(const void * ptr)23 static inline bool IS_ERR(const void *ptr)
24 {
25 	return IS_ERR_VALUE((unsigned long)ptr);
26 }
27 
IS_ERR_OR_NULL(const void * ptr)28 static inline bool IS_ERR_OR_NULL(const void *ptr)
29 {
30 	return (!ptr) || IS_ERR_VALUE((unsigned long)ptr);
31 }
32 
33 #endif
34