1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */ 261d0b5a4SRusty Russell #ifndef ERR_H 361d0b5a4SRusty Russell #define ERR_H 461d0b5a4SRusty Russell #define MAX_ERRNO 4095 561d0b5a4SRusty Russell 661d0b5a4SRusty Russell #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO) 761d0b5a4SRusty Russell ERR_PTR(long error)861d0b5a4SRusty Russellstatic inline void * __must_check ERR_PTR(long error) 961d0b5a4SRusty Russell { 1061d0b5a4SRusty Russell return (void *) error; 1161d0b5a4SRusty Russell } 1261d0b5a4SRusty Russell PTR_ERR(const void * ptr)1361d0b5a4SRusty Russellstatic inline long __must_check PTR_ERR(const void *ptr) 1461d0b5a4SRusty Russell { 1561d0b5a4SRusty Russell return (long) ptr; 1661d0b5a4SRusty Russell } 1761d0b5a4SRusty Russell IS_ERR(const void * ptr)1861d0b5a4SRusty Russellstatic inline long __must_check IS_ERR(const void *ptr) 1961d0b5a4SRusty Russell { 2061d0b5a4SRusty Russell return IS_ERR_VALUE((unsigned long)ptr); 2161d0b5a4SRusty Russell } 2261d0b5a4SRusty Russell IS_ERR_OR_NULL(const void * ptr)2361d0b5a4SRusty Russellstatic inline long __must_check IS_ERR_OR_NULL(const void *ptr) 2461d0b5a4SRusty Russell { 2561d0b5a4SRusty Russell return !ptr || IS_ERR_VALUE((unsigned long)ptr); 2661d0b5a4SRusty Russell } 2761d0b5a4SRusty Russell #endif /* ERR_H */ 28