From: Thorsten Blum <thorsten.blum@linux.dev>
To: Paul Walmsley <pjw@kernel.org>,
Palmer Dabbelt <palmer@dabbelt.com>,
Albert Ou <aou@eecs.berkeley.edu>,
Alexandre Ghiti <alex@ghiti.fr>,
Junhui Liu <junhui.liu@pigmoral.tech>,
Nutty Liu <liujingqi@lanxincomputing.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
Alexandre Ghiti <alexghiti@rivosinc.com>,
linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org
Subject: [PATCH] riscv: pi: replace strlcat with strscpy in get_early_cmdline
Date: Mon, 4 May 2026 17:49:24 +0200 [thread overview]
Message-ID: <20260504154924.141566-3-thorsten.blum@linux.dev> (raw)
Use the return value of strscpy() instead of calling strlen(fdt_cmdline)
again and return early on string truncation. Drop the explicit size
argument since early_cmdline has a fixed length, which strscpy()
determines using sizeof() when the argument is omitted.
Replace strlcat() with strscpy() to append CONFIG_CMDLINE.
Also remove the unnecessary fdt_cmdline NULL initialization.
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
arch/riscv/kernel/pi/cmdline_early.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/arch/riscv/kernel/pi/cmdline_early.c b/arch/riscv/kernel/pi/cmdline_early.c
index 389d086a0718..0afbe4077cb8 100644
--- a/arch/riscv/kernel/pi/cmdline_early.c
+++ b/arch/riscv/kernel/pi/cmdline_early.c
@@ -12,8 +12,8 @@ static char early_cmdline[COMMAND_LINE_SIZE];
static char *get_early_cmdline(uintptr_t dtb_pa)
{
- const char *fdt_cmdline = NULL;
- unsigned int fdt_cmdline_size = 0;
+ const char *fdt_cmdline;
+ ssize_t fdt_cmdline_size = 0;
int chosen_node;
if (!IS_ENABLED(CONFIG_CMDLINE_FORCE)) {
@@ -22,18 +22,18 @@ static char *get_early_cmdline(uintptr_t dtb_pa)
fdt_cmdline = fdt_getprop((void *)dtb_pa, chosen_node,
"bootargs", NULL);
if (fdt_cmdline) {
- fdt_cmdline_size = strlen(fdt_cmdline);
- strscpy(early_cmdline, fdt_cmdline,
- COMMAND_LINE_SIZE);
+ fdt_cmdline_size = strscpy(early_cmdline, fdt_cmdline);
+ if (fdt_cmdline_size < 0)
+ return early_cmdline;
}
}
}
if (IS_ENABLED(CONFIG_CMDLINE_EXTEND) ||
IS_ENABLED(CONFIG_CMDLINE_FORCE) ||
- fdt_cmdline_size == 0 /* CONFIG_CMDLINE_FALLBACK */) {
- strlcat(early_cmdline, CONFIG_CMDLINE, COMMAND_LINE_SIZE);
- }
+ fdt_cmdline_size == 0 /* CONFIG_CMDLINE_FALLBACK */)
+ strscpy(early_cmdline + fdt_cmdline_size, CONFIG_CMDLINE,
+ COMMAND_LINE_SIZE - fdt_cmdline_size);
return early_cmdline;
}
reply other threads:[~2026-05-04 15:50 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20260504154924.141566-3-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=alex@ghiti.fr \
--cc=alexghiti@rivosinc.com \
--cc=aou@eecs.berkeley.edu \
--cc=junhui.liu@pigmoral.tech \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=liujingqi@lanxincomputing.com \
--cc=palmer@dabbelt.com \
--cc=pjw@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