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