diff mbox series

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

Message ID 077d491bfa92c2a16f0843c2b0df0773ab8496ee.1592426215.git.rdna@fb.com
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series bpf: Support access to bpf map fields | expand

Commit Message

Andrey Ignatov June 17, 2020, 8:43 p.m. UTC
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@fb.com>
---
 include/linux/btf.h | 2 ++
 kernel/bpf/btf.c    | 8 +++++++-
 2 files changed, 9 insertions(+), 1 deletion(-)
diff mbox series

Patch

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;