serial: embed the rx buffer in struct serial_dev_priv
authorRasmus Villemoes <ravi@prevas.dk>
Thu, 3 Oct 2024 14:10:29 +0000 (16:10 +0200)
committerTom Rini <trini@konsulko.com>
Wed, 16 Oct 2024 21:54:31 +0000 (15:54 -0600)
The initialization of upriv->buf doesn't check for a NULL return. But
there's actually no point in doing a separate, unconditional malloc()
in post_probe; we can just make serial_dev_priv contain the rx buffer
itself, and let the (larger) allocation be handled by the driver core
when it allocates the ->per_device_auto. The total run-time memory
used is mostly the same, we reduce the code size a little, and as a
bonus, struct serial_dev_priv does not contain the unused members when
!SERIAL_RX_BUFFER.

Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/serial/serial-uclass.c
include/serial.h

index 484f0f7..d737e25 100644 (file)
@@ -588,11 +588,6 @@ static int serial_post_probe(struct udevice *dev)
        sdev.getc = serial_stub_getc;
        sdev.tstc = serial_stub_tstc;
 
-#if CONFIG_IS_ENABLED(SERIAL_RX_BUFFER)
-       /* Allocate the RX buffer */
-       upriv->buf = malloc(CONFIG_SERIAL_RX_BUFFER_SIZE);
-#endif
-
        stdio_register_dev(&sdev, &upriv->sdev);
 #endif
        return 0;
index 1456323..eabc49f 100644 (file)
@@ -298,9 +298,11 @@ struct dm_serial_ops {
 struct serial_dev_priv {
        struct stdio_dev *sdev;
 
-       char *buf;
+#if CONFIG_IS_ENABLED(SERIAL_RX_BUFFER)
+       char buf[CONFIG_SERIAL_RX_BUFFER_SIZE];
        uint rd_ptr;
        uint wr_ptr;
+#endif
 };
 
 /* Access the serial operations for a device */