
On Wed, Mar 16, 2022 at 01:23:38PM -0600, Simon Glass wrote:
Hi,
On Wed, 16 Mar 2022 at 09:41, Pierre-Clément Tosi ptosi@google.com wrote:
Upgrade the header to version 5.16 of the kernel:
commit df0cc57e057f18e44dac8e6c18aba47ab53202f9
Signed-off-by: Pierre-Clément Tosi ptosi@google.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
include/linux/typecheck.h | 10 ++++++++++ 1 file changed, 10 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
But I don't understand how this works at all. Could you add a comment?
This patch is a simple upgrade of the header. I needed it for another patch stack and, given how trivial and self-contained it is, I thought I would slip it into this one.
If your "this" refers to the macro itself, an error should be generated by the compiler when dereferencing a non-pointer and it avoids introducing side effects through the use of __dummy but I'm not sure what the sizeof is there for; is it perhaps compliant for an implementation to keep generating code when encountering a dereferenced non-pointer (leading to a bogus result, from UB) so that sizeof forces it to depend on that expression being of a valid type? Or is it to do with catching variables of incomplete type e.g. arrays of unknown size? It was introduced by commit cb0f80039fb7 ("bitops: Add non-atomic bitops for pointers"), which doesn't provide much information either.
diff --git a/include/linux/typecheck.h b/include/linux/typecheck.h index eb5b74a575..46b15e2aae 100644 --- a/include/linux/typecheck.h +++ b/include/linux/typecheck.h @@ -1,3 +1,4 @@ +/* SPDX-License-Identifier: GPL-2.0 */ #ifndef TYPECHECK_H_INCLUDED #define TYPECHECK_H_INCLUDED
@@ -21,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 */
2.35.1.723.g4982287a31-goog
Regards, Simon