Linux Serial subsystem development
 help / color / mirror / Atom feed
From: Hugo Villeneuve <hugo@hugovil.com>
To: gregkh@linuxfoundation.org, jirislaby@kernel.org,
	hvilleneuve@dimonoff.com
Cc: linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org,
	hugo@hugovil.com
Subject: [PATCH 5/7] serial: sc16is7xx: improve sc16is7xx_regmap_name() buffer size computation
Date: Thu, 30 Nov 2023 14:10:47 -0500	[thread overview]
Message-ID: <20231130191050.3165862-6-hugo@hugovil.com> (raw)
In-Reply-To: <20231130191050.3165862-1-hugo@hugovil.com>

From: Hugo Villeneuve <hvilleneuve@dimonoff.com>

Define macro for regmap port name suffix and use it in addition to
SC16IS7XX_MAX_PORTS to automatically compute the required buffer size to
hold the name.

This helps with code readability by making it more obvious what is the
required size of the buffer.

Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
---
 drivers/tty/serial/sc16is7xx.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/tty/serial/sc16is7xx.c b/drivers/tty/serial/sc16is7xx.c
index 750c55b93f5e..b02e6c79da67 100644
--- a/drivers/tty/serial/sc16is7xx.c
+++ b/drivers/tty/serial/sc16is7xx.c
@@ -20,6 +20,7 @@
 #include <linux/regmap.h>
 #include <linux/serial_core.h>
 #include <linux/serial.h>
+#include <linux/stringify.h>
 #include <linux/tty.h>
 #include <linux/tty_flip.h>
 #include <linux/spi/spi.h>
@@ -27,6 +28,7 @@
 #include <uapi/linux/sched/types.h>
 
 #define SC16IS7XX_NAME			"sc16is7xx"
+#define SC16IS7XX_PORT_NAME_SUFFIX	"port" /* Used for regmap name. */
 #define SC16IS7XX_MAX_DEVS		8
 #define SC16IS7XX_MAX_PORTS		2 /* Maximum number of UART ports per IC. */
 
@@ -1700,9 +1702,9 @@ static struct regmap_config regcfg = {
 
 static const char *sc16is7xx_regmap_name(unsigned int port_id)
 {
-	static char buf[6];
+	static char buf[sizeof(SC16IS7XX_PORT_NAME_SUFFIX __stringify(SC16IS7XX_MAX_PORTS))];
 
-	snprintf(buf, sizeof(buf), "port%u", port_id);
+	snprintf(buf, sizeof(buf), SC16IS7XX_PORT_NAME_SUFFIX "%u", port_id);
 
 	return buf;
 }
-- 
2.39.2


  parent reply	other threads:[~2023-11-30 19:11 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-30 19:10 [PATCH 0/7] serial: sc16is7xx and max310x: regmap fixes and improvements Hugo Villeneuve
2023-11-30 19:10 ` [PATCH 1/7] serial: sc16is7xx: fix snprintf format specifier in sc16is7xx_regmap_name() Hugo Villeneuve
2023-12-06  6:29   ` kernel test robot
2023-12-07 17:52     ` Hugo Villeneuve
2023-12-07 18:24       ` Andy Shevchenko
2023-12-07 19:02         ` Hugo Villeneuve
2023-12-12 20:03         ` Hugo Villeneuve
2023-12-13 14:43           ` Andy Shevchenko
2023-12-07 19:45       ` David Laight
2023-12-07  1:44   ` Greg KH
2023-12-07 16:02     ` Hugo Villeneuve
2023-12-07  1:45   ` Greg KH
2023-12-07 16:05     ` Hugo Villeneuve
2023-11-30 19:10 ` [PATCH 2/7] serial: sc16is7xx: remove global regmap from struct sc16is7xx_port Hugo Villeneuve
2023-11-30 19:10 ` [PATCH 3/7] serial: sc16is7xx: remove unused line structure member Hugo Villeneuve
2023-11-30 19:10 ` [PATCH 4/7] serial: sc16is7xx: add macro for max number of UART ports Hugo Villeneuve
2023-11-30 19:10 ` Hugo Villeneuve [this message]
2023-11-30 19:10 ` [PATCH 6/7] serial: max310x: add macro for max number of ports Hugo Villeneuve
2023-12-01 15:59   ` Jan Kundrát
2023-11-30 19:10 ` [PATCH 7/7] serial: max310x: use separate regmap name for each port Hugo Villeneuve
2023-12-01 16:00   ` Jan Kundrát
2023-12-06 14:22   ` kernel test robot

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=20231130191050.3165862-6-hugo@hugovil.com \
    --to=hugo@hugovil.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hvilleneuve@dimonoff.com \
    --cc=jirislaby@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /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