linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tty: mxser: Remove __counted_by from mxser_board.ports[]
@ 2024-05-29 21:29 Nathan Chancellor
  2024-05-30  6:22 ` Jiri Slaby
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Nathan Chancellor @ 2024-05-29 21:29 UTC (permalink / raw)
  To: Jiri Slaby, Greg Kroah-Hartman
  Cc: Kees Cook, Gustavo A. R. Silva, Bill Wendling, Justin Stitt,
	linux-serial, imx, linux-arm-kernel, linux-hardening, llvm,
	patches, stable, Nathan Chancellor

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: stable@vger.kernel.org
Closes: https://github.com/ClangBuiltLinux/linux/issues/2026
Fixes: f34907ecca71 ("mxser: Annotate struct mxser_board with __counted_by")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
 drivers/tty/mxser.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/mxser.c b/drivers/tty/mxser.c
index 458bb1280ebf..5b97e420a95f 100644
--- a/drivers/tty/mxser.c
+++ b/drivers/tty/mxser.c
@@ -288,7 +288,7 @@ struct mxser_board {
 	enum mxser_must_hwid must_hwid;
 	speed_t max_baud;
 
-	struct mxser_port ports[] __counted_by(nports);
+	struct mxser_port ports[] /* __counted_by(nports) */;
 };
 
 static DECLARE_BITMAP(mxser_boards, MXSER_BOARDS);

---
base-commit: 1613e604df0cd359cf2a7fbd9be7a0bcfacfabd0
change-id: 20240529-drop-counted-by-ports-mxser-board-ed2a66f1a6e2

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-06-28 15:59 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-29 21:29 [PATCH] tty: mxser: Remove __counted_by from mxser_board.ports[] Nathan Chancellor
2024-05-30  6:22 ` Jiri Slaby
2024-05-30  7:40   ` Greg Kroah-Hartman
2024-05-30  8:12     ` Gustavo A. R. Silva
2024-05-30  8:33       ` Jiri Slaby
2024-05-30  8:41         ` Jiri Slaby
2024-05-30  8:43           ` Bill Wendling
2024-05-30  8:46             ` Gustavo A. R. Silva
2024-06-03  6:07               ` Jiri Slaby
2024-06-03  8:26                 ` Gustavo A. R. Silva
2024-06-12 20:04                   ` Gustavo A. R. Silva
2024-05-30  8:42         ` Gustavo A. R. Silva
2024-05-30 17:43     ` Nathan Chancellor
2024-06-27 17:14 ` Kees Cook
2024-06-28  2:51   ` Gustavo A. R. Silva
2024-06-28 14:31   ` Greg Kroah-Hartman
2024-06-28 15:58 ` Kees Cook

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).