summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEduard Zingerman <eddyz87@gmail.com>2022-10-01 13:44:24 +0300
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2023-04-20 13:10:24 +0300
commit59dc9767cefbe4b931054bfab39d6aab0bb040f5 (patch)
treed427d0ded98addc4178cbae1c9d9b2e569d5206e
parent2765aca637761db530d7a285bdb85ea1a10318af (diff)
downloadlinux-59dc9767cefbe4b931054bfab39d6aab0bb040f5.tar.xz
bpftool: Print newline before '}' for struct with padding only fields
[ Upstream commit 44a726c3f23cf762ef4ce3c1709aefbcbe97f62c ] 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> Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Link: https://lore.kernel.org/bpf/20221001104425.415768-1-eddyz87@gmail.com Signed-off-by: Sasha Levin <sashal@kernel.org>
-rw-r--r--tools/lib/bpf/btf_dump.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 558d34fbd331..6a8d8ed34b76 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -969,7 +969,11 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
if (is_struct)
btf_dump_emit_bit_padding(d, off, t->size * 8, align, false, 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)