tty: hvc_console: use flexible array for outbuf
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Tue, 21 Nov 2023 09:22:52 +0000 (10:22 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 25 Nov 2023 07:23:17 +0000 (07:23 +0000)
This means:
* move outbuf to the end of struct hvc_struct and convert from pointer
  to flexible array (the structure is smaller now)
* use struct_size() at the allocation site
* align outbuf in the struct instead of ALIGN() at kzalloc()

And apart from the above, use u8 instead of char (which are the same
thanks to -funsigned-char). The former is now preferred over the latter.

It makes the code easier to understand.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org
Link: https://lore.kernel.org/r/20231121092258.9334-12-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/hvc/hvc_console.c
drivers/tty/hvc/hvc_console.h

index 57f5c37125e63f36b44c19f32e796b6dd0b38415..cd1f657f782df218b12e315dd3fdab79474d2bec 100644 (file)
@@ -922,8 +922,7 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
                        return ERR_PTR(err);
        }
 
-       hp = kzalloc(ALIGN(sizeof(*hp), sizeof(long)) + outbuf_size,
-                       GFP_KERNEL);
+       hp = kzalloc(struct_size(hp, outbuf, outbuf_size), GFP_KERNEL);
        if (!hp)
                return ERR_PTR(-ENOMEM);
 
@@ -931,7 +930,6 @@ struct hvc_struct *hvc_alloc(uint32_t vtermno, int data,
        hp->data = data;
        hp->ops = ops;
        hp->outbuf_size = outbuf_size;
-       hp->outbuf = &((char *)hp)[ALIGN(sizeof(*hp), sizeof(long))];
 
        tty_port_init(&hp->port);
        hp->port.ops = &hvc_port_ops;
index 78f7543511f105fc4300f0411b40ba30467a844d..4062f8ad84df3817989b9f1234eb4e5db3e47043 100644 (file)
@@ -37,7 +37,6 @@ struct hvc_struct {
        spinlock_t lock;
        int index;
        int do_wakeup;
-       char *outbuf;
        int outbuf_size;
        int n_outbuf;
        uint32_t vtermno;
@@ -48,6 +47,7 @@ struct hvc_struct {
        struct work_struct tty_resize;
        struct list_head next;
        unsigned long flags;
+       u8 outbuf[] __aligned(sizeof(long));
 };
 
 /* implemented by a low level driver */