aboutsummaryrefslogtreecommitdiffstats
path: root/xen/include/xen/err.h
diff options
context:
space:
mode:
authorJan Beulich <jbeulich@suse.com>2012-09-03 09:40:38 +0200
committerJan Beulich <jbeulich@suse.com>2012-09-03 09:40:38 +0200
commit8e66050e3223a9aa55ca29ec32b2e78c3e69e085 (patch)
tree22bf4997c2366565228de8bb0a31c0eaf4873be5 /xen/include/xen/err.h
parentf1297904185f73262522b6277252bfb699644766 (diff)
downloadxen-8e66050e3223a9aa55ca29ec32b2e78c3e69e085.tar.gz
xen-8e66050e3223a9aa55ca29ec32b2e78c3e69e085.tar.bz2
xen-8e66050e3223a9aa55ca29ec32b2e78c3e69e085.zip
make domain_create() return a proper error code
While triggered by the XSA-9 fix, this really is of more general use; that fix just pointed out very sharply that the current situation with all domain creation failures reported to user (tools) space as -ENOMEM is very unfortunate (actively misleading users _and_ support personnel). Pull over the pointer <-> error code conversion infrastructure from Linux, and use it in domain_create() and all it callers. Signed-off-by: Jan Beulich <jbeulich@suse.com> Acked-by: Keir Fraser <keir@xen.org>
Diffstat (limited to 'xen/include/xen/err.h')
-rw-r--r--xen/include/xen/err.h57
1 files changed, 57 insertions, 0 deletions
diff --git a/xen/include/xen/err.h b/xen/include/xen/err.h
new file mode 100644
index 0000000000..2f29b57d28
--- /dev/null
+++ b/xen/include/xen/err.h
@@ -0,0 +1,57 @@
+#if !defined(__XEN_ERR_H__) && !defined(__ASSEMBLY__)
+#define __XEN_ERR_H__
+
+#include <xen/compiler.h>
+#include <xen/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 could be a per-architecture thing, to allow different
+ * error and pointer decisions.
+ */
+#define MAX_ERRNO 4095
+
+#define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
+
+static inline void *__must_check ERR_PTR(long error)
+{
+ return (void *)error;
+}
+
+static inline long __must_check PTR_ERR(const void *ptr)
+{
+ return (long)ptr;
+}
+
+static inline long __must_check IS_ERR(const void *ptr)
+{
+ return IS_ERR_VALUE((unsigned long)ptr);
+}
+
+static inline long __must_check IS_ERR_OR_NULL(const void *ptr)
+{
+ return !ptr || IS_ERR_VALUE((unsigned long)ptr);
+}
+
+/**
+ * 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.
+ */
+static inline void * __must_check ERR_CAST(const void *ptr)
+{
+ /* cast away the const */
+ return (void *)ptr;
+}
+
+static inline int __must_check PTR_RET(const void *ptr)
+{
+ return IS_ERR(ptr) ? PTR_ERR(ptr) : 0;
+}
+
+#endif /* __XEN_ERR_H__ */