All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' for struct with padding only fields
@ 2022-10-01 10:44 Eduard Zingerman
  2022-10-01 10:44 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test btf dump " Eduard Zingerman
  2022-10-05 22:30 ` [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' " patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Eduard Zingerman @ 2022-10-01 10:44 UTC (permalink / raw)
  To: bpf, ast, andrii, daniel, kernel-team; +Cc: Eduard Zingerman

btf_dump_emit_struct_def attempts to print empty structures at a
single line, e.g. `struct empty {}`. However, it has to account for a
case when there are no regular but some padding fields in the struct.
In such case `vlen` would be zero, but size would be non-zero.

E.g. here is struct bpf_timer from vmlinux.h before this patch:

 struct bpf_timer {
 	long: 64;
	long: 64;};

And after this patch:

 struct bpf_dynptr {
 	long: 64;
	long: 64;
 };

Signed-off-by: Eduard Zingerman <eddyz87@gmail.com>
---
 tools/lib/bpf/btf_dump.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 4221f73a74d0..e4da6de68d8f 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -944,7 +944,11 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
 					  lvl + 1);
 	}
 
-	if (vlen)
+	/*
+	 * Keep `struct empty {}` on a single line,
+	 * only print newline when there are regular or padding fields.
+	 */
+	if (vlen || t->size)
 		btf_dump_printf(d, "\n");
 	btf_dump_printf(d, "%s}", pfx(lvl));
 	if (packed)
-- 
2.37.3


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

end of thread, other threads:[~2022-10-05 22:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-01 10:44 [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' for struct with padding only fields Eduard Zingerman
2022-10-01 10:44 ` [PATCH bpf-next v2 2/2] selftests/bpf: Test btf dump " Eduard Zingerman
2022-10-05 22:30 ` [PATCH bpf-next v2 1/2] bpftool: Print newline before '}' " patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.