The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] bpftool: use btf_vlen()/btf_kind()/btf_kflag() helpers consistently
@ 2026-07-01  6:25 luoliang
  2026-07-01 12:58 ` Quentin Monnet
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: luoliang @ 2026-07-01  6:25 UTC (permalink / raw)
  To: Quentin Monnet
  Cc: Alexei Starovoitov, Andrii Nakryiko, bpf, linux-kernel, Liang Luo

From: luoliang <luoliang@kylinos.cn>

The btf_vlen(), btf_kind() and btf_kflag() inline helpers defined in
tools/lib/bpf/btf.h are thin wrappers around the BTF_INFO_VLEN(),
BTF_INFO_KIND() and BTF_INFO_KFLAG() UAPI macros - each one simply
returns the corresponding macro applied to t->info.

bpftool already uses these helpers in most places, but 13 call sites
in btf.c and btf_dumper.c still open-code the raw macros. Use the
helpers consistently, matching the rest of bpftool as well as libbpf.

No functional change.

Signed-off-by: Liang Luo <luoliang@kylinos.cn>
---
 tools/bpf/bpftool/btf.c        | 12 ++++++------
 tools/bpf/bpftool/btf_dumper.c | 14 +++++++-------
 2 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index 6ef908adf3a4..24e4cb600b3f 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -179,7 +179,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 	case BTF_KIND_STRUCT:
 	case BTF_KIND_UNION: {
 		const struct btf_member *m = (const void *)(t + 1);
-		__u32 i, vlen = BTF_INFO_VLEN(t->info);
+		__u32 i, vlen = btf_vlen(t);
 
 		if (json_output) {
 			jsonw_uint_field(w, "size", t->size);
@@ -193,7 +193,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 			const char *name = btf_str(btf, m->name_off);
 			__u32 bit_off, bit_sz;
 
-			if (BTF_INFO_KFLAG(t->info)) {
+			if (btf_kflag(t)) {
 				bit_off = BTF_MEMBER_BIT_OFFSET(m->offset);
 				bit_sz = BTF_MEMBER_BITFIELD_SIZE(m->offset);
 			} else {
@@ -224,7 +224,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 	}
 	case BTF_KIND_ENUM: {
 		const struct btf_enum *v = (const void *)(t + 1);
-		__u32 i, vlen = BTF_INFO_VLEN(t->info);
+		__u32 i, vlen = btf_vlen(t);
 		const char *encoding;
 
 		encoding = btf_kflag(t) ? "SIGNED" : "UNSIGNED";
@@ -300,7 +300,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 		break;
 	}
 	case BTF_KIND_FWD: {
-		const char *fwd_kind = BTF_INFO_KFLAG(t->info) ? "union"
+		const char *fwd_kind = btf_kflag(t) ? "union"
 							       : "struct";
 
 		if (json_output)
@@ -322,7 +322,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 	}
 	case BTF_KIND_FUNC_PROTO: {
 		const struct btf_param *p = (const void *)(t + 1);
-		__u32 i, vlen = BTF_INFO_VLEN(t->info);
+		__u32 i, vlen = btf_vlen(t);
 
 		if (json_output) {
 			jsonw_uint_field(w, "ret_type_id", t->type);
@@ -365,7 +365,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 	case BTF_KIND_DATASEC: {
 		const struct btf_var_secinfo *v = (const void *)(t + 1);
 		const struct btf_type *vt;
-		__u32 i, vlen = BTF_INFO_VLEN(t->info);
+		__u32 i, vlen = btf_vlen(t);
 
 		if (json_output) {
 			jsonw_uint_field(w, "size", t->size);
diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
index 9dc8425b1789..e4075824343f 100644
--- a/tools/bpf/bpftool/btf_dumper.c
+++ b/tools/bpf/bpftool/btf_dumper.c
@@ -476,8 +476,8 @@ static int btf_dumper_struct(const struct btf_dumper *d, __u32 type_id,
 	if (!t)
 		return -EINVAL;
 
-	kind_flag = BTF_INFO_KFLAG(t->info);
-	vlen = BTF_INFO_VLEN(t->info);
+	kind_flag = btf_kflag(t);
+	vlen = btf_vlen(t);
 	jsonw_start_object(d->jw);
 	m = (struct btf_member *)(t + 1);
 
@@ -535,7 +535,7 @@ static int btf_dumper_datasec(const struct btf_dumper *d, __u32 type_id,
 	if (!t)
 		return -EINVAL;
 
-	vlen = BTF_INFO_VLEN(t->info);
+	vlen = btf_vlen(t);
 	vsi = (struct btf_var_secinfo *)(t + 1);
 
 	jsonw_start_object(d->jw);
@@ -557,7 +557,7 @@ static int btf_dumper_do_type(const struct btf_dumper *d, __u32 type_id,
 {
 	const struct btf_type *t = btf__type_by_id(d->btf, type_id);
 
-	switch (BTF_INFO_KIND(t->info)) {
+	switch (btf_kind(t)) {
 	case BTF_KIND_INT:
 		return btf_dumper_int(t, bit_offset, data, d->jw,
 				     d->is_plain_text);
@@ -631,7 +631,7 @@ static int __btf_dumper_type_only(const struct btf *btf, __u32 type_id,
 
 	t = btf__type_by_id(btf, type_id);
 
-	switch (BTF_INFO_KIND(t->info)) {
+	switch (btf_kind(t)) {
 	case BTF_KIND_INT:
 	case BTF_KIND_TYPEDEF:
 	case BTF_KIND_FLOAT:
@@ -661,7 +661,7 @@ static int __btf_dumper_type_only(const struct btf *btf, __u32 type_id,
 		break;
 	case BTF_KIND_FWD:
 		BTF_PRINT_ARG("%s %s ",
-			      BTF_INFO_KFLAG(t->info) ? "union" : "struct",
+			      btf_kflag(t) ? "union" : "struct",
 			      btf__name_by_offset(btf, t->name_off));
 		break;
 	case BTF_KIND_VOLATILE:
@@ -718,7 +718,7 @@ static int btf_dump_func(const struct btf *btf, char *func_sig,
 		BTF_PRINT_ARG("%s(", btf__name_by_offset(btf, func->name_off));
 	else
 		BTF_PRINT_ARG("(");
-	vlen = BTF_INFO_VLEN(func_proto->info);
+	vlen = btf_vlen(func_proto);
 	for (i = 0; i < vlen; i++) {
 		struct btf_param *arg = &((struct btf_param *)(func_proto + 1))[i];
 
-- 
2.43.0


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

* Re: [PATCH] bpftool: use btf_vlen()/btf_kind()/btf_kflag() helpers consistently
  2026-07-01  6:25 [PATCH] bpftool: use btf_vlen()/btf_kind()/btf_kflag() helpers consistently luoliang
@ 2026-07-01 12:58 ` Quentin Monnet
  2026-07-01 15:05 ` KaFai Wan
  2026-07-02  1:23 ` [PATCH v2] " luoliang
  2 siblings, 0 replies; 7+ messages in thread
