1*4882a593Smuzhiyun #ifndef _LINUX_ERR_H 2*4882a593Smuzhiyun #define _LINUX_ERR_H 3*4882a593Smuzhiyun 4*4882a593Smuzhiyun #include <linux/compiler.h> 5*4882a593Smuzhiyun #include <linux/compat.h> 6*4882a593Smuzhiyun 7*4882a593Smuzhiyun #include <linux/errno.h> 8*4882a593Smuzhiyun 9*4882a593Smuzhiyun 10*4882a593Smuzhiyun /* 11*4882a593Smuzhiyun * Kernel pointers have redundant information, so we can use a 12*4882a593Smuzhiyun * scheme where we can return either an error code or a dentry 13*4882a593Smuzhiyun * pointer with the same return value. 14*4882a593Smuzhiyun * 15*4882a593Smuzhiyun * This should be a per-architecture thing, to allow different 16*4882a593Smuzhiyun * error and pointer decisions. 17*4882a593Smuzhiyun */ 18*4882a593Smuzhiyun #define MAX_ERRNO 4095 19*4882a593Smuzhiyun 20*4882a593Smuzhiyun #ifndef __ASSEMBLY__ 21*4882a593Smuzhiyun 22*4882a593Smuzhiyun #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) 23*4882a593Smuzhiyun ERR_PTR(long error)24*4882a593Smuzhiyunstatic inline void *ERR_PTR(long error) 25*4882a593Smuzhiyun { 26*4882a593Smuzhiyun return (void *) error; 27*4882a593Smuzhiyun } 28*4882a593Smuzhiyun PTR_ERR(const void * ptr)29*4882a593Smuzhiyunstatic inline long PTR_ERR(const void *ptr) 30*4882a593Smuzhiyun { 31*4882a593Smuzhiyun return (long) ptr; 32*4882a593Smuzhiyun } 33*4882a593Smuzhiyun IS_ERR(const void * ptr)34*4882a593Smuzhiyunstatic inline long IS_ERR(const void *ptr) 35*4882a593Smuzhiyun { 36*4882a593Smuzhiyun return IS_ERR_VALUE((unsigned long)ptr); 37*4882a593Smuzhiyun } 38*4882a593Smuzhiyun IS_ERR_OR_NULL(const void * ptr)39*4882a593Smuzhiyunstatic inline bool IS_ERR_OR_NULL(const void *ptr) 40*4882a593Smuzhiyun { 41*4882a593Smuzhiyun return !ptr || IS_ERR_VALUE((unsigned long)ptr); 42*4882a593Smuzhiyun } 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun /** 45*4882a593Smuzhiyun * ERR_CAST - Explicitly cast an error-valued pointer to another pointer type 46*4882a593Smuzhiyun * @ptr: The pointer to cast. 47*4882a593Smuzhiyun * 48*4882a593Smuzhiyun * Explicitly cast an error-valued pointer to another pointer type in such a 49*4882a593Smuzhiyun * way as to make it clear that's what's going on. 50*4882a593Smuzhiyun */ ERR_CAST(__force const void * ptr)51*4882a593Smuzhiyunstatic inline void * __must_check ERR_CAST(__force const void *ptr) 52*4882a593Smuzhiyun { 53*4882a593Smuzhiyun /* cast away the const */ 54*4882a593Smuzhiyun return (void *) ptr; 55*4882a593Smuzhiyun } 56*4882a593Smuzhiyun 57*4882a593Smuzhiyun #endif 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun #endif /* _LINUX_ERR_H */ 60