[PATCH bpf-next 2/6] bpf: Introduce btf_find_by_name_kind_next()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Introduce btf_find_by_name_kind_next() function to find btf_id by name
and kind starting from specified start_id to reuse the function in
finding duplicates (e.g. structs with same name) in btf.

Signed-off-by: Andrey Ignatov <rdna@xxxxxx>
---
 include/linux/btf.h | 2 ++
 kernel/bpf/btf.c    | 8 +++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/include/linux/btf.h b/include/linux/btf.h
index 5c1ea99b480f..69e017594298 100644
--- a/include/linux/btf.h
+++ b/include/linux/btf.h
@@ -56,6 +56,8 @@ bool btf_member_is_reg_int(const struct btf *btf, const struct btf_type *s,
 int btf_find_spin_lock(const struct btf *btf, const struct btf_type *t);
 bool btf_type_is_void(const struct btf_type *t);
 s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind);
+s32 btf_find_by_name_kind_next(const struct btf *btf, const char *name, u8 kind,
+			       u32 start_id);
 const struct btf_type *btf_type_skip_modifiers(const struct btf *btf,
 					       u32 id, u32 *res_id);
 const struct btf_type *btf_type_resolve_ptr(const struct btf *btf,
diff --git a/kernel/bpf/btf.c b/kernel/bpf/btf.c
index 3eb804618a53..e5c5305e859c 100644
--- a/kernel/bpf/btf.c
+++ b/kernel/bpf/btf.c
@@ -383,12 +383,18 @@ static bool btf_type_is_datasec(const struct btf_type *t)
 }
 
 s32 btf_find_by_name_kind(const struct btf *btf, const char *name, u8 kind)
+{
+	return btf_find_by_name_kind_next(btf, name, kind, 1);
+}
+
+s32 btf_find_by_name_kind_next(const struct btf *btf, const char *name, u8 kind,
+			       u32 start_id)
 {
 	const struct btf_type *t;
 	const char *tname;
 	u32 i;
 
-	for (i = 1; i <= btf->nr_types; i++) {
+	for (i = start_id; i <= btf->nr_types; i++) {
 		t = btf->types[i];
 		if (BTF_INFO_KIND(t->info) != kind)
 			continue;
-- 
2.24.1





[Index of Archives]     [Linux Samsung SoC]     [Linux Rockchip SoC]     [Linux Actions SoC]     [Linux for Synopsys ARC Processors]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]


  Powered by Linux