summaryrefslogtreecommitdiff
path: root/include/linux/typecheck.h
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2016-12-28 00:36:01 +0900
committerTom Rini <trini@konsulko.com>2017-01-14 16:46:29 -0500
commitff90af6c73883121358251bba66245ff4da3755c (patch)
treeb529b70b7ded25b775a0affbbedbe5220872e13c /include/linux/typecheck.h
parenta7b817699985b515b63a601b317e3e8fd413d7e9 (diff)
typecheck: import include/linux/typecheck.h from Linux 4.9
Copied from Linux 4.9. Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'include/linux/typecheck.h')
-rw-r--r--include/linux/typecheck.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/include/linux/typecheck.h b/include/linux/typecheck.h
new file mode 100644
index 0000000000..eb5b74a575
--- /dev/null
+++ b/include/linux/typecheck.h
@@ -0,0 +1,24 @@
+#ifndef TYPECHECK_H_INCLUDED
+#define TYPECHECK_H_INCLUDED
+
+/*
+ * Check at compile time that something is of a particular type.
+ * Always evaluates to 1 so you may use it easily in comparisons.
+ */
+#define typecheck(type,x) \
+({ type __dummy; \
+ typeof(x) __dummy2; \
+ (void)(&__dummy == &__dummy2); \
+ 1; \
+})
+
+/*
+ * Check at compile time that 'function' is a certain type, or is a pointer
+ * to that type (needs to use typedef for the function type.)
+ */
+#define typecheck_fn(type,function) \
+({ typeof(type) __tmp = function; \
+ (void)__tmp; \
+})
+
+#endif /* TYPECHECK_H_INCLUDED */