From: Quentin Monnet @ 2026-07-01 12:58 UTC (permalink / raw)
  To: luoliang; +Cc: Alexei Starovoitov, Andrii Nakryiko, bpf, linux-kernel

On 01/07/2026 07:25, luoliang@kylinos.cn wrote:
> From: luoliang <luoliang@kylinos.cn>
> 
> The btf_vlen(), btf_kind() and btf_kflag() inline helpers defined in
> tools/lib/bpf/btf.h are thin wrappers around the BTF_INFO_VLEN(),
> BTF_INFO_KIND() and BTF_INFO_KFLAG() UAPI macros - each one simply
> returns the corresponding macro applied to t->info.
> 
> bpftool already uses these helpers in most places, but 13 call sites
> in btf.c and btf_dumper.c still open-code the raw macros. Use the
> helpers consistently, matching the rest of bpftool as well as libbpf.
> 
> No functional change.
> 
> Signed-off-by: Liang Luo <luoliang@kylinos.cn>


Reviewed-by: Quentin Monnet <qmo@kernel.org>

Thank you

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

* Re: [PATCH] bpftool: use btf_vlen()/btf_kind()/btf_kflag() helpers consistently
  2026-07-01  6:25 [PATCH] bpftool: use btf_vlen()/btf_kind()/btf_kflag() helpers consistently luoliang
  2026-07-01 12:58 ` Quentin Monnet
@ 2026-07-01 15:05 ` KaFai Wan
  2026-07-01 20:03   ` Andrii Nakryiko
  2026-07-02  1:23 ` [PATCH v2] " luoliang
  2 siblings, 1 reply; 7+ messages in thread
