summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRasmus Villemoes <[email protected]>2024-10-03 16:10:29 +0200
committerTom Rini <[email protected]>2024-10-16 15:54:31 -0600
commit6cc6a2f6992ebe0c087a0da29d1ded3f8799d6ca (patch)
treef8f124b0e0c010d4c9c03587f12a921e6ddff6b6
parent32822982307d3f4288580fe2f3b25e5031900702 (diff)
serial: embed the rx buffer in struct serial_dev_priv
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 <[email protected]> Reviewed-by: Simon Glass <[email protected]>
-rw-r--r--drivers/serial/serial-uclass.c5
-rw-r--r--include/serial.h4
2 files changed, 3 insertions, 6 deletions
diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 484f0f7d3e8..d737e25223d 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -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;
diff --git a/include/serial.h b/include/serial.h
index 14563239b7d..eabc49f820f 100644
--- a/include/serial.h
+++ b/include/serial.h
@@ -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 */