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 <gre...@linuxfoundation.org>
Signed-off-by: Gustavo A. R. Silva <gustavo...@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

Reply via email to