Skip to contentSkip to conversation

selftest: net: prevent use of uninitialized variable

PATCH Superseded Alessandro Zanni 2 participants 2 messages Oct 21, 2025 – Oct 22, 2025

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 selftest: net: prevent use of uninitialized variable

Fix to avoid the usage of the ret variable uninitialized in the following macro expansions.

It solves the following warning:

In file included from netlink-dumps.c:21:
netlink-dumps.c: In function ‘dump_extack’:
../kselftest_harness.h:788:35: warning: ‘ret’ may be used uninitialized [-Wmaybe-uninitialized]

  788 |                         intmax_t  __exp_print = (intmax_t)__exp; \
      |                                   ^~~~~~~~~~~
../kselftest_harness.h:631:9: note: in expansion of macro ‘__EXPECT’
  631 |         __EXPECT(expected, #expected, seen, #seen, ==, 0)
      |         ^~~~~~~~
netlink-dumps.c:169:9: note: in expansion of macro ‘EXPECT_EQ’
  169 |         EXPECT_EQ(ret, FOUND_EXTACK);
      |         ^~~~~~~~~

The issue can be reproduced, building the tests, with the command:
make -C tools/testing/selftests TARGETS=net

---
 tools/testing/selftests/net/netlink-dumps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/netlink-dumps.c +1 -1
index 7618ebe528a4..8ebb8b1b9c5c 100644
@@ -112,7 +112,7 @@ static const struct {
 TEST(dump_extack)
 {
 	int netlink_sock;
-	int i, cnt, ret;
+	int i, cnt, ret = 0;
 	char buf[8192];
 	int one = 1;
 	ssize_t n;
Signature · 1 line
2.43.0
reviewer
#1 lore raw
Quoted 30 lines · Alessandro Zanni

Fix to avoid the usage of the ret variable uninitialized in the following macro expansions.

It solves the following warning:

In file included from netlink-dumps.c:21:
netlink-dumps.c: In function ‘dump_extack’:
../kselftest_harness.h:788:35: warning: ‘ret’ may be used uninitialized [-Wmaybe-uninitialized]

  788 |                         intmax_t  __exp_print = (intmax_t)__exp; \
      |                                   ^~~~~~~~~~~
../kselftest_harness.h:631:9: note: in expansion of macro ‘__EXPECT’
  631 |         __EXPECT(expected, #expected, seen, #seen, ==, 0)
      |         ^~~~~~~~
netlink-dumps.c:169:9: note: in expansion of macro ‘EXPECT_EQ’
  169 |         EXPECT_EQ(ret, FOUND_EXTACK);
      |         ^~~~~~~~~

The issue can be reproduced, building the tests, with the command:
make -C tools/testing/selftests TARGETS=net

---
 tools/testing/selftests/net/netlink-dumps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/testing/selftests/net/netlink-dumps.c +0 -0
index 7618ebe528a4..8ebb8b1b9c5c 100644

tools/testing/selftests/net/netlink-dumps.c static const struct { · line 115

Quoted 5 lines
tools/testing/selftests/net/netlink-dumps.c +1 -1
@@ -112,7 +112,7 @@ static const struct {
 TEST(dump_extack)
 {
 	int netlink_sock;
-	int i, cnt, ret;
+	int i, cnt, ret = 0;

Hi Alessandro,

I suggest moving this line so that reverse xmas tree order - longest line to shortest - is preserved.

Quoted 6 lines
tools/testing/selftests/net/netlink-dumps.c +0 -0
 	char buf[8192];
 	int one = 1;
 	ssize_t n;
Signature · 1 line
2.43.0