Messages in this thread Patch in this message | ![/](/images/icornerl.gif) | | From | Alexander Lobakin <> | Subject | [PATCH RFC kspp-next 1/3] compiler_types: add Endianness-dependent __counted_by_{le,be} | Date | Mon, 18 Mar 2024 14:03:52 +0100 |
| |
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 --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 -- 2.44.0
| ![\](/images/icornerr.gif) |