aboutsummaryrefslogtreecommitdiff
path: root/tools/lib
diff options
context:
space:
mode:
authorGravatar Andrii Nakryiko <andrii@kernel.org> 2022-12-12 13:15:00 -0800
committerGravatar Daniel Borkmann <daniel@iogearbox.net> 2022-12-15 00:05:12 +0100
commit872aec4b5f635d94111d48ec3c57fbe078d64e7d (patch)
tree092064744a5e4e5afedb3e3a866a08d4a6290b13 /tools/lib
parentlibbpf: Optimized return value in libbpf_strerror when errno is libbpf errno (diff)
downloadlinux-872aec4b5f635d94111d48ec3c57fbe078d64e7d.tar.gz
linux-872aec4b5f635d94111d48ec3c57fbe078d64e7d.tar.bz2
linux-872aec4b5f635d94111d48ec3c57fbe078d64e7d.zip
libbpf: Fix single-line struct definition output in btf_dump
btf_dump APIs emit unnecessary tabs when emitting struct/union definition that fits on the single line. Before this patch we'd get: struct blah {<tab>}; This patch fixes this and makes sure that we get more natural: struct blah {}; Fixes: 44a726c3f23c ("bpftool: Print newline before '}' for struct with padding only fields") Signed-off-by: Andrii Nakryiko <andrii@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Link: https://lore.kernel.org/bpf/20221212211505.558851-2-andrii@kernel.org
Diffstat (limited to 'tools/lib')
-rw-r--r--tools/lib/bpf/btf_dump.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index deb2bc9a0a7b..69e80ee5f70e 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -959,9 +959,12 @@ static void btf_dump_emit_struct_def(struct btf_dump *d,
* Keep `struct empty {}` on a single line,
* only print newline when there are regular or padding fields.
*/
- if (vlen || t->size)
+ if (vlen || t->size) {
btf_dump_printf(d, "\n");
- btf_dump_printf(d, "%s}", pfx(lvl));
+ btf_dump_printf(d, "%s}", pfx(lvl));
+ } else {
+ btf_dump_printf(d, "}");
+ }
if (packed)
btf_dump_printf(d, " __attribute__((packed))");
}