From: Andrii Nakryiko Date: Mon, 12 Dec 2022 21:15:00 +0000 (-0800) Subject: libbpf: Fix single-line struct definition output in btf_dump X-Git-Tag: v6.1.37~2210 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8a5342878429f94ac6086e531f9b404be6837c0e;p=platform%2Fkernel%2Flinux-starfive.git libbpf: Fix single-line struct definition output in btf_dump [ Upstream commit 872aec4b5f635d94111d48ec3c57fbe078d64e7d ] 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 {}; 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 Signed-off-by: Daniel Borkmann Link: https://lore.kernel.org/bpf/20221212211505.558851-2-andrii@kernel.org Signed-off-by: Sasha Levin --- diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c index 80a15a6..4cd1d49 100644 --- a/tools/lib/bpf/btf_dump.c +++ b/tools/lib/bpf/btf_dump.c @@ -1015,9 +1015,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))"); }