[PATCH v2 08/13] selftests: net: netlink-dumps: Avoid uninitialized variable warning

Guenter Roeck posted 13 patches 1 week, 6 days ago
[PATCH v2 08/13] selftests: net: netlink-dumps: Avoid uninitialized variable warning
Posted by Guenter Roeck 1 week, 6 days ago
The following warning is seen when building netlink-dumps.

netlink-dumps.c: In function ‘dump_extack’:
../kselftest_harness.h:788:35: warning: ‘ret’ may be used uninitialized

Problem is that the loop which initializes 'ret' may exit early without
initializing the variable if recv() returns an error. Always initialize
'ret' to solve the problem.

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
---
v2: Update subject and description to reflect that the patch fixes a build
    warning. 

 tools/testing/selftests/net/netlink-dumps.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/tools/testing/selftests/net/netlink-dumps.c b/tools/testing/selftests/net/netlink-dumps.c
index 679b6c77ace7..67bf3fc2d66b 100644
--- a/tools/testing/selftests/net/netlink-dumps.c
+++ b/tools/testing/selftests/net/netlink-dumps.c
@@ -112,7 +112,7 @@ static const struct {
 TEST(dump_extack)
 {
 	int netlink_sock;
-	int i, cnt, ret;
+	int i, cnt, ret = FOUND_ERR;
 	char buf[8192];
 	int one = 1;
 	ssize_t n;
-- 
2.45.2

Re: [PATCH v2 08/13] selftests: net: netlink-dumps: Avoid uninitialized variable warning
Posted by Jakub Kicinski 1 week, 2 days ago
On Fri,  5 Dec 2025 09:10:02 -0800 Guenter Roeck wrote:
> The following warning is seen when building netlink-dumps.
> 
> netlink-dumps.c: In function ‘dump_extack’:
> ../kselftest_harness.h:788:35: warning: ‘ret’ may be used uninitialized
> 
> Problem is that the loop which initializes 'ret' may exit early without
> initializing the variable if recv() returns an error. Always initialize
> 'ret' to solve the problem.

Are you sure you're working off the latest tree? I think this should
already be fixed by 13cb6ac5b50

I applied the other 3 networking changes.
Re: [PATCH v2 08/13] selftests: net: netlink-dumps: Avoid uninitialized variable warning
Posted by Guenter Roeck 1 week, 1 day ago
On 12/10/25 01:13, Jakub Kicinski wrote:
> On Fri,  5 Dec 2025 09:10:02 -0800 Guenter Roeck wrote:
>> The following warning is seen when building netlink-dumps.
>>
>> netlink-dumps.c: In function ‘dump_extack’:
>> ../kselftest_harness.h:788:35: warning: ‘ret’ may be used uninitialized
>>
>> Problem is that the loop which initializes 'ret' may exit early without
>> initializing the variable if recv() returns an error. Always initialize
>> 'ret' to solve the problem.
> 
> Are you sure you're working off the latest tree? I think this should
> already be fixed by 13cb6ac5b50
> 

Sorry for missing the fix. I was working off v6.18, which was the tip of
the tree when I wrote the patch.

> I applied the other 3 networking changes.

Thanks a lot!

Guenter