Blame view

include/linux/err.h 1.35 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
  #ifndef _LINUX_ERR_H
  #define _LINUX_ERR_H
  
  #include <linux/compiler.h>
  
  #include <asm/errno.h>
  
  /*
   * Kernel pointers have redundant information, so we can use a
   * scheme where we can return either an error code or a dentry
   * pointer with the same return value.
   *
   * This should be a per-architecture thing, to allow different
   * error and pointer decisions.
   */
fa79837d5   Ralf Baechle   [PATCH] Fix IS_ER...
16
  #define MAX_ERRNO	4095
ebba5f9fc   Randy Dunlap   [PATCH] consisten...
17
  #ifndef __ASSEMBLY__
fa79837d5   Ralf Baechle   [PATCH] Fix IS_ER...
18
  #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
07ab67c8d   Linus Torvalds   Fix get_unmapped_...
19

e47103b1a   Jani Nikula   err.h: add __must...
20
  static inline void * __must_check ERR_PTR(long error)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
21
22
23
  {
  	return (void *) error;
  }
e47103b1a   Jani Nikula   err.h: add __must...
24
  static inline long __must_check PTR_ERR(const void *ptr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
27
  {
  	return (long) ptr;
  }
e47103b1a   Jani Nikula   err.h: add __must...
28
  static inline long __must_check IS_ERR(const void *ptr)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
  {
07ab67c8d   Linus Torvalds   Fix get_unmapped_...
30
  	return IS_ERR_VALUE((unsigned long)ptr);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
  }
e47103b1a   Jani Nikula   err.h: add __must...
32
  static inline long __must_check IS_ERR_OR_NULL(const void *ptr)
603c4ba96   Phil Carmody   err.h: add helper...
33
34
35
  {
  	return !ptr || IS_ERR_VALUE((unsigned long)ptr);
  }
d1bc8e954   David Howells   Add an ERR_CAST()...
36
37
38
39
40
41
42
  /**
   * ERR_CAST - Explicitly cast an error-valued pointer to another pointer type
   * @ptr: The pointer to cast.
   *
   * Explicitly cast an error-valued pointer to another pointer type in such a
   * way as to make it clear that's what's going on.
   */
e47103b1a   Jani Nikula   err.h: add __must...
43
  static inline void * __must_check ERR_CAST(const void *ptr)
d1bc8e954   David Howells   Add an ERR_CAST()...
44
45
46
47
  {
  	/* cast away the const */
  	return (void *) ptr;
  }
fa9ee9c4b   Uwe Kleine-König   include/linux/err...
48
49
50
51
52
53
54
  static inline int __must_check PTR_RET(const void *ptr)
  {
  	if (IS_ERR(ptr))
  		return PTR_ERR(ptr);
  	else
  		return 0;
  }
ebba5f9fc   Randy Dunlap   [PATCH] consisten...
55
  #endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
56
  #endif /* _LINUX_ERR_H */