[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20260201215247.677121-2-thorsten.blum@linux.dev>
Date: Sun, 1 Feb 2026 22:52:48 +0100
From: Thorsten Blum <thorsten.blum@...ux.dev>
To: Martin KaFai Lau <martin.lau@...ux.dev>,
Alexei Starovoitov <ast@...nel.org>,
Daniel Borkmann <daniel@...earbox.net>,
Andrii Nakryiko <andrii@...nel.org>,
Eduard Zingerman <eddyz87@...il.com>,
Song Liu <song@...nel.org>,
Yonghong Song <yonghong.song@...ux.dev>,
John Fastabend <john.fastabend@...il.com>,
KP Singh <kpsingh@...nel.org>,
Stanislav Fomichev <sdf@...ichev.me>,
Hao Luo <haoluo@...gle.com>,
Jiri Olsa <jolsa@...nel.org>
Cc: Thorsten Blum <thorsten.blum@...ux.dev>,
bpf@...r.kernel.org,
linux-kernel@...r.kernel.org
Subject: [PATCH bpf-next v2] bpf: Replace snprintf("%s", ...) with strscpy in parse_{base,module}
Replace snprintf("%s", ...) with the faster and more direct strscpy().
Signed-off-by: Thorsten Blum <thorsten.blum@...ux.dev>
---
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/20260201180445.664056-2-thorsten.blum@linux.dev/
---
kernel/bpf/btf.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 8959f3bc1e92..7708958e3fb8 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -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) {
--
Thorsten Blum <thorsten.blum@...ux.dev>
GPG: 1D60 735E 8AEF 3BE4 73B6 9D84 7336 78FD 8DFE EAD4
Powered by blists - more mailing lists