aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/include/linux/typecheck.h
diff options
context:
space:
mode:
authorKumar Kartikeya Dwivedi <memxor@gmail.com>2021-07-02 16:48:22 +0530
committerAlexei Starovoitov <ast@kernel.org>2021-07-07 20:01:45 -0700
commitcb0f80039fb7ec9981a74d22019daaa85ff51a3d (patch)
tree4a723ac4dfa94fb5af8474bb084e9f997559d805 /include/linux/typecheck.h
parentnet: core: Split out code to run generic XDP prog (diff)
downloadwireguard-linux-cb0f80039fb7ec9981a74d22019daaa85ff51a3d.tar.xz
wireguard-linux-cb0f80039fb7ec9981a74d22019daaa85ff51a3d.zip
bitops: Add non-atomic bitops for pointers
cpumap needs to set, clear, and test the lowest bit in skb pointer in various places. To make these checks less noisy, add pointer friendly bitop macros that also do some typechecking to sanitize the argument. These wrap the non-atomic bitops __set_bit, __clear_bit, and test_bit but for pointer arguments. Pointer's address has to be passed in and it is treated as an unsigned long *, since width and representation of pointer and unsigned long match on targets Linux supports. They are prefixed with double underscore to indicate lack of atomicity. Signed-off-by: Kumar Kartikeya Dwivedi <memxor@gmail.com> Signed-off-by: Alexei Starovoitov <ast@kernel.org> Reviewed-by: Toke Høiland-Jørgensen <toke@redhat.com> Link: https://lore.kernel.org/bpf/20210702111825.491065-3-memxor@gmail.com
Diffstat (limited to 'include/linux/typecheck.h')
-rw-r--r--include/linux/typecheck.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/include/linux/typecheck.h b/include/linux/typecheck.h
index 20d310331eb5..46b15e2aaefb 100644
--- a/include/linux/typecheck.h
+++ b/include/linux/typecheck.h
@@ -22,4 +22,13 @@
(void)__tmp; \
})
+/*
+ * Check at compile time that something is a pointer type.
+ */
+#define typecheck_pointer(x) \
+({ typeof(x) __dummy; \
+ (void)sizeof(*__dummy); \
+ 1; \
+})
+
#endif /* TYPECHECK_H_INCLUDED */