From: pengdonglin Introduce a new helper function to clarify the code and no functional changes are introduced. Cc: Eduard Zingerman Cc: Alexei Starovoitov Cc: Andrii Nakryiko Cc: Alan Maguire Cc: Ihor Solodrai Cc: Xiaoqin Zhang Signed-off-by: pengdonglin --- 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