err.h 1.1 KB

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