Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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.

Fixes: 3837a0379533 ("serial: sc16is7xx: improve regmap debugfs by using one regmap per port")
Cc: <stable@vger.kernel.org> # 6.1.x: 3837a03 serial: sc16is7xx: improve regmap debugfs by using one regmap per port
Suggested-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Hugo Villeneuve <hvilleneuve@dimonoff.com>
Link: https://lore.kernel.org/r/20231211171353.2901416-2-hugo@hugovil.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

authored by

Hugo Villeneuve and committed by
Greg Kroah-Hartman
6bcab3c8 96d7e361

+8 -6
+8 -6
drivers/tty/serial/sc16is7xx.c
··· 1708 1708 .max_register = SC16IS7XX_EFCR_REG, 1709 1709 }; 1710 1710 1711 - static const char *sc16is7xx_regmap_name(unsigned int port_id) 1711 + static const char *sc16is7xx_regmap_name(u8 port_id) 1712 1712 { 1713 - static char buf[6]; 1714 - 1715 - snprintf(buf, sizeof(buf), "port%d", port_id); 1716 - 1717 - return buf; 1713 + switch (port_id) { 1714 + case 0: return "port0"; 1715 + case 1: return "port1"; 1716 + default: 1717 + WARN_ON(true); 1718 + return NULL; 1719 + } 1718 1720 } 1719 1721 1720 1722 static unsigned int sc16is7xx_regmap_port_mask(unsigned int port_id)