summary refs log tree commit diff
path: root/tools/bpf
diff options
context:
space:
mode:
authorAndrii Nakryiko <andrii@kernel.org>2021-10-22 16:09:15 -0700
committerAndrii Nakryiko <andrii@kernel.org>2021-10-22 16:09:15 -0700
commit59f2a29c04128a46df0031d4deb4c4b07c5edcea (patch)
treeb2c6ec554b4b21bb648bf273b9acbd215fc9f813 /tools/bpf
parent1000298c76830bc291358e98e8fa5baa3baa9b3a (diff)
parent487ef148cf17730442444c07a4c56f16578ec73e (diff)
downloadlinux-59f2a29c04128a46df0031d4deb4c4b07c5edcea.tar.gz
Merge branch 'libbpf: Add btf__type_cnt() and btf__raw_data() APIs'
Hengqi Chen says:

====================

Add btf__type_cnt() and btf__raw_data() APIs and deprecate
btf__get_nr_type() and btf__get_raw_data() since the old APIs
don't follow libbpf naming convention. Also update tools/selftests
to use these new APIs. This is part of effort towards libbpf v1.0

v1->v2:
 - Update commit message, deprecate the old APIs in libbpf v0.7 (Andrii)
 - Separate changes in tools/ to individual patches (Andrii)
====================

Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Diffstat (limited to 'tools/bpf')
-rw-r--r--tools/bpf/bpftool/btf.c12
-rw-r--r--tools/bpf/bpftool/gen.c4
-rw-r--r--tools/bpf/resolve_btfids/main.c4
3 files changed, 10 insertions, 10 deletions
diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index 7b68d4f65fe6..0cd769adac66 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -329,7 +329,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 				printf("\n\ttype_id=%u offset=%u size=%u",
 				       v->type, v->offset, v->size);
 
-				if (v->type <= btf__get_nr_types(btf)) {
+				if (v->type < btf__type_cnt(btf)) {
 					vt = btf__type_by_id(btf, v->type);
 					printf(" (%s '%s')",
 					       btf_kind_str[btf_kind_safe(btf_kind(vt))],
@@ -390,14 +390,14 @@ static int dump_btf_raw(const struct btf *btf,
 		}
 	} else {
 		const struct btf *base;
-		int cnt = btf__get_nr_types(btf);
+		int cnt = btf__type_cnt(btf);
 		int start_id = 1;
 
 		base = btf__base_btf(btf);
 		if (base)
-			start_id = btf__get_nr_types(base) + 1;
+			start_id = btf__type_cnt(base);
 
-		for (i = start_id; i <= cnt; i++) {
+		for (i = start_id; i < cnt; i++) {
 			t = btf__type_by_id(btf, i);
 			dump_btf_type(btf, i, t);
 		}
@@ -440,9 +440,9 @@ static int dump_btf_c(const struct btf *btf,
 				goto done;
 		}
 	} else {
-		int cnt = btf__get_nr_types(btf);
+		int cnt = btf__type_cnt(btf);
 
-		for (i = 1; i <= cnt; i++) {
+		for (i = 1; i < cnt; i++) {
 			err = btf_dump__dump_type(d, i);
 			if (err)
 				goto done;
diff --git a/tools/bpf/bpftool/gen.c b/tools/bpf/bpftool/gen.c
index c446405ab73f..5c18351290f0 100644
--- a/tools/bpf/bpftool/gen.c
+++ b/tools/bpf/bpftool/gen.c
@@ -211,7 +211,7 @@ static int codegen_datasec_def(struct bpf_object *obj,
 static int codegen_datasecs(struct bpf_object *obj, const char *obj_name)
 {
 	struct btf *btf = bpf_object__btf(obj);
-	int n = btf__get_nr_types(btf);
+	int n = btf__type_cnt(btf);
 	struct btf_dump *d;
 	struct bpf_map *map;
 	const struct btf_type *sec;
@@ -233,7 +233,7 @@ static int codegen_datasecs(struct bpf_object *obj, const char *obj_name)
 			continue;
 
 		sec = NULL;
-		for (i = 1; i <= n; i++) {
+		for (i = 1; i < n; i++) {
 			const struct btf_type *t = btf__type_by_id(btf, i);
 			const char *name;
 
diff --git a/tools/bpf/resolve_btfids/main.c b/tools/bpf/resolve_btfids/main.c
index 716e6ad1864b..a59cb0ee609c 100644
--- a/tools/bpf/resolve_btfids/main.c
+++ b/tools/bpf/resolve_btfids/main.c
@@ -502,12 +502,12 @@ static int symbols_resolve(struct object *obj)
 	}
 
 	err = -1;
-	nr_types = btf__get_nr_types(btf);
+	nr_types = btf__type_cnt(btf);
 
 	/*
 	 * Iterate all the BTF types and search for collected symbol IDs.
 	 */
-	for (type_id = 1; type_id <= nr_types; type_id++) {
+	for (type_id = 1; type_id < nr_types; type_id++) {
 		const struct btf_type *type;
 		struct rb_root *root;
 		struct btf_id *id;