]> git.ipfire.org Git - thirdparty/linux.git/commit
compiler_types.h: Attributes: Add __counted_by_ptr macro
authorBill Wendling <morbo@google.com>
Fri, 16 Jan 2026 00:57:57 +0000 (00:57 +0000)
committerKees Cook <kees@kernel.org>
Sat, 17 Jan 2026 19:00:28 +0000 (11:00 -0800)
commit150a04d817d8f5be5a4f92799827cdc8d7e45989
tree2551fa6089849d2f48cd9fc99563c7237e9c2d67
parent9f54ab83cb2a17071be70a80b94db6c36e597696
compiler_types.h: Attributes: Add __counted_by_ptr macro

Introduce __counted_by_ptr(), which works like __counted_by(), but for
pointer struct members.

struct foo {
int a, b, c;
char *buffer __counted_by_ptr(bytes);
short nr_bars;
struct bar *bars __counted_by_ptr(nr_bars);
size_t bytes;
};

Because "counted_by" can only be applied to pointer members in very
recent compiler versions, its application ends up needing to be distinct
from flexibe array "counted_by" annotations, hence a separate macro.

This is a reworking of Kees' previous patch [1].

Link: https://lore.kernel.org/all/20251020220118.1226740-1-kees@kernel.org/
Co-developed-by: Kees Cook <kees@kernel.org>
Signed-off-by: Bill Wendling <morbo@google.com>
Link: https://patch.msgid.link/20260116005838.2419118-1-morbo@google.com
Signed-off-by: Kees Cook <kees@kernel.org>
Makefile
include/linux/compiler_types.h
include/uapi/linux/stddef.h
init/Kconfig