netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] selftests/bpf: initialize duration variable before using
@ 2020-01-23 23:51 Stanislav Fomichev
  2020-01-24  8:54 ` Martin Lau
  2020-01-24 10:11 ` Daniel Borkmann
  0 siblings, 2 replies; 3+ messages in thread
From: Stanislav Fomichev @ 2020-01-23 23:51 UTC (permalink / raw)
  To: netdev, bpf; +Cc: davem, ast, daniel, John Sperbeck, Stanislav Fomichev

From: John Sperbeck <jsperbeck@google.com>

The 'duration' variable is referenced in the CHECK() macro, and there are
some uses of the macro before 'duration' is set.  The clang compiler
(validly) complains about this.

Sample error:

.../selftests/bpf/prog_tests/fexit_test.c:23:6: warning: variable 'duration' is uninitialized when used here [-Wuninitialized]
        if (CHECK(err, "prog_load sched cls", "err %d errno %d\n", err, errno))
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../selftests/bpf/test_progs.h:134:25: note: expanded from macro 'CHECK'
        if (CHECK(err, "prog_load sched cls", "err %d errno %d\n", err, errno))
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        _CHECK(condition, tag, duration, format)
                               ^~~~~~~~

Signed-off-by: John Sperbeck <jsperbeck@google.com>
Signed-off-by: Stanislav Fomichev <sdf@google.com>
---
 tools/testing/selftests/bpf/prog_tests/fentry_test.c   | 2 +-
 tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c | 2 +-
 tools/testing/selftests/bpf/prog_tests/fexit_test.c    | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/bpf/prog_tests/fentry_test.c b/tools/testing/selftests/bpf/prog_tests/fentry_test.c
index e1a379f5f7d2..5cc06021f27d 100644
--- a/tools/testing/selftests/bpf/prog_tests/fentry_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/fentry_test.c
@@ -9,7 +9,7 @@ void test_fentry_test(void)
 	struct test_pkt_access *pkt_skel = NULL;
 	struct fentry_test *fentry_skel = NULL;
 	int err, pkt_fd, i;
-	__u32 duration, retval;
+	__u32 duration = 0, retval;
 	__u64 *result;
 
 	pkt_skel = test_pkt_access__open_and_load();
diff --git a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
index db5c74d2ce6d..cde463af7071 100644
--- a/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
+++ b/tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c
@@ -11,7 +11,7 @@ static void test_fexit_bpf2bpf_common(const char *obj_file,
 	int err, pkt_fd, i;
 	struct bpf_link **link = NULL;
 	struct bpf_program **prog = NULL;
-	__u32 duration, retval;
+	__u32 duration = 0, retval;
 	struct bpf_map *data_map;
 	const int zero = 0;
 	u64 *result = NULL;
diff --git a/tools/testing/selftests/bpf/prog_tests/fexit_test.c b/tools/testing/selftests/bpf/prog_tests/fexit_test.c
index f99013222c74..d2c3655dd7a3 100644
--- a/tools/testing/selftests/bpf/prog_tests/fexit_test.c
+++ b/tools/testing/selftests/bpf/prog_tests/fexit_test.c
@@ -13,7 +13,7 @@ void test_fexit_test(void)
 	int err, pkt_fd, kfree_skb_fd, i;
 	struct bpf_link *link[6] = {};
 	struct bpf_program *prog[6];
-	__u32 duration, retval;
+	__u32 duration = 0, retval;
 	struct bpf_map *data_map;
 	const int zero = 0;
 	u64 result[6];
-- 
2.25.0.341.g760bfbb309-goog


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

* Re: [PATCH bpf-next] selftests/bpf: initialize duration variable before using
  2020-01-23 23:51 [PATCH bpf-next] selftests/bpf: initialize duration variable before using Stanislav Fomichev
@ 2020-01-24  8:54 ` Martin Lau
  2020-01-24 10:11 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Martin Lau @ 2020-01-24  8:54 UTC (permalink / raw)
  To: Stanislav Fomichev
  Cc: netdev@vger.kernel.org, bpf@vger.kernel.org, davem@davemloft.net,
	ast@kernel.org, daniel@iogearbox.net, John Sperbeck

On Thu, Jan 23, 2020 at 03:51:44PM -0800, Stanislav Fomichev wrote:
> From: John Sperbeck <jsperbeck@google.com>
> 
> The 'duration' variable is referenced in the CHECK() macro, and there are
> some uses of the macro before 'duration' is set.  The clang compiler
Acked-by: Martin KaFai Lau <kafai@fb.com>

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

* Re: [PATCH bpf-next] selftests/bpf: initialize duration variable before using
  2020-01-23 23:51 [PATCH bpf-next] selftests/bpf: initialize duration variable before using Stanislav Fomichev
  2020-01-24  8:54 ` Martin Lau
@ 2020-01-24 10:11 ` Daniel Borkmann
  1 sibling, 0 replies; 3+ messages in thread
From: Daniel Borkmann @ 2020-01-24 10:11 UTC (permalink / raw)
  To: Stanislav Fomichev, netdev, bpf; +Cc: davem, ast, John Sperbeck

On 1/24/20 12:51 AM, Stanislav Fomichev wrote:
> From: John Sperbeck <jsperbeck@google.com>
> 
> The 'duration' variable is referenced in the CHECK() macro, and there are
> some uses of the macro before 'duration' is set.  The clang compiler
> (validly) complains about this.
> 
> Sample error:
> 
> .../selftests/bpf/prog_tests/fexit_test.c:23:6: warning: variable 'duration' is uninitialized when used here [-Wuninitialized]
>          if (CHECK(err, "prog_load sched cls", "err %d errno %d\n", err, errno))
>              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> .../selftests/bpf/test_progs.h:134:25: note: expanded from macro 'CHECK'
>          if (CHECK(err, "prog_load sched cls", "err %d errno %d\n", err, errno))
>              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>          _CHECK(condition, tag, duration, format)
>                                 ^~~~~~~~
> 
> Signed-off-by: John Sperbeck <jsperbeck@google.com>
> Signed-off-by: Stanislav Fomichev <sdf@google.com>

Applied, thanks!

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

end of thread, other threads:[~2020-01-24 10:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-01-23 23:51 [PATCH bpf-next] selftests/bpf: initialize duration variable before using Stanislav Fomichev
2020-01-24  8:54 ` Martin Lau
2020-01-24 10:11 ` Daniel Borkmann

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).