hv_drv_UsbErr.h 1.2 KB

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