From: Thorsten Blum <thorsten.blum@linux.dev>
To: Andy Shevchenko <andriy.shevchenko@linux.intel.com>,
Thomas Gleixner <tglx@kernel.org>, Ingo Molnar <mingo@redhat.com>,
Borislav Petkov <bp@alien8.de>,
Dave Hansen <dave.hansen@linux.intel.com>,
x86@kernel.org, "H. Peter Anvin" <hpa@zytor.com>,
Andrew Morton <akpm@linux-foundation.org>,
Ard Biesheuvel <ardb@kernel.org>,
"Mike Rapoport (Microsoft)" <rppt@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
Jiri Bohac <jbohac@suse.cz>,
Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Cc: Thorsten Blum <thorsten.blum@linux.dev>,
Ingo Molnar <mingo@kernel.org>,
linux-kernel@vger.kernel.org
Subject: [PATCH v2] x86/setup: Replace strlcat() with snprintf() in setup_arch()
Date: Thu, 25 Jun 2026 17:01:18 +0200 [thread overview]
Message-ID: <20260625150119.705227-2-thorsten.blum@linux.dev> (raw)
In preparation to remove strlcat() from the kernel [1], replace two
strlcat() calls with snprintf() in setup_arch().
Also drop the explicit size argument to strscpy() to further simplify
the code since strscpy() can determine the size automatically when the
destination buffer has a fixed length.
Link: https://github.com/KSPP/linux/issues/370 [1]
Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
---
Changes in v2:
- Use a Link: tag as suggested by Andy
- v1: https://lore.kernel.org/r/20260604131752.1327556-3-thorsten.blum@linux.dev/
---
arch/x86/kernel/setup.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
index 46882ce79c3a..b11b0ce31a27 100644
--- a/arch/x86/kernel/setup.c
+++ b/arch/x86/kernel/setup.c
@@ -21,6 +21,7 @@
#include <linux/pci.h>
#include <linux/random.h>
#include <linux/root_dev.h>
+#include <linux/sprintf.h>
#include <linux/static_call.h>
#include <linux/sysfb.h>
#include <linux/swiotlb.h>
@@ -915,16 +916,18 @@ void __init setup_arch(char **cmdline_p)
strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
#else
if (builtin_cmdline[0]) {
+ size_t len = strnlen(builtin_cmdline, COMMAND_LINE_SIZE);
+
/* append boot loader cmdline to builtin */
- strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
- strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
+ snprintf(builtin_cmdline + len, COMMAND_LINE_SIZE - len, " %s",
+ boot_command_line);
strscpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
}
#endif
builtin_cmdline_added = true;
#endif
- strscpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
+ strscpy(command_line, boot_command_line);
*cmdline_p = command_line;
/*
reply other threads:[~2026-06-25 15:02 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=20260625150119.705227-2-thorsten.blum@linux.dev \
--to=thorsten.blum@linux.dev \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=ardb@kernel.org \
--cc=bp@alien8.de \
--cc=dave.hansen@linux.intel.com \
--cc=harshit.m.mogalapalli@oracle.com \
--cc=hpa@zytor.com \
--cc=jbohac@suse.cz \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=mingo@redhat.com \
--cc=rppt@kernel.org \
--cc=tglx@kernel.org \
--cc=tzimmermann@suse.de \
--cc=x86@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