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