From: KaFai Wan @ 2026-07-01 15:05 UTC (permalink / raw)
  To: luoliang, Quentin Monnet
  Cc: Alexei Starovoitov, Andrii Nakryiko, bpf, linux-kernel

On Wed, 2026-07-01 at 14:25 +0800, luoliang@kylinos.cn wrote:
> From: luoliang <luoliang@kylinos.cn>
> 
> The btf_vlen(), btf_kind() and btf_kflag() inline helpers defined in
> tools/lib/bpf/btf.h are thin wrappers around the BTF_INFO_VLEN(),
> BTF_INFO_KIND() and BTF_INFO_KFLAG() UAPI macros - each one simply
> returns the corresponding macro applied to t->info.
> 
> bpftool already uses these helpers in most places, but 13 call sites
> in btf.c and btf_dumper.c still open-code the raw macros. Use the
> helpers consistently, matching the rest of bpftool as well as libbpf.
> 
> No functional change.
> 
> Signed-off-by: Liang Luo <luoliang@kylinos.cn>
> ---
>  tools/bpf/bpftool/btf.c        | 12 ++++++------
>  tools/bpf/bpftool/btf_dumper.c | 14 +++++++-------
>  2 files changed, 13 insertions(+), 13 deletions(-)
> 
> diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
> index 6ef908adf3a4..24e4cb600b3f 100644
> --- a/tools/bpf/bpftool/btf.c
> +++ b/tools/bpf/bpftool/btf.c
> @@ -179,7 +179,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
>  	case BTF_KIND_STRUCT:
>  	case BTF_KIND_UNION: {
>  		const struct btf_member *m = (const void *)(t + 1);
> -		__u32 i, vlen = BTF_INFO_VLEN(t->info);
> +		__u32 i, vlen = btf_vlen(t);
>  
>  		if (json_output) {
>  			jsonw_uint_field(w, "size", t->size);
> @@ -193,7 +193,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
>  			const char *name = btf_str(btf, m->name_off);
>  			__u32 bit_off, bit_sz;
>  
> -			if (BTF_INFO_KFLAG(t->info)) {
> +			if (btf_kflag(t)) {
>  				bit_off = BTF_MEMBER_BIT_OFFSET(m->offset);
>  				bit_sz = BTF_MEMBER_BITFIELD_SIZE(m->offset);
>  			} else {
> @@ -224,7 +224,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
>  	}
>  	case BTF_KIND_ENUM: {
>  		const struct btf_enum *v = (const void *)(t + 1);
> -		__u32 i, vlen = BTF_INFO_VLEN(t->info);
> +		__u32 i, vlen = btf_vlen(t);
>  		const char *encoding;
>  
>  		encoding = btf_kflag(t) ? "SIGNED" : "UNSIGNED";
> @@ -300,7 +300,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
>  		break;
>  	}
>  	case BTF_KIND_FWD: {
> -		const char *fwd_kind = BTF_INFO_KFLAG(t->info) ? "union"
> +		const char *fwd_kind = btf_kflag(t) ? "union"
>  							       : "struct";
nit: coding style, and can be one line.
>  
>  		if (json_output)
> @@ -322,7 +322,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
>  	}
>  	case BTF_KIND_FUNC_PROTO: {
>  		const struct btf_param *p = (const void *)(t + 1);
> -		__u32 i, vlen = BTF_INFO_VLEN(t->info);
> +		__u32 i, vlen = btf_vlen(t);
>  
>  		if (json_output) {
>  			jsonw_uint_field(w, "ret_type_id", t->type);
> @@ -365,7 +365,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
>  	case BTF_KIND_DATASEC: {
>  		const struct btf_var_secinfo *v = (const void *)(t + 1);
>  		const struct btf_type *vt;
> -		__u32 i, vlen = BTF_INFO_VLEN(t->info);
> +		__u32 i, vlen = btf_vlen(t);
>  
>  		if (json_output) {
>  			jsonw_uint_field(w, "size", t->size);
> diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
> index 9dc8425b1789..e4075824343f 100644
> --- a/tools/bpf/bpftool/btf_dumper.c
> +++ b/tools/bpf/bpftool/btf_dumper.c
> @@ -476,8 +476,8 @@ static int btf_dumper_struct(const struct btf_dumper *d, __u32 type_id,
>  	if (!t)
>  		return -EINVAL;
>  
> -	kind_flag = BTF_INFO_KFLAG(t->info);
> -	vlen = BTF_INFO_VLEN(t->info);
> +	kind_flag = btf_kflag(t);
> +	vlen = btf_vlen(t);
>  	jsonw_start_object(d->jw);
>  	m = (struct btf_member *)(t + 1);
>  
> @@ -535,7 +535,7 @@ static int btf_dumper_datasec(const struct btf_dumper *d, __u32 type_id,
>  	if (!t)
>  		return -EINVAL;
>  
> -	vlen = BTF_INFO_VLEN(t->info);
> +	vlen = btf_vlen(t);
>  	vsi = (struct btf_var_secinfo *)(t + 1);
>  
>  	jsonw_start_object(d->jw);
> @@ -557,7 +557,7 @@ static int btf_dumper_do_type(const struct btf_dumper *d, __u32 type_id,
>  {
>  	const struct btf_type *t = btf__type_by_id(d->btf, type_id);
>  
> -	switch (BTF_INFO_KIND(t->info)) {
> +	switch (btf_kind(t)) {
>  	case BTF_KIND_INT:
>  		return btf_dumper_int(t, bit_offset, data, d->jw,
>  				     d->is_plain_text);
> @@ -631,7 +631,7 @@ static int __btf_dumper_type_only(const struct btf *btf, __u32 type_id,
>  
>  	t = btf__type_by_id(btf, type_id);
>  
> -	switch (BTF_INFO_KIND(t->info)) {
> +	switch (btf_kind(t)) {
>  	case BTF_KIND_INT:
>  	case BTF_KIND_TYPEDEF:
>  	case BTF_KIND_FLOAT:
> @@ -661,7 +661,7 @@ static int __btf_dumper_type_only(const struct btf *btf, __u32 type_id,
>  		break;
>  	case BTF_KIND_FWD:
>  		BTF_PRINT_ARG("%s %s ",
> -			      BTF_INFO_KFLAG(t->info) ? "union" : "struct",
> +			      btf_kflag(t) ? "union" : "struct",
>  			      btf__name_by_offset(btf, t->name_off));
>  		break;
>  	case BTF_KIND_VOLATILE:
> @@ -718,7 +718,7 @@ static int btf_dump_func(const struct btf *btf, char *func_sig,
>  		BTF_PRINT_ARG("%s(", btf__name_by_offset(btf, func->name_off));
>  	else
>  		BTF_PRINT_ARG("(");
> -	vlen = BTF_INFO_VLEN(func_proto->info);
> +	vlen = btf_vlen(func_proto);
>  	for (i = 0; i < vlen; i++) {
>  		struct btf_param *arg = &((struct btf_param *)(func_proto + 1))[i];
>  


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

* Re: [PATCH] bpftool: use btf_vlen()/btf_kind()/btf_kflag() helpers consistently
  2026-07-01 15:05 ` KaFai Wan
@ 2026-07-01 20:03   ` Andrii Nakryiko
  2026-07-02  1:46     ` luoliang
  0 siblings, 1 reply; 7+ messages in thread
From: Andrii Nakryiko @ 2026-07-01 20:03 UTC (permalink / raw)
  To: KaFai Wan
  Cc: luoliang, Quentin Monnet, Alexei Starovoitov, Andrii Nakryiko,
	bpf, linux-kernel

On Wed, Jul 1, 2026 at 8:05 AM KaFai Wan <kafai.wan@linux.dev> wrote:
>
> On Wed, 2026-07-01 at 14:25 +0800, luoliang@kylinos.cn wrote:
> > From: luoliang <luoliang@kylinos.cn>
> >
> > The btf_vlen(), btf_kind() and btf_kflag() inline helpers defined in
> > tools/lib/bpf/btf.h are thin wrappers around the BTF_INFO_VLEN(),
> > BTF_INFO_KIND() and BTF_INFO_KFLAG() UAPI macros - each one simply
> > returns the corresponding macro applied to t->info.
> >
> > bpftool already uses these helpers in most places, but 13 call sites
> > in btf.c and btf_dumper.c still open-code the raw macros. Use the
> > helpers consistently, matching the rest of bpftool as well as libbpf.
> >
> > No functional change.
> >
> > Signed-off-by: Liang Luo <luoliang@kylinos.cn>
> > ---
> >  tools/bpf/bpftool/btf.c        | 12 ++++++------
> >  tools/bpf/bpftool/btf_dumper.c | 14 +++++++-------
> >  2 files changed, 13 insertions(+), 13 deletions(-)
> >
> > diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
> > index 6ef908adf3a4..24e4cb600b3f 100644
> > --- a/tools/bpf/bpftool/btf.c
> > +++ b/tools/bpf/bpftool/btf.c
> > @@ -179,7 +179,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
> >       case BTF_KIND_STRUCT:
> >       case BTF_KIND_UNION: {
> >               const struct btf_member *m = (const void *)(t + 1);
> > -             __u32 i, vlen = BTF_INFO_VLEN(t->info);
> > +             __u32 i, vlen = btf_vlen(t);
> >
> >               if (json_output) {
> >                       jsonw_uint_field(w, "size", t->size);
> > @@ -193,7 +193,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
> >                       const char *name = btf_str(btf, m->name_off);
> >                       __u32 bit_off, bit_sz;
> >
> > -                     if (BTF_INFO_KFLAG(t->info)) {
> > +                     if (btf_kflag(t)) {
> >                               bit_off = BTF_MEMBER_BIT_OFFSET(m->offset);
> >                               bit_sz = BTF_MEMBER_BITFIELD_SIZE(m->offset);
> >                       } else {
> > @@ -224,7 +224,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
> >       }
> >       case BTF_KIND_ENUM: {
> >               const struct btf_enum *v = (const void *)(t + 1);
> > -             __u32 i, vlen = BTF_INFO_VLEN(t->info);
> > +             __u32 i, vlen = btf_vlen(t);
> >               const char *encoding;
> >
> >               encoding = btf_kflag(t) ? "SIGNED" : "UNSIGNED";
> > @@ -300,7 +300,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
> >               break;
> >       }
> >       case BTF_KIND_FWD: {
> > -             const char *fwd_kind = BTF_INFO_KFLAG(t->info) ? "union"
> > +             const char *fwd_kind = btf_kflag(t) ? "union"
> >                                                              : "struct";
> nit: coding style, and can be one line.

this is the only line that would benefit from a tiny amount of human
touch and judgement call, and yet...

pw-bot: cr


> >
> >               if (json_output)
> > @@ -322,7 +322,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
> >       }
> >       case BTF_KIND_FUNC_PROTO: {
> >               const struct btf_param *p = (const void *)(t + 1);
> > -             __u32 i, vlen = BTF_INFO_VLEN(t->info);
> > +             __u32 i, vlen = btf_vlen(t);
> >
> >               if (json_output) {
> >                       jsonw_uint_field(w, "ret_type_id", t->type);
> > @@ -365,7 +365,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
> >       case BTF_KIND_DATASEC: {
> >               const struct btf_var_secinfo *v = (const void *)(t + 1);
> >               const struct btf_type *vt;
> > -             __u32 i, vlen = BTF_INFO_VLEN(t->info);
> > +             __u32 i, vlen = btf_vlen(t);
> >
> >               if (json_output) {
> >                       jsonw_uint_field(w, "size", t->size);
> > diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
> > index 9dc8425b1789..e4075824343f 100644
> > --- a/tools/bpf/bpftool/btf_dumper.c
> > +++ b/tools/bpf/bpftool/btf_dumper.c
> > @@ -476,8 +476,8 @@ static int btf_dumper_struct(const struct btf_dumper *d, __u32 type_id,
> >       if (!t)
> >               return -EINVAL;
> >
> > -     kind_flag = BTF_INFO_KFLAG(t->info);
> > -     vlen = BTF_INFO_VLEN(t->info);
> > +     kind_flag = btf_kflag(t);
> > +     vlen = btf_vlen(t);
> >       jsonw_start_object(d->jw);
> >       m = (struct btf_member *)(t + 1);
> >
> > @@ -535,7 +535,7 @@ static int btf_dumper_datasec(const struct btf_dumper *d, __u32 type_id,
> >       if (!t)
> >               return -EINVAL;
> >
> > -     vlen = BTF_INFO_VLEN(t->info);
> > +     vlen = btf_vlen(t);
> >       vsi = (struct btf_var_secinfo *)(t + 1);
> >
> >       jsonw_start_object(d->jw);
> > @@ -557,7 +557,7 @@ static int btf_dumper_do_type(const struct btf_dumper *d, __u32 type_id,
> >  {
> >       const struct btf_type *t = btf__type_by_id(d->btf, type_id);
> >
> > -     switch (BTF_INFO_KIND(t->info)) {
> > +     switch (btf_kind(t)) {
> >       case BTF_KIND_INT:
> >               return btf_dumper_int(t, bit_offset, data, d->jw,
> >                                    d->is_plain_text);
> > @@ -631,7 +631,7 @@ static int __btf_dumper_type_only(const struct btf *btf, __u32 type_id,
> >
> >       t = btf__type_by_id(btf, type_id);
> >
> > -     switch (BTF_INFO_KIND(t->info)) {
> > +     switch (btf_kind(t)) {
> >       case BTF_KIND_INT:
> >       case BTF_KIND_TYPEDEF:
> >       case BTF_KIND_FLOAT:
> > @@ -661,7 +661,7 @@ static int __btf_dumper_type_only(const struct btf *btf, __u32 type_id,
> >               break;
> >       case BTF_KIND_FWD:
> >               BTF_PRINT_ARG("%s %s ",
> > -                           BTF_INFO_KFLAG(t->info) ? "union" : "struct",
> > +                           btf_kflag(t) ? "union" : "struct",
> >                             btf__name_by_offset(btf, t->name_off));
> >               break;
> >       case BTF_KIND_VOLATILE:
> > @@ -718,7 +718,7 @@ static int btf_dump_func(const struct btf *btf, char *func_sig,
> >               BTF_PRINT_ARG("%s(", btf__name_by_offset(btf, func->name_off));
> >       else
> >               BTF_PRINT_ARG("(");
> > -     vlen = BTF_INFO_VLEN(func_proto->info);
> > +     vlen = btf_vlen(func_proto);
> >       for (i = 0; i < vlen; i++) {
> >               struct btf_param *arg = &((struct btf_param *)(func_proto + 1))[i];
> >
>

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

* [PATCH v2] bpftool: use btf_vlen()/btf_kind()/btf_kflag() helpers consistently
  2026-07-01  6:25 [PATCH] bpftool: use btf_vlen()/btf_kind()/btf_kflag() helpers consistently luoliang
  2026-07-01 12:58 ` Quentin Monnet
  2026-07-01 15:05 ` KaFai Wan
@ 2026-07-02  1:23 ` luoliang
  2026-07-02 16:30   ` patchwork-bot+netdevbpf
  2 siblings, 1 reply; 7+ messages in thread
From: luoliang @ 2026-07-02  1:23 UTC (permalink / raw)
  To: Quentin Monnet
  Cc: Alexei Starovoitov, Andrii Nakryiko, KaFai Wan, bpf, linux-kernel,
	Liang Luo

From: luoliang <luoliang@kylinos.cn>

The btf_vlen(), btf_kind() and btf_kflag() inline helpers defined in
tools/lib/bpf/btf.h are thin wrappers around the BTF_INFO_VLEN(),
BTF_INFO_KIND() and BTF_INFO_KFLAG() UAPI macros - each one simply
returns the corresponding macro applied to t->info.

bpftool already uses these helpers in most places, but 13 call sites
in btf.c and btf_dumper.c still open-code the raw macros. Use the
helpers consistently, matching the rest of bpftool as well as libbpf.

No functional change.

Signed-off-by: Liang Luo <luoliang@kylinos.cn>
Reviewed-by: Quentin Monnet <qmo@kernel.org>
---

Changes in v2:
- Collapse the BTF_KIND_FWD fwd_kind assignment to a single line now
  that btf_kflag(t) is short enough, as suggested by KaFai Wan and
  requested by Andrii Nakryiko.
---
 tools/bpf/bpftool/btf.c        | 13 ++++++-------
 tools/bpf/bpftool/btf_dumper.c | 14 +++++++-------
 2 files changed, 13 insertions(+), 14 deletions(-)

diff --git a/tools/bpf/bpftool/btf.c b/tools/bpf/bpftool/btf.c
index 6ef908adf3a4..c9589026da8d 100644
--- a/tools/bpf/bpftool/btf.c
+++ b/tools/bpf/bpftool/btf.c
@@ -179,7 +179,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 	case BTF_KIND_STRUCT:
 	case BTF_KIND_UNION: {
 		const struct btf_member *m = (const void *)(t + 1);
-		__u32 i, vlen = BTF_INFO_VLEN(t->info);
+		__u32 i, vlen = btf_vlen(t);
 
 		if (json_output) {
 			jsonw_uint_field(w, "size", t->size);
@@ -193,7 +193,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 			const char *name = btf_str(btf, m->name_off);
 			__u32 bit_off, bit_sz;
 
-			if (BTF_INFO_KFLAG(t->info)) {
+			if (btf_kflag(t)) {
 				bit_off = BTF_MEMBER_BIT_OFFSET(m->offset);
 				bit_sz = BTF_MEMBER_BITFIELD_SIZE(m->offset);
 			} else {
@@ -224,7 +224,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 	}
 	case BTF_KIND_ENUM: {
 		const struct btf_enum *v = (const void *)(t + 1);
-		__u32 i, vlen = BTF_INFO_VLEN(t->info);
+		__u32 i, vlen = btf_vlen(t);
 		const char *encoding;
 
 		encoding = btf_kflag(t) ? "SIGNED" : "UNSIGNED";
@@ -300,8 +300,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 		break;
 	}
 	case BTF_KIND_FWD: {
-		const char *fwd_kind = BTF_INFO_KFLAG(t->info) ? "union"
-							       : "struct";
+		const char *fwd_kind = btf_kflag(t) ? "union" : "struct";
 
 		if (json_output)
 			jsonw_string_field(w, "fwd_kind", fwd_kind);
@@ -322,7 +321,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 	}
 	case BTF_KIND_FUNC_PROTO: {
 		const struct btf_param *p = (const void *)(t + 1);
-		__u32 i, vlen = BTF_INFO_VLEN(t->info);
+		__u32 i, vlen = btf_vlen(t);
 
 		if (json_output) {
 			jsonw_uint_field(w, "ret_type_id", t->type);
@@ -365,7 +364,7 @@ static int dump_btf_type(const struct btf *btf, __u32 id,
 	case BTF_KIND_DATASEC: {
 		const struct btf_var_secinfo *v = (const void *)(t + 1);
 		const struct btf_type *vt;
-		__u32 i, vlen = BTF_INFO_VLEN(t->info);
+		__u32 i, vlen = btf_vlen(t);
 
 		if (json_output) {
 			jsonw_uint_field(w, "size", t->size);
diff --git a/tools/bpf/bpftool/btf_dumper.c b/tools/bpf/bpftool/btf_dumper.c
index 9dc8425b1789..e4075824343f 100644
--- a/tools/bpf/bpftool/btf_dumper.c
+++ b/tools/bpf/bpftool/btf_dumper.c
@@ -476,8 +476,8 @@ static int btf_dumper_struct(const struct btf_dumper *d, __u32 type_id,
 	if (!t)
 		return -EINVAL;
 
-	kind_flag = BTF_INFO_KFLAG(t->info);
-	vlen = BTF_INFO_VLEN(t->info);
+	kind_flag = btf_kflag(t);
+	vlen = btf_vlen(t);
 	jsonw_start_object(d->jw);
 	m = (struct btf_member *)(t + 1);
 
@@ -535,7 +535,7 @@ static int btf_dumper_datasec(const struct btf_dumper *d, __u32 type_id,
 	if (!t)
 		return -EINVAL;
 
-	vlen = BTF_INFO_VLEN(t->info);
+	vlen = btf_vlen(t);
 	vsi = (struct btf_var_secinfo *)(t + 1);
 
 	jsonw_start_object(d->jw);
@@ -557,7 +557,7 @@ static int btf_dumper_do_type(const struct btf_dumper *d, __u32 type_id,
 {
 	const struct btf_type *t = btf__type_by_id(d->btf, type_id);
 
-	switch (BTF_INFO_KIND(t->info)) {
+	switch (btf_kind(t)) {
 	case BTF_KIND_INT:
 		return btf_dumper_int(t, bit_offset, data, d->jw,
 				     d->is_plain_text);
@@ -631,7 +631,7 @@ static int __btf_dumper_type_only(const struct btf *btf, __u32 type_id,
 
 	t = btf__type_by_id(btf, type_id);
 
-	switch (BTF_INFO_KIND(t->info)) {
+	switch (btf_kind(t)) {
 	case BTF_KIND_INT:
 	case BTF_KIND_TYPEDEF:
 	case BTF_KIND_FLOAT:
@@ -661,7 +661,7 @@ static int __btf_dumper_type_only(const struct btf *btf, __u32 type_id,
 		break;
 	case BTF_KIND_FWD:
 		BTF_PRINT_ARG("%s %s ",
-			      BTF_INFO_KFLAG(t->info) ? "union" : "struct",
+			      btf_kflag(t) ? "union" : "struct",
 			      btf__name_by_offset(btf, t->name_off));
 		break;
 	case BTF_KIND_VOLATILE:
@@ -718,7 +718,7 @@ static int btf_dump_func(const struct btf *btf, char *func_sig,
 		BTF_PRINT_ARG("%s(", btf__name_by_offset(btf, func->name_off));
 	else
 		BTF_PRINT_ARG("(");
-	vlen = BTF_INFO_VLEN(func_proto->info);
+	vlen = btf_vlen(func_proto);
 	for (i = 0; i < vlen; i++) {
 		struct btf_param *arg = &((struct btf_param *)(func_proto + 1))[i];
 
-- 
2.43.0


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

* Re: [PATCH] bpftool: use btf_vlen()/btf_kind()/btf_kflag() helpers consistently
  2026-07-01 20:03   ` Andrii Nakryiko
@ 2026-07-02  1:46     ` luoliang
  0 siblings, 0 replies; 7+ messages in thread
From: luoliang @ 2026-07-02  1:46 UTC (permalink / raw)
  To: Andrii Nakryiko
  Cc: KaFai Wan, Quentin Monnet, Alexei Starovoitov, bpf, linux-kernel,
	Liang Luo

On Wed, 1 Jul 2026 13:03:51 -0700, Andrii Nakryiko <andrii@nakryiko@gmail.com> wrote:
> this is the only line that would benefit from a tiny amount of human
> touch and judgement call, and yet...
>
> pw-bot: cr

Thanks Andrii (and KaFai for spotting this). Folded into v2, sent as a
reply to the original patch.

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

* Re: [PATCH v2] bpftool: use btf_vlen()/btf_kind()/btf_kflag() helpers consistently
  2026-07-02  1:23 ` [PATCH v2] " luoliang
@ 2026-07-02 16:30   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2026-07-02 16:30 UTC (permalink / raw)
  To: None; +Cc: qmo, ast, andrii, kafai.wan, bpf, linux-kernel

Hello:

This patch was applied to bpf/bpf-next.git (master)
by Andrii Nakryiko <andrii@kernel.org>:

On Thu,  2 Jul 2026 09:23:11 +0800 you wrote:
> From: luoliang <luoliang@kylinos.cn>
> 
> The btf_vlen(), btf_kind() and btf_kflag() inline helpers defined in
> tools/lib/bpf/btf.h are thin wrappers around the BTF_INFO_VLEN(),
> BTF_INFO_KIND() and BTF_INFO_KFLAG() UAPI macros - each one simply
> returns the corresponding macro applied to t->info.
> 
> [...]

Here is the summary with links:
  - [v2] bpftool: use btf_vlen()/btf_kind()/btf_kflag() helpers consistently
    https://git.kernel.org/bpf/bpf-next/c/bb4e90e91ba1

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

end of thread, other threads:[~2026-07-02 16:30 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-01  6:25 [PATCH] bpftool: use btf_vlen()/btf_kind()/btf_kflag() helpers consistently luoliang
2026-07-01 12:58 ` Quentin Monnet
2026-07-01 15:05 ` KaFai Wan
2026-07-01 20:03   ` Andrii Nakryiko
2026-07-02  1:46     ` luoliang
2026-07-02  1:23 ` [PATCH v2] " luoliang
2026-07-02 16:30   ` 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