Skip to content

Commit

Permalink
serial: sc16is7xx: remove wasteful static buffer in sc16is7xx_regmap_…
Browse files Browse the repository at this point in the history
…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: 3837a03 ("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>
  • Loading branch information
Hugo Villeneuve authored and Greg Kroah-Hartman committed Dec 15, 2023
1 parent 96d7e36 commit 6bcab3c
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions drivers/tty/serial/sc16is7xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6bcab3c

Please sign in to comment.