From: Jiri Slaby <jirislaby@kernel.org>
To: "Gustavo A. R. Silva" <gustavoars@kernel.org>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
linux-hardening@vger.kernel.org
Subject: Re: [PATCH v3][next] tty: tty_buffer: Avoid hundreds of -Wflex-array-member-not-at-end warnings
Date: Thu, 6 Feb 2025 10:12:21 +0100 [thread overview]
Message-ID: <daea13b0-137c-4ab5-8388-1d46919b8609@kernel.org> (raw)
In-Reply-To: <Z6QvAZxiQusdaDkH@kspp>
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@linuxfoundation.org>
> Signed-off-by: Gustavo A. R. Silva <gustavoars@kernel.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
next prev parent reply other threads:[~2025-02-06 9:12 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-02-06 3:39 [PATCH v3][next] tty: tty_buffer: Avoid hundreds of -Wflex-array-member-not-at-end warnings Gustavo A. R. Silva
2025-02-06 4:40 ` Greg Kroah-Hartman
2025-02-06 23:23 ` Gustavo A. R. Silva
2025-02-07 9:38 ` Greg Kroah-Hartman
2025-02-06 9:12 ` Jiri Slaby [this message]
2025-02-06 9:23 ` Gustavo A. R. Silva
2025-02-11 7:02 ` Gustavo A. R. Silva
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=daea13b0-137c-4ab5-8388-1d46919b8609@kernel.org \
--to=jirislaby@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=gustavoars@kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-serial@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox