Skip to contentSkip to conversation

bpf: Replace snprintf("%s", ...) with strscpy in parse_{base,module}

PATCH Applied Thorsten Blum 2 participants 2 messages Feb 1 – Feb 3 BPF

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 bpf: Replace snprintf("%s", ...) with strscpy in parse_{base,module}

Replace snprintf("%s", ...) with the faster and more direct strscpy().

---
Changes in v2:
- Keep snprintf("%s", ...) in btf_show_name() as suggested by Alexei
- Update patch title
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

---
 kernel/bpf/btf.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
kernel/bpf/btf.c +3 -2
index 8959f3bc1e92..7708958e3fb8 100644
@@ -25,6 +25,7 @@
 #include <linux/perf_event.h>
 #include <linux/bsearch.h>
 #include <linux/kobject.h>
+#include <linux/string.h>
 #include <linux/sysfs.h>
 #include <linux/overflow.h>
 
@@ -6324,7 +6325,7 @@ static struct btf *btf_parse_base(struct btf_verifier_env *env, const char *name
 	btf->data_size = data_size;
 	btf->kernel_btf = true;
 	btf->named_start_id = 0;
-	snprintf(btf->name, sizeof(btf->name), "%s", name);
+	strscpy(btf->name, name);
 
 	err = btf_parse_hdr(env);
 	if (err)
@@ -6443,7 +6444,7 @@ static struct btf *btf_parse_module(const char *module_name, const void *data,
 	btf->start_str_off = base_btf->hdr.str_len;
 	btf->kernel_btf = true;
 	btf->named_start_id = 0;
-	snprintf(btf->name, sizeof(btf->name), "%s", module_name);
+	strscpy(btf->name, module_name);
 
 	btf->data = kvmemdup(data, data_size, GFP_KERNEL | __GFP_NOWARN);
 	if (!btf->data) {
Signature · 2 lines
Thorsten Blum <[email protected]>
GPG: 1D60 735E 8AEF 3BE4 73B6  9D84 7336 78FD 8DFE EAD4
#1 lore raw
This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Hello:

This patch was applied to bpf/bpf-next.git (master) by Alexei Starovoitov <[email protected]>:

Quoted 10 lines · On Sun, 1 Feb 2026 22:52:48 +0100 you wrote:

Replace snprintf("%s", ...) with the faster and more direct strscpy().

---
Changes in v2:
- Keep snprintf("%s", ...) in btf_show_name() as suggested by Alexei
- Update patch title
- Link to v1: https://lore.kernel.org/lkml/[email protected]/

[...]

Here is the summary with links:
- [bpf-next,v2] bpf: Replace snprintf("%s", ...) with strscpy in parse_{base,module}

    https://git.kernel.org/bpf/bpf-next/c/d95d76aa772b

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html