[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20251218113051.455293-13-dolinux.peng@gmail.com>
Date: Thu, 18 Dec 2025 19:30:50 +0800
From: Donglin Peng <dolinux.peng@...il.com>
To: ast@...nel.org,
andrii.nakryiko@...il.com,
eddyz87@...il.com
Cc: zhangxiaoqin@...omi.com,
ihor.solodrai@...ux.dev,
linux-kernel@...r.kernel.org,
bpf@...r.kernel.org,
pengdonglin <pengdonglin@...omi.com>,
Alan Maguire <alan.maguire@...cle.com>
Subject: [PATCH bpf-next v10 12/13] btf: Add btf_is_sorted to refactor the code
From: pengdonglin <pengdonglin@...omi.com>
Introduce a new helper function to clarify the code and no
functional changes are introduced.
Cc: Eduard Zingerman <eddyz87@...il.com>
Cc: Alexei Starovoitov <ast@...nel.org>
Cc: Andrii Nakryiko <andrii.nakryiko@...il.com>
Cc: Alan Maguire <alan.maguire@...cle.com>
Cc: Ihor Solodrai <ihor.solodrai@...ux.dev>
Cc: Xiaoqin Zhang <zhangxiaoqin@...omi.com>
Signed-off-by: pengdonglin <pengdonglin@...omi.com>
---
include/linux/btf.h | 1 +
kernel/bpf/btf.c | 9 +++++++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/include/linux/btf.h b/include/linux/btf.h
index 2d28f2b22ae5..947ed2abf632 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -221,6 +221,7 @@ bool btf_is_vmlinux(const struct btf *btf);
struct module *btf_try_get_module(const struct btf *btf);
u32 btf_nr_types(const struct btf *btf);
u32 btf_sorted_start_id(const struct btf *btf);
+bool btf_is_sorted(const struct btf *btf);
struct btf *btf_base_btf(const struct btf *btf);
bool btf_type_is_i32(const struct btf_type *t);
bool btf_type_is_i64(const struct btf_type *t);
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 3aeb4f00cbfe..0f20887a6f02 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -555,6 +555,11 @@ u32 btf_sorted_start_id(const struct btf *btf)
return btf->sorted_start_id ?: (btf->start_id ?: 1);
}
+bool btf_is_sorted(const struct btf *btf)
+{
+ return btf->sorted_start_id > 0;
+}
+
/*
* Assuming that types are sorted by name in ascending order.
*/
@@ -649,9 +654,9 @@ s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind)
return idx;
}
- if (btf->sorted_start_id > 0 && name[0]) {
+ if (btf_is_sorted(btf) && name[0]) {
/* skip anonymous types */
- s32 start_id = btf->sorted_start_id;
+ s32 start_id = btf_sorted_start_id(btf);
s32 end_id = btf_nr_types(btf) - 1;
idx = btf_find_by_name_bsearch(btf, name, start_id, end_id);
--
2.34.1
Powered by blists - more mailing lists