BPF List
 help / color / mirror / Atom feed
* [PATCH bpf-next] bpftool: Fix handling enum64 in btf dump sorting
@ 2024-09-01 21:30 Mykyta
  2024-09-02 16:22 ` Daniel Borkmann
  0 siblings, 1 reply; 8+ messages in thread
From: Mykyta @ 2024-09-01 21:30 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, kafai, kernel-team; +Cc: Mykyta Yatsenko

From: Mykyta Yatsenko <yatsenko@meta.com>

Wrong function is used to access the first enum64 element.
Substituting btf_enum(t) with btf_enum64(t) for BTF_KIND_ENUM64.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
---
 tools/bpf/bpftool/btf.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index 6789c7a4d5ca..b0f12c511bb3 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -557,16 +557,23 @@ static const char *btf_type_sort_name(const struct btf *btf, __u32 index, bool f
 	const struct btf_type *t = btf__type_by_id(btf, index);
 
 	switch (btf_kind(t)) {
-	case BTF_KIND_ENUM:
-	case BTF_KIND_ENUM64: {
+	case BTF_KIND_ENUM: {
 		int name_off = t->name_off;
 
 		/* Use name of the first element for anonymous enums if allowed */
-		if (!from_ref && !t->name_off && btf_vlen(t))
+		if (!from_ref && !name_off && btf_vlen(t))
 			name_off = btf_enum(t)->name_off;
 
 		return btf__name_by_offset(btf, name_off);
 	}
+	case BTF_KIND_ENUM64: {
+		int name_off = t->name_off;
+
+		if (!from_ref && !name_off && btf_vlen(t))
+			name_off = btf_enum64(t)->name_off;
+
+		return btf__name_by_offset(btf, name_off);
+	}
 	case BTF_KIND_ARRAY:
 		return btf_type_sort_name(btf, btf_array(t)->type, true);
 	case BTF_KIND_TYPE_TAG:
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread
* [PATCH bpf-next] bpftool: Fix handling enum64 in btf dump sorting
@ 2024-09-02 17:17 Mykyta Yatsenko
  2024-09-02 18:52 ` Quentin Monnet
  2024-09-02 20:50 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 8+ messages in thread
From: Mykyta Yatsenko @ 2024-09-02 17:17 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, kafai, kernel-team; +Cc: Mykyta Yatsenko

From: Mykyta Yatsenko <yatsenko@meta.com>

Wrong function is used to access the first enum64 element.
Substituting btf_enum(t) with btf_enum64(t) for BTF_KIND_ENUM64.

Signed-off-by: Mykyta Yatsenko <yatsenko@meta.com>
---
 tools/bpf/bpftool/btf.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index 6789c7a4d5ca..3b57ba095ab6 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -561,9 +561,10 @@ static const char *btf_type_sort_name(const struct btf *btf, __u32 index, bool f
 	case BTF_KIND_ENUM64: {
 		int name_off = t->name_off;
 
-		/* Use name of the first element for anonymous enums if allowed */
-		if (!from_ref && !t->name_off && btf_vlen(t))
-			name_off = btf_enum(t)->name_off;
+		if (!from_ref && !name_off && btf_vlen(t))
+			name_off = btf_kind(t) == BTF_KIND_ENUM64 ?
+				btf_enum64(t)->name_off :
+				btf_enum(t)->name_off;
 
 		return btf__name_by_offset(btf, name_off);
 	}
-- 
2.46.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-09-03 18:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-09-01 21:30 [PATCH bpf-next] bpftool: Fix handling enum64 in btf dump sorting Mykyta
2024-09-02 16:22 ` Daniel Borkmann
2024-09-02 16:52   ` Mykyta Yatsenko
2024-09-03 16:51   ` Andrii Nakryiko
2024-09-03 18:27     ` Daniel Borkmann
  -- strict thread matches above, loose matches on Subject: below --
2024-09-02 17:17 Mykyta Yatsenko
2024-09-02 18:52 ` Quentin Monnet
2024-09-02 20:50 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox