Skip to contentSkip to conversation

selftests/bpf: initialize duration variable before using

PATCH Applied Stanislav Fomichev 3 participants 3 messages Jan 23, 2020 – Jan 24, 2020

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftests/bpf: initialize duration variable before using

From: John Sperbeck <[email protected]>

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)
^~~~~~~~

---
 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(-)
tools/testing/selftests/bpf/prog_tests/fentry_test.c +1 -1
index e1a379f5f7d2..5cc06021f27d 100644
@@ -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();
tools/testing/selftests/bpf/prog_tests/fexit_bpf2bpf.c +1 -1
index db5c74d2ce6d..cde463af7071 100644
@@ -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;
tools/testing/selftests/bpf/prog_tests/fexit_test.c +1 -1
index f99013222c74..d2c3655dd7a3 100644
@@ -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];
Signature · 1 line
2.25.0.341.g760bfbb309-goog
maintainer Applied
#2 lore raw
In reply to Stanislav Fomichev
Quoted 17 lines · Stanislav Fomichev

From: John Sperbeck <[email protected]>

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)
^~~~~~~~

Quoted 2 lines

Applied, thanks!