stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 6.12.y] libbpf: Prevent compiler warnings/errors
@ 2025-04-11  3:36 He Zhe
  2025-04-13 16:47 ` Sasha Levin
  0 siblings, 1 reply; 2+ messages in thread
From: He Zhe @ 2025-04-11  3:36 UTC (permalink / raw)
  To: stable; +Cc: bpf, ezulian, andrii, jolsa, acme, zhe.he

From: Eder Zulian <ezulian@redhat.com>

commit 7f4ec77f3fee41dd6a41f03a40703889e6e8f7b2 upstream.

Initialize 'new_off' and 'pad_bits' to 0 and 'pad_type' to  NULL in
btf_dump_emit_bit_padding to prevent compiler warnings/errors which are
observed when compiling with 'EXTRA_CFLAGS=-g -Og' options, but do not
happen when compiling with current default options.

For example, when compiling libbpf with

  $ make "EXTRA_CFLAGS=-g -Og" -C tools/lib/bpf/ clean all

Clang version 17.0.6 and GCC 13.3.1 fail to compile btf_dump.c due to
following errors:

  btf_dump.c: In function ‘btf_dump_emit_bit_padding’:
  btf_dump.c:903:42: error: ‘new_off’ may be used uninitialized [-Werror=maybe-uninitialized]
    903 |         if (new_off > cur_off && new_off <= next_off) {
        |                                  ~~~~~~~~^~~~~~~~~~~
  btf_dump.c:870:13: note: ‘new_off’ was declared here
    870 |         int new_off, pad_bits, bits, i;
        |             ^~~~~~~
  btf_dump.c:917:25: error: ‘pad_type’ may be used uninitialized [-Werror=maybe-uninitialized]
    917 |                         btf_dump_printf(d, "\n%s%s: %d;", pfx(lvl), pad_type,
        |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    918 |                                         in_bitfield ? new_off - cur_off : 0);
        |                                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  btf_dump.c:871:21: note: ‘pad_type’ was declared here
    871 |         const char *pad_type;
        |                     ^~~~~~~~
  btf_dump.c:930:20: error: ‘pad_bits’ may be used uninitialized [-Werror=maybe-uninitialized]
    930 |                 if (bits == pad_bits) {
        |                    ^
  btf_dump.c:870:22: note: ‘pad_bits’ was declared here
    870 |         int new_off, pad_bits, bits, i;
        |                      ^~~~~~~~
  cc1: all warnings being treated as errors

Signed-off-by: Eder Zulian <ezulian@redhat.com>
Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Link: https://lore.kernel.org/bpf/20241022172329.3871958-3-ezulian@redhat.com
Signed-off-by: He Zhe <zhe.he@windriver.com>
Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com>
---
Build test passed.
---
 tools/lib/bpf/btf_dump.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/lib/bpf/btf_dump.c b/tools/lib/bpf/btf_dump.c
index 0a7327541c17..46cce18c8308 100644
--- a/tools/lib/bpf/btf_dump.c
+++ b/tools/lib/bpf/btf_dump.c
@@ -867,8 +867,8 @@ static void btf_dump_emit_bit_padding(const struct btf_dump *d,
 	} pads[] = {
 		{"long", d->ptr_sz * 8}, {"int", 32}, {"short", 16}, {"char", 8}
 	};
-	int new_off, pad_bits, bits, i;
-	const char *pad_type;
+	int new_off = 0, pad_bits = 0, bits, i;
+	const char *pad_type = NULL;
 
 	if (cur_off >= next_off)
 		return; /* no gap */
-- 
2.34.1


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

* Re: [PATCH 6.12.y] libbpf: Prevent compiler warnings/errors
  2025-04-11  3:36 [PATCH 6.12.y] libbpf: Prevent compiler warnings/errors He Zhe
@ 2025-04-13 16:47 ` Sasha Levin
  0 siblings, 0 replies; 2+ messages in thread
From: Sasha Levin @ 2025-04-13 16:47 UTC (permalink / raw)
  To: stable; +Cc: He Zhe, Sasha Levin

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected.
No action required from the submitter.

The upstream commit SHA1 provided is correct: 7f4ec77f3fee41dd6a41f03a40703889e6e8f7b2

WARNING: Author mismatch between patch and upstream commit:
Backport author: He Zhe<zhe.he@windriver.com>
Commit author: Eder Zulian<ezulian@redhat.com>

Status in newer kernel trees:
6.14.y | Present (exact SHA1)
6.13.y | Present (exact SHA1)

Note: The patch differs from the upstream commit:
---
1:  7f4ec77f3fee4 ! 1:  1a7061fb10c80 libbpf: Prevent compiler warnings/errors
    @@ Metadata
      ## Commit message ##
         libbpf: Prevent compiler warnings/errors
     
    +    commit 7f4ec77f3fee41dd6a41f03a40703889e6e8f7b2 upstream.
    +
         Initialize 'new_off' and 'pad_bits' to 0 and 'pad_type' to  NULL in
         btf_dump_emit_bit_padding to prevent compiler warnings/errors which are
         observed when compiling with 'EXTRA_CFLAGS=-g -Og' options, but do not
    @@ Commit message
         Signed-off-by: Andrii Nakryiko <andrii@kernel.org>
         Acked-by: Jiri Olsa <jolsa@kernel.org>
         Link: https://lore.kernel.org/bpf/20241022172329.3871958-3-ezulian@redhat.com
    +    Signed-off-by: He Zhe <zhe.he@windriver.com>
    +    Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com>
     
      ## tools/lib/bpf/btf_dump.c ##
     @@ tools/lib/bpf/btf_dump.c: static void btf_dump_emit_bit_padding(const struct btf_dump *d,
---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-6.12.y       |  Success    |  Success   |

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

end of thread, other threads:[~2025-04-13 16:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-11  3:36 [PATCH 6.12.y] libbpf: Prevent compiler warnings/errors He Zhe
2025-04-13 16:47 ` Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).