Skip to contentSkip to conversation

mmc: mmc_spi: drop buggy snprintf()

PATCH In review Bartosz Golaszewski 2 participants 2 messages Oct 8, 2024 – Oct 9, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mmc: mmc_spi: drop buggy snprintf()

From: Bartosz Golaszewski <[email protected]>

GCC 13 complains about the truncated output of snprintf():

drivers/mmc/host/mmc_spi.c: In function ‘mmc_spi_response_get’:
drivers/mmc/host/mmc_spi.c:227:64: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
227 | snprintf(tag, sizeof(tag), " ... CMD%d response SPI_%s",
| ^
drivers/mmc/host/mmc_spi.c:227:9: note: ‘snprintf’ output between 26 and 43 bytes into a destination of size 32

  227 |         snprintf(tag, sizeof(tag), "  ... CMD%d response SPI_%s",
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  228 |                 cmd->opcode, maptype(cmd));

Drop it and fold the string it generates into the only place where it's emitted - the dev_dbg() call at the end of the function.

Fixes 15a0580ced08 ("mmc_spi host driver")

---
- instead of fixing the buffer size, just drop the snprintf() call altogether

 drivers/mmc/host/mmc_spi.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/mmc/host/mmc_spi.c +3 -6
index 8fee7052f2ef..47443fb5eb33 100644
@@ -222,10 +222,6 @@ static int mmc_spi_response_get(struct mmc_spi_host *host,
 	u8 	leftover = 0;
 	unsigned short rotator;
 	int 	i;
-	char	tag[32];
-
-	snprintf(tag, sizeof(tag), "  ... CMD%d response SPI_%s",
-		cmd->opcode, maptype(cmd));
 
 	/* Except for data block reads, the whole response will already
 	 * be stored in the scratch buffer.  It's somewhere after the
@@ -378,8 +374,9 @@ static int mmc_spi_response_get(struct mmc_spi_host *host,
 	}
 
 	if (value < 0)
-		dev_dbg(&host->spi->dev, "%s: resp %04x %08x\n",
-			tag, cmd->resp[0], cmd->resp[1]);
+		dev_dbg(&host->spi->dev,
+			"  ... CMD%d response SPI_%s: resp %04x %08x\n",
+			cmd->opcode, maptype(cmd), cmd->resp[0], cmd->resp[1]);
 
 	/* disable chipselect on errors and some success cases */
 	if (value >= 0 && cs_on)
Signature · 1 line
2.43.0
#1 lore raw
Quoted 14 lines · Bartosz Golaszewski

From: Bartosz Golaszewski <[email protected]>

GCC 13 complains about the truncated output of snprintf():

drivers/mmc/host/mmc_spi.c: In function ‘mmc_spi_response_get’:
drivers/mmc/host/mmc_spi.c:227:64: error: ‘snprintf’ output may be truncated before the last format character [-Werror=format-truncation=]
227 | snprintf(tag, sizeof(tag), " ... CMD%d response SPI_%s",
| ^
drivers/mmc/host/mmc_spi.c:227:9: note: ‘snprintf’ output between 26 and 43 bytes into a destination of size 32

  227 |         snprintf(tag, sizeof(tag), "  ... CMD%d response SPI_%s",
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  228 |                 cmd->opcode, maptype(cmd));
Quoted 6 lines

Drop it and fold the string it generates into the only place where it's emitted - the dev_dbg() call at the end of the function.

Fixes 15a0580ced08 ("mmc_spi host driver")

Applied for next, thanks!

Kind regards
Uffe

Quoted 37 lines

---
- instead of fixing the buffer size, just drop the snprintf() call altogether

 drivers/mmc/host/mmc_spi.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)
drivers/mmc/host/mmc_spi.c +3 -7
index 8fee7052f2ef..47443fb5eb33 100644
@@ -222,10 +222,6 @@ static int mmc_spi_response_get(struct mmc_spi_host *host,
        u8      leftover = 0;
        unsigned short rotator;
        int     i;
-       char    tag[32];
-
-       snprintf(tag, sizeof(tag), "  ... CMD%d response SPI_%s",
-               cmd->opcode, maptype(cmd));
 
        /* Except for data block reads, the whole response will already
         * be stored in the scratch buffer.  It's somewhere after the
@@ -378,8 +374,9 @@ static int mmc_spi_response_get(struct mmc_spi_host *host,
        }
 
        if (value < 0)
-               dev_dbg(&host->spi->dev, "%s: resp %04x %08x\n",
-                       tag, cmd->resp[0], cmd->resp[1]);
+               dev_dbg(&host->spi->dev,
+                       "  ... CMD%d response SPI_%s: resp %04x %08x\n",
+                       cmd->opcode, maptype(cmd), cmd->resp[0], cmd->resp[1]);
 
        /* disable chipselect on errors and some success cases */
        if (value >= 0 && cs_on)
--

2.43.0