mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Alexei Starovoitov <alexei.starovoitov@gmail.com>,
	Tiezhu Yang <yangtiezhu@loongson.cn>
Cc: Andrii Nakryiko <andrii@kernel.org>, bpf <bpf@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH bpf v1] selftests/bpf: Fix set but not used errors
Date: Fri, 17 Oct 2025 10:40:23 -0700	[thread overview]
Message-ID: <1ce0c35c4c444ba85f753df5b0d0c5cd4870d887.camel@gmail.com> (raw)
In-Reply-To: <CAADnVQJjSNEuX=HJKrD=pefC4C9dQk2aqP+hnRscUEDTntVXyA@mail.gmail.com>

On Fri, 2025-10-17 at 10:20 -0700, Alexei Starovoitov wrote:
> On Fri, Oct 17, 2025 at 2:35 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote:
> >
> > There are some set but not used errors under tools/testing/selftests/bpf
> > when compiling with the latest upstream mainline GCC, add the compiler
> > attribute __maybe_unused for the variables that may be used to fix the
> > errors, compile tested only.
> >
> > Cc: stable@vger.kernel.org
> > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
> > ---
> >  tools/testing/selftests/bpf/map_tests/lpm_trie_map_basic_ops.c | 3 ++-
> >  tools/testing/selftests/bpf/prog_tests/bpf_cookie.c            | 3 ++-
> >  tools/testing/selftests/bpf/prog_tests/find_vma.c              | 3 ++-
> >  tools/testing/selftests/bpf/prog_tests/perf_branches.c         | 3 ++-
> >  tools/testing/selftests/bpf/prog_tests/perf_link.c             | 3 ++-
> >  tools/testing/selftests/bpf/test_maps.h                        | 1 +
> >  tools/testing/selftests/bpf/test_progs.h                       | 1 +
> >  7 files changed, 12 insertions(+), 5 deletions(-)
> >
> > diff --git a/tools/testing/selftests/bpf/map_tests/lpm_trie_map_basic_ops.c b/tools/testing/selftests/bpf/map_tests/lpm_trie_map_basic_ops.c
> > index d32e4edac930..2b8edf996126 100644
> > --- a/tools/testing/selftests/bpf/map_tests/lpm_trie_map_basic_ops.c
> > +++ b/tools/testing/selftests/bpf/map_tests/lpm_trie_map_basic_ops.c
> > @@ -226,7 +226,8 @@ static void test_lpm_order(void)
> >  static void test_lpm_map(int keysize)
> >  {
> >         LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_NO_PREALLOC);
> > -       volatile size_t n_matches, n_matches_after_delete;
> > +       /* To avoid a -Wunused-but-set-variable warning. */
> > +       __maybe_unused volatile size_t n_matches, n_matches_after_delete;
>
> I think it's better to disable the warning instead of hacking the tests.
> Arguably it's a grey zone whether n_matches++ qualifies as a "use".
> It's certainly not a nop, since it's a volatile variable.
>
> pw-bot: cr

Maybe something like below?

--- a/tools/testing/selftests/bpf/map_tests/lpm_trie_map_basic_ops.c
+++ b/tools/testing/selftests/bpf/map_tests/lpm_trie_map_basic_ops.c
@@ -223,6 +223,8 @@ static void test_lpm_order(void)
        tlpm_clear(l2);
 }

+static int print_stats; /* debug knob */
+
 static void test_lpm_map(int keysize)
 {
        LIBBPF_OPTS(bpf_map_create_opts, opts, .map_flags = BPF_F_NO_PREALLOC);
@@ -334,14 +336,14 @@ static void test_lpm_map(int keysize)
        tlpm_clear(list);

        /* With 255 random nodes in the map, we are pretty likely to match
-        * something on every lookup. For statistics, use this:
-        *
-        *     printf("          nodes: %zu\n"
-        *            "        lookups: %zu\n"
-        *            "        matches: %zu\n"
-        *            "matches(delete): %zu\n",
-        *            n_nodes, n_lookups, n_matches, n_matches_after_delete);
+        * something on every lookup.
         */
+       if (print_stats)
+               printf("          nodes: %zu\n"
+                      "        lookups: %zu\n"
+                      "        matches: %zu\n"
+                      "matches(delete): %zu\n",
+                      n_nodes, n_lookups, n_matches, n_matches_after_delete);
 }

  reply	other threads:[~2025-10-17 17:40 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-17  9:21 Tiezhu Yang
2025-10-17 17:20 ` Alexei Starovoitov
2025-10-17 17:40   ` Eduard Zingerman [this message]
2025-10-17 17:43     ` Alexei Starovoitov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1ce0c35c4c444ba85f753df5b0d0c5cd4870d887.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=alexei.starovoitov@gmail.com \
    --cc=andrii@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=yangtiezhu@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®