* [PATCH] powerpc/rtas_flash: Use scnprintf() in rtas_flash_read_num()
@ 2026-07-22 16:28 Thorsten Blum
2026-09-25 6:48 ` Sourabh Jain
0 siblings, 1 reply; 2+ messages in thread
From: Thorsten Blum @ 2026-07-22 16:28 UTC (permalink / raw)
To: Madhavan Srinivasan, Michael Ellerman, Nicholas Piggin,
Christophe Leroy (CS GROUP)
Cc: Thorsten Blum, linuxppc-dev, linux-kernel
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);
}
/* We could be much more efficient here. But to keep this function
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] powerpc/rtas_flash: Use scnprintf() in rtas_flash_read_num()
2026-07-22 16:28 [PATCH] powerpc/rtas_flash: Use scnprintf() in rtas_flash_read_num() Thorsten Blum
@ 2026-09-25 6:48 ` Sourabh Jain
0 siblings, 0 replies; 2+ messages in thread
From: Sourabh Jain @ 2026-09-25 6:48 UTC (permalink / raw)
To: Thorsten Blum, Madhavan Srinivasan, Michael Ellerman,
Nicholas Piggin, Christophe Leroy (CS GROUP)
Cc: linuxppc-dev, linux-kernel
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-09-25 6:48 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-07-22 16:28 [PATCH] powerpc/rtas_flash: Use scnprintf() in rtas_flash_read_num() Thorsten Blum
2026-09-25 6:48 ` Sourabh Jain
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®