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 3/4] serial: add build-time sanity check of CONFIG_SERIAL_RX_BUFFER_SIZE
Date: Thu,  3 Oct 2024 16:10:28 +0200	[thread overview]
Message-ID: <20241003141029.920035-4-ravi@prevas.dk> (raw)
In-Reply-To: <20241003141029.920035-1-ravi@prevas.dk>

The help text says it must be a power of 2, and the implementation
does rely on that. Enforce it.

A violation gives a wall of text, but the last few lines should be
reasonably obvious:

drivers/serial/serial-uclass.c:334:9: note: in expansion of macro ‘BUILD_BUG_ON_NOT_POWER_OF_2’
  334 |         BUILD_BUG_ON_NOT_POWER_OF_2(CONFIG_SERIAL_RX_BUFFER_SIZE);

Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
---
 drivers/serial/serial-uclass.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/serial/serial-uclass.c b/drivers/serial/serial-uclass.c
index 28d7a202afc..484f0f7d3e8 100644
--- a/drivers/serial/serial-uclass.c
+++ b/drivers/serial/serial-uclass.c
@@ -18,6 +18,7 @@
 #include <dm/lists.h>
 #include <dm/device-internal.h>
 #include <dm/of_access.h>
+#include <linux/build_bug.h>
 #include <linux/delay.h>
 
 DECLARE_GLOBAL_DATA_PTR;
@@ -330,6 +331,8 @@ static int _serial_tstc(struct udevice *dev)
 	struct serial_dev_priv *upriv = dev_get_uclass_priv(dev);
 	uint wr, avail;
 
+	BUILD_BUG_ON_NOT_POWER_OF_2(CONFIG_SERIAL_RX_BUFFER_SIZE);
+
 	/* Read all available chars into the RX buffer while there's room */
 	avail = CONFIG_SERIAL_RX_BUFFER_SIZE - (upriv->wr_ptr - upriv->rd_ptr);
 	while (avail-- && __serial_tstc(dev)) {
-- 
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 ` Rasmus Villemoes [this message]
2024-10-09  1:51   ` [PATCH 3/4] serial: add build-time sanity check of CONFIG_SERIAL_RX_BUFFER_SIZE Simon Glass
2024-10-03 14:10 ` [PATCH 4/4] serial: embed the rx buffer in struct serial_dev_priv Rasmus Villemoes
2024-10-09  1:51   ` 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-4-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