err.h 1.1 KB

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