]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
tty: tty_buffer: use struct_size() in tty_buffer_alloc()
authorJiri Slaby (SUSE) <jirislaby@kernel.org>
Wed, 16 Aug 2023 10:55:22 +0000 (12:55 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Tue, 22 Aug 2023 12:58:15 +0000 (14:58 +0200)
Now, that tty_buffer::data has the right type, use struct_size() for
size calculation. struct_size() makes the code less error-prone and more
readable.

Signed-off-by: "Jiri Slaby (SUSE)" <jirislaby@kernel.org>
Link: https://lore.kernel.org/r/20230816105530.3335-3-jirislaby@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/tty/tty_buffer.c

index 684d099cbe111f98cf5a6a0d0a4f2cd11d54d9f8..c94df1a2d7f884892bb117c202716d7895046374 100644 (file)
@@ -177,8 +177,7 @@ static struct tty_buffer *tty_buffer_alloc(struct tty_port *port, size_t size)
         */
        if (atomic_read(&port->buf.mem_used) > port->buf.mem_limit)
                return NULL;
-       p = kmalloc(sizeof(struct tty_buffer) + 2 * size,
-                   GFP_ATOMIC | __GFP_NOWARN);
+       p = kmalloc(struct_size(p, data, 2 * size), GFP_ATOMIC | __GFP_NOWARN);
        if (p == NULL)
                return NULL;