aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe JAILLET <christophe.jaillet@wanadoo.fr>2023-09-04 21:54:36 +0200
committerDamien Le Moal <dlemoal@kernel.org>2023-09-11 15:13:35 +0900
commite97eb65dd464e7f118a16a26337322d07eb653e2 (patch)
tree59f4d07c48e20c1ffadff7865588a6a868bb06fd
parent24e0e61db3cb86a66824531989f1df80e0939f26 (diff)
downloadlinux-e97eb65dd464e7f118a16a26337322d07eb653e2.tar.gz
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>
-rw-r--r--drivers/ata/sata_mv.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
index d105db5c7d81a6..45e48d653c60b5 100644
--- a/drivers/ata/sata_mv.c
+++ b/drivers/ata/sata_mv.c
@@ -1255,8 +1255,8 @@ 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,
- "%08x ", readl(start + b));
+ o += scnprintf(linebuf + o, sizeof(linebuf) - o,
+ "%08x ", readl(start + b));
b += sizeof(u32);
}
dev_dbg(dev, "%s: %p: %s\n",