Commit e97eb65d authored by Christophe JAILLET's avatar Christophe JAILLET Committed by Damien Le Moal
Browse files

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: default avatarChristophe JAILLET <christophe.jaillet@wanadoo.fr>
Signed-off-by: default avatarDamien Le Moal <dlemoal@kernel.org>
parent 24e0e61d
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -1255,7 +1255,7 @@ static void mv_dump_mem(struct device *dev, void __iomem *start, unsigned bytes)

	for (b = 0; b < bytes; ) {
		for (w = 0, o = 0; b < bytes && w < 4; w++) {
			o += snprintf(linebuf + o, sizeof(linebuf) - o,
			o += scnprintf(linebuf + o, sizeof(linebuf) - o,
				       "%08x ", readl(start + b));
			b += sizeof(u32);
		}