err.h 564 B

123456789101112131415161718192021222324252627
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef ERR_H
  3. #define ERR_H
  4. #define MAX_ERRNO 4095
  5. #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
  6. static inline void * __must_check ERR_PTR(long error)
  7. {
  8. return (void *) error;
  9. }
  10. static inline long __must_check PTR_ERR(const void *ptr)
  11. {
  12. return (long) ptr;
  13. }
  14. static inline long __must_check IS_ERR(const void *ptr)
  15. {
  16. return IS_ERR_VALUE((unsigned long)ptr);
  17. }
  18. static inline long __must_check IS_ERR_OR_NULL(const void *ptr)
  19. {
  20. return !ptr || IS_ERR_VALUE((unsigned long)ptr);
  21. }
  22. #endif /* ERR_H */