From: Damien Le Moal <dlemoal@kernel.org>
To: Christophe JAILLET <christophe.jaillet@wanadoo.fr>
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
linux-ide@vger.kernel.org
Subject: Re: [PATCH] ata: sata_mv: Fix incorrect string length computation in mv_dump_mem()
Date: Tue, 5 Sep 2023 14:04:00 +0900 [thread overview]
Message-ID: <b5dcc85d-f709-a3a3-e7ad-9c71f278842a@kernel.org> (raw)
In-Reply-To: <1a35e114a3dcc33053ca7cca41cb06b8426d8c40.1693857262.git.christophe.jaillet@wanadoo.fr>
On 9/5/23 04:54, Christophe JAILLET wrote:
> 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>
Doesn't this need Fixes and CC stable tags ?
> ---
> drivers/ata/sata_mv.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/ata/sata_mv.c b/drivers/ata/sata_mv.c
> index d105db5c7d81..45e48d653c60 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",
--
Damien Le Moal
Western Digital Research
next prev parent reply other threads:[~2023-09-05 16:45 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-04 19:54 Christophe JAILLET
2023-09-05 5:04 ` Damien Le Moal [this message]
2023-09-05 15:28 ` Christophe JAILLET
2023-09-06 1:11 ` Damien Le Moal
2023-09-08 5:18 ` Christophe JAILLET
2023-09-11 6:14 ` Damien Le Moal
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b5dcc85d-f709-a3a3-e7ad-9c71f278842a@kernel.org \
--to=dlemoal@kernel.org \
--cc=christophe.jaillet@wanadoo.fr \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-ide@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®