Skip to content

Commit 1c07c9b

Browse files
nathanchancekees
authored andcommitted
tty: mxser: Remove __counted_by from mxser_board.ports[]
Work for __counted_by on generic pointers in structures (not just flexible array members) has started landing in Clang 19 (current tip of tree). During the development of this feature, a restriction was added to __counted_by to prevent the flexible array member's element type from including a flexible array member itself such as: struct foo { int count; char buf[]; }; struct bar { int count; struct foo data[] __counted_by(count); }; because the size of data cannot be calculated with the standard array size formula: sizeof(struct foo) * count This restriction was downgraded to a warning but due to CONFIG_WERROR, it can still break the build. The application of __counted_by on the ports member of 'struct mxser_board' triggers this restriction, resulting in: drivers/tty/mxser.c:291:2: error: 'counted_by' should not be applied to an array with element of unknown size because 'struct mxser_port' is a struct type with a flexible array member. This will be an error in a future compiler version [-Werror,-Wbounds-safety-counted-by-elt-type-unknown-size] 291 | struct mxser_port ports[] __counted_by(nports); | ^~~~~~~~~~~~~~~~~~~~~~~~~ 1 error generated. Remove this use of __counted_by to fix the warning/error. However, rather than remove it altogether, leave it commented, as it may be possible to support this in future compiler releases. Cc: <[email protected]> Closes: ClangBuiltLinux#2026 Fixes: f34907e ("mxser: Annotate struct mxser_board with __counted_by") Signed-off-by: Nathan Chancellor <[email protected]> Link: https://lore.kernel.org/r/20240529-drop-counted-by-ports-mxser-board-v1-1-0ab217f4da6d@kernel.org Signed-off-by: Kees Cook <[email protected]>
1 parent 6db1208 commit 1c07c9b

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

drivers/tty/mxser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ struct mxser_board {
288288
enum mxser_must_hwid must_hwid;
289289
speed_t max_baud;
290290

291-
struct mxser_port ports[] __counted_by(nports);
291+
struct mxser_port ports[] /* __counted_by(nports) */;
292292
};
293293

294294
static DECLARE_BITMAP(mxser_boards, MXSER_BOARDS);

0 commit comments

Comments
 (0)