Re: [PATCH bpf-next 1/5] libbpf: add BTF field iterator

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

 



On Tue, 2024-06-04 at 14:40 -0700, Andrii Nakryiko wrote:

[...]

> > Nit: it is a bit confusing that for two 'if' statements above
> >      m_idx is guarded by vlen and off_idx is guarded by m_cnt :)
> 
> I'm open to suggestions. m_idx stands for "current member index",
> m_cnt is for "per-member offset count", while "off_idx" is generic
> "offset index" which indexes either a singular set of offsets or
> per-member set of offsets. Easy ;)

Well, since you've asked, how about renaming like below?
At-least 'off_idx' is always compared to something with 'off' in it's name.

---

diff --git a/tools/lib/bpf/btf.c b/tools/lib/bpf/btf.c
index 1de7579f2a08..9ea09b808459 100644
--- a/tools/lib/bpf/btf.c
+++ b/tools/lib/bpf/btf.c
@@ -5169,7 +5169,7 @@ __u32 *btf_field_iter_next(struct btf_field_iter *it)
 		return NULL;
 
 	if (it->m_idx < 0) {
-		if (it->off_idx < it->desc.t_cnt)
+		if (it->off_idx < it->desc.t_offs_cnt)
 			return it->p + it->desc.t_offs[it->off_idx++];
 		/* move to per-member iteration */
 		it->m_idx = 0;
@@ -5183,7 +5183,7 @@ __u32 *btf_field_iter_next(struct btf_field_iter *it)
 		return NULL;
 	}
 
-	if (it->off_idx >= it->desc.m_cnt) {
+	if (it->off_idx >= it->desc.m_offs_cnt) {
 		/* exhausted this member's fields, go to the next member */
 		it->m_idx++;
 		it->p += it->desc.m_sz;
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 9f4a04367287..aa32b4537dba 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -515,11 +515,11 @@ enum btf_field_iter_kind {
 
 struct btf_field_desc {
 	/* once-per-type offsets */
-	int t_cnt, t_offs[2];
+	int t_offs_cnt, t_offs[2];
 	/* member struct size, or zero, if no members */
 	int m_sz;
 	/* repeated per-member offsets */
-	int m_cnt, m_offs[1];
+	int m_offs_cnt, m_offs[1];
 };
 
 struct btf_field_iter {






[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