Patch "bpftool: Print newline before '}' for struct with padding only fields" has been added to the 6.1-stable tree

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This is a note to let you know that I've just added the patch titled

    bpftool: Print newline before '}' for struct with padding only fields

to the 6.1-stable tree which can be found at:
    http://www.kernel.org/git/?p=linux/kernel/git/stable/stable-queue.git;a=summary

The filename of the patch is:
     bpftool-print-newline-before-for-struct-with-padding.patch
and it can be found in the queue-6.1 subdirectory.

If you, or anyone else, feels it should not be added to the stable tree,
please let <stable@xxxxxxxxxxxxxxx> know about it.



commit 292fe1693c8b3cb3bb94efd082b8023eef6dc6e9
Author: Eduard Zingerman <eddyz87@xxxxxxxxx>
Date:   Sat Oct 1 13:44:24 2022 +0300

    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@xxxxxxxxx>
    Signed-off-by: Andrii Nakryiko <andrii@xxxxxxxxxx>
    Link: https://lore.kernel.org/bpf/20221001104425.415768-1-eddyz87@xxxxxxxxx
    Signed-off-by: Sasha Levin <sashal@xxxxxxxxxx>

diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 56102711f395a..80a15a6802094 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -1011,7 +1011,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)



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux