Skip to content

Commit e97eb65

Browse files
tititiou36damien-lemoal
authored andcommitted
ata: sata_mv: Fix incorrect string length computation in mv_dump_mem()
snprintf() returns the "number of characters which *would* be generated for the given input", not the size *really* generated. In order to avoid too large values for 'o' (and potential negative values for "sizeof(linebuf) o") use scnprintf() instead of snprintf(). Note that given the "w < 4" in the for loop, the buffer can NOT overflow, but using the *right* function is always better. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
1 parent 24e0e61 commit e97eb65

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

drivers/ata/sata_mv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1255,8 +1255,8 @@ static void mv_dump_mem(struct device *dev, void __iomem *start, unsigned bytes)
12551255

12561256
for (b = 0; b < bytes; ) {
12571257
for (w = 0, o = 0; b < bytes && w < 4; w++) {
1258-
o += snprintf(linebuf + o, sizeof(linebuf) - o,
1259-
"%08x ", readl(start + b));
1258+
o += scnprintf(linebuf + o, sizeof(linebuf) - o,
1259+
"%08x ", readl(start + b));
12601260
b += sizeof(u32);
12611261
}
12621262
dev_dbg(dev, "%s: %p: %s\n",

0 commit comments

Comments
 (0)