public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Rasmus Villemoes <ravi@prevas.dk>
To: u-boot@lists.denx.de
Cc: Stefan Roese <sr@denx.de>, Tom Rini <trini@konsulko.com>,
	Rasmus Villemoes <ravi@prevas.dk>
Subject: [PATCH 4/4] serial: embed the rx buffer in struct serial_dev_priv
Date: Thu,  3 Oct 2024 16:10:29 +0200	[thread overview]
Message-ID: <20241003141029.920035-5-ravi@prevas.dk> (raw)
In-Reply-To: <20241003141029.920035-1-ravi@prevas.dk>

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>
---
 drivers/serial/serial-uclass.c | 5 -----
 include/serial.h               | 4 +++-
 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 */
-- 
2.46.2


  parent reply	other threads:[~2024-10-03 14:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-10-03 14:10 [PATCH 0/4] some serial rx buffer patches Rasmus Villemoes
2024-10-03 14:10 ` [PATCH 1/4] serial: fix circular rx buffer edge case Rasmus Villemoes
2024-10-09  1:51   ` Simon Glass
2024-10-09 11:03     ` Rasmus Villemoes
2024-10-17 23:23       ` Simon Glass
2024-10-03 14:10 ` [PATCH 2/4] serial: do not overwrite not-consumed characters in rx buffer Rasmus Villemoes
2024-10-09  1:51   ` Simon Glass
2024-10-03 14:10 ` [PATCH 3/4] serial: add build-time sanity check of CONFIG_SERIAL_RX_BUFFER_SIZE Rasmus Villemoes
2024-10-09  1:51   ` Simon Glass
2024-10-03 14:10 ` Rasmus Villemoes [this message]
2024-10-09  1:51   ` [PATCH 4/4] serial: embed the rx buffer in struct serial_dev_priv Simon Glass
2024-10-17  2:22 ` [PATCH 0/4] some serial rx buffer patches Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20241003141029.920035-5-ravi@prevas.dk \
    --to=ravi@prevas.dk \
    --cc=sr@denx.de \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox