diff mbox series

[RFC,kspp-next,1/3] compiler_types: add Endianness-dependent __counted_by_{le,be}

Message ID 20240318130354.2713265-2-aleksander.lobakin@intel.com (mailing list archive)
State Superseded
Headers show
Series compiler_types: add Endianness-dependent __counted_by_{le,be} | expand

Commit Message

Alexander Lobakin March 18, 2024, 1:03 p.m. UTC
Some structures contain flexible arrays at the end and the counter for
them, but the counter has explicit Endianness and thus __counted_by()
can't be used directly.
To increase test coverage for potential problems without breaking
anything, introduce __counted_by_{le,be} defined depending on platform's
Endianness to either __counted_by() when applicable or noop otherwise.
Maybe it would be a good idea to introduce such attributes on compiler
level if possible, but for now let's stop on what we have.

Signed-off-by: Alexander Lobakin <aleksander.lobakin@intel.com>
---
 include/linux/compiler_types.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/include/linux/compiler_types.h b/include/linux/compiler_types.h
index 3e64ec0f7ac8..9506efbf2b8c 100644
--- a/include/linux/compiler_types.h
+++ b/include/linux/compiler_types.h
@@ -242,6 +242,17 @@  struct ftrace_likely_data {
  */
 #define noinline_for_stack noinline
 
+/*
+ * Apply __counted_by() when the Endianness matches to increase test coverage.
+ */
+#ifdef __LITTLE_ENDIAN
+#define __counted_by_le(member)	__counted_by(member)
+#define __counted_by_be(member)
+#else
+#define __counted_by_le(member)
+#define __counted_by_be(member)	__counted_by(member)
+#endif
+
 /*
  * Sanitizer helper attributes: Because using __always_inline and
  * __no_sanitize_* conflict, provide helper attributes that will either expand