hc
2024-10-22 8ac6c7a54ed1b98d142dce24b11c6de6a1e239a5
kernel/tools/include/linux/err.h
....@@ -20,7 +20,7 @@
2020 * Userspace note:
2121 * The same principle works for userspace, because 'error' pointers
2222 * fall down to the unused hole far from user space, as described
23
- * in Documentation/x86/x86_64/mm.txt for x86_64 arch:
23
+ * in Documentation/x86/x86_64/mm.rst for x86_64 arch:
2424 *
2525 * 0000000000000000 - 00007fffffffffff (=47 bits) user space, different per mm hole caused by [48:63] sign extension
2626 * ffffffffffe00000 - ffffffffffffffff (=2 MB) unused hole
....@@ -52,4 +52,24 @@
5252 return unlikely(!ptr) || IS_ERR_VALUE((unsigned long)ptr);
5353 }
5454
55
+static inline int __must_check PTR_ERR_OR_ZERO(__force const void *ptr)
56
+{
57
+ if (IS_ERR(ptr))
58
+ return PTR_ERR(ptr);
59
+ else
60
+ return 0;
61
+}
62
+
63
+/**
64
+ * ERR_CAST - Explicitly cast an error-valued pointer to another pointer type
65
+ * @ptr: The pointer to cast.
66
+ *
67
+ * Explicitly cast an error-valued pointer to another pointer type in such a
68
+ * way as to make it clear that's what's going on.
69
+ */
70
+static inline void * __must_check ERR_CAST(__force const void *ptr)
71
+{
72
+ /* cast away the const */
73
+ return (void *) ptr;
74
+}
5575 #endif /* _LINUX_ERR_H */