[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <daea13b0-137c-4ab5-8388-1d46919b8609@kernel.org>
Date: Thu, 6 Feb 2025 10:12:21 +0100
From: Jiri Slaby <jirislaby@...nel.org>
To: "Gustavo A. R. Silva" <gustavoars@...nel.org>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>
Cc: linux-kernel@...r.kernel.org, linux-serial@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH v3][next] tty: tty_buffer: Avoid hundreds of
-Wflex-array-member-not-at-end warnings
On 06. 02. 25, 4:39, Gustavo A. R. Silva wrote:
> Currently, member `sentinel` in `struct tty_bufhead` is causing trouble
> becase its type is `struct tty_buffer`, which is a flexible structure
> --meaning it contains a flexible-array member. This combined with the
> fact that `sentinel` is positioned in the middle of `struct tty_bufhead`,
THUMBS_UP
> Suggested-by: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@...nel.org>
> ---
> Changes in v3:
> - Implement `struct tty_buffer_hdr` as a separate struct and embed it
> into `struct tty_buffer`. Refactor the rest of the code, accordingly.
Better, but:
> diff --git a/drivers/tty/tty_buffer.c b/drivers/tty/tty_buffer.c
> index 79f0ff94ce00..cd04a6567a33 100644
> --- a/drivers/tty/tty_buffer.c
> +++ b/drivers/tty/tty_buffer.c
...
> @@ -576,11 +579,14 @@ int tty_insert_flip_string_and_push_buffer(struct tty_port *port,
> void tty_buffer_init(struct tty_port *port)
> {
> struct tty_bufhead *buf = &port->buf;
> + struct tty_buffer *buf_sentinel;
> +
> + buf_sentinel = container_of(&buf->sentinel, struct tty_buffer, hdr);
Bah, so this is ugly and even dangerous if someone adds a member to
tty_buffer outside _hdr.
We should link headers in the list, it appears.
> --- a/include/linux/tty_buffer.h
> +++ b/include/linux/tty_buffer.h
> @@ -7,7 +7,7 @@
> #include <linux/mutex.h>
> #include <linux/workqueue.h>
>
> -struct tty_buffer {
> +struct tty_buffer_hdr {
> union {
> struct tty_buffer *next;
> struct llist_node free;
> @@ -15,9 +15,13 @@ struct tty_buffer {
> unsigned int used;
> unsigned int size;
> unsigned int commit;
> - unsigned int lookahead; /* Lazy update on recv, can become less than "read" */
> + unsigned int lookahead; /* Lazy update on recv, can become less than "read" */
This is an unrelated/unwanted change.
thanks,
--
js
suse labs
Powered by blists - more mailing lists