patch "serial: sc16is7xx: remove wasteful static buffer in" added to tty-next
Subsystems (2)
This is a note to let you know that I've just added the patch titled
serial: sc16is7xx: remove wasteful static buffer in
to my tty git tree which can be found at
git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/tty.git
in the tty-next branch.
The patch will show up in the next release of the linux-next tree (usually sometime within the next 24 hours during the week.)
The patch will also be merged in the next major kernel release during the merge window.
If you have any questions about this process, please let me know.
From 6bcab3c8acc88e265c570dea969fd04f137c8a4c Mon Sep 17 00:00:00 2001
From: Hugo Villeneuve <[email protected]>
Date: Mon, 11 Dec 2023 12:13:48 -0500
Subject: serial: sc16is7xx: remove wasteful static buffer in
sc16is7xx_regmap_name()
Using a static buffer inside sc16is7xx_regmap_name() was a convenient and simple way to set the regmap name without having to allocate and free a buffer each time it is called. The drawback is that the static buffer wastes memory for nothing once regmap is fully initialized.
Remove static buffer and use constant strings instead.
This also avoids a truncation warning when using "%d" or "%u" in snprintf which was flagged by kernel test robot.
--- drivers/tty/serial/sc16is7xx.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-)
drivers/tty/serial/sc16is7xx.c +8 -6
@@ -1708,13 +1708,15 @@ static struct regmap_config regcfg = { .max_register = SC16IS7XX_EFCR_REG, }; -static const char *sc16is7xx_regmap_name (unsigned int port_id) +static const char *sc16is7xx_regmap_name (u8 port_id) { -static char buf[6 ]; - -snprintf (buf,sizeof (buf),"port%d" , port_id); - -return buf; +switch (port_id) { +case 0 :return "port0" ; +case 1 :return "port1" ; +default : +WARN_ON (true); +return NULL ; + } }static unsigned int sc16is7xx_regmap_port_mask (unsigned int port_id)
Signature · 1 line
2.43.0