From: Sourabh Jain <sourabhjain@linux.ibm.com>
To: Thorsten Blum <thorsten.blum@linux.dev>,
Madhavan Srinivasan <maddy@linux.ibm.com>,
Michael Ellerman <mpe@ellerman.id.au>,
Nicholas Piggin <npiggin@gmail.com>,
"Christophe Leroy (CS GROUP)" <chleroy@kernel.org>
Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] powerpc/rtas_flash: Use scnprintf() in rtas_flash_read_num()
Date: Fri, 25 Sep 2026 12:18:17 +0530 [thread overview]
Message-ID: <ff767954-a8c0-49eb-94f1-8f0b9419498c@linux.ibm.com> (raw)
In-Reply-To: <20260722162816.156697-3-thorsten.blum@linux.dev>
On 22/07/26 21:58, Thorsten Blum wrote:
> Use scnprintf() and its return value to avoid a separate strlen() call.
>
> Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
> ---
> arch/powerpc/kernel/rtas_flash.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/arch/powerpc/kernel/rtas_flash.c b/arch/powerpc/kernel/rtas_flash.c
> index 583dc16e9d3c..aff8a67e274f 100644
> --- a/arch/powerpc/kernel/rtas_flash.c
> +++ b/arch/powerpc/kernel/rtas_flash.c
> @@ -291,6 +291,7 @@ static ssize_t rtas_flash_read_num(struct file *file, char __user *buf,
> {
> struct rtas_update_flash_t *const uf = &rtas_update_flash_data;
> char msg[RTAS_MSG_MAXLEN];
> + size_t len;
> int status;
>
> mutex_lock(&rtas_update_flash_mutex);
> @@ -298,8 +299,8 @@ static ssize_t rtas_flash_read_num(struct file *file, char __user *buf,
> mutex_unlock(&rtas_update_flash_mutex);
>
> /* Read as number */
> - sprintf(msg, "%d\n", status);
> - return simple_read_from_buffer(buf, count, ppos, msg, strlen(msg));
> + len = scnprintf(msg, sizeof(msg), "%d\n", status);
> + return simple_read_from_buffer(buf, count, ppos, msg, len);
Though there is no real buffer overflow issue here, it is a good idea to
convert sprintf to scnprintf. This change helps avoid calling strlen on the
same buffer.
Changes looks good to me. Feel free to add:
Reviewed-by: Sourabh Jain <sourabhjain@linux.ibm.com>
> }
>
> /* We could be much more efficient here. But to keep this function
prev parent reply other threads:[~2026-09-25 6:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-22 16:28 Thorsten Blum
2026-09-25 6:48 ` Sourabh Jain [this message]
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=ff767954-a8c0-49eb-94f1-8f0b9419498c@linux.ibm.com \
--to=sourabhjain@linux.ibm.com \
--cc=chleroy@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linuxppc-dev@lists.ozlabs.org \
--cc=maddy@linux.ibm.com \
--cc=mpe@ellerman.id.au \
--cc=npiggin@gmail.com \
--cc=thorsten.blum@linux.dev \
/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®