[PATCH 5/7] serial: sc16is7xx: improve sc16is7xx_regmap_name() buffer size computation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Hugo Villeneuve <hvilleneuve@xxxxxxxxxxxx>

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@xxxxxxxxxxxx>
---
 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





[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux