]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
bpf: Replace snprintf("%s") with strscpy
authorThorsten Blum <thorsten.blum@linux.dev>
Sun, 1 Feb 2026 21:52:48 +0000 (22:52 +0100)
committerAlexei Starovoitov <ast@kernel.org>
Tue, 3 Feb 2026 02:43:33 +0000 (18:43 -0800)
Replace snprintf("%s") with the faster and more direct strscpy().

Signed-off-by: Thorsten Blum <thorsten.blum@linux.dev>
Link: https://lore.kernel.org/r/20260201215247.677121-2-thorsten.blum@linux.dev
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
kernel/bpf/btf.c

index 8959f3bc1e927be3b574179da8acb5a129702006..7708958e3fb8ca244d0c9e56d6007e9168d696a3 100644 (file)
@@ -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) {