Skip to contentSkip to conversation

selftest:net: Fix uninit return values

PATCH Superseded Sidharth Seela 3 participants 4 messages Sep 30, 2025

Subsystems (4)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 selftest:net: Fix uninit return values

Fix functions that return undefined values. These issues were caught by running clang using LLVM=1 option.

Clang warnings are as follows:
ovpn-cli.c:1587:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]

 1587 |         if (!sock) {
      |             ^~~~~

ovpn-cli.c:1635:9: note: uninitialized use occurs here
1635 | return ret;
| ^~~
ovpn-cli.c:1587:2: note: remove the 'if' if its condition is always false

 1587 |         if (!sock) {
      |         ^~~~~~~~~~~~
 1588 |                 fprintf(stderr, "cannot allocate netlink socket\n");
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1589 |                 goto err_free;
      |                 ~~~~~~~~~~~~~~
 1590 |         }
      |         ~
ovpn-cli.c:1584:15: note: initialize the variable 'ret' to silence this warning
 1584 |         int mcid, ret;
      |                      ^
      |                       = 0
ovpn-cli.c:2107:7: warning: variable 'ret' is used uninitialized whenever switch case is taken [-Wsometimes-uninitialized]
 2107 |         case CMD_INVALID:
      |              ^~~~~~~~~~~

ovpn-cli.c:2111:9: note: uninitialized use occurs here
2111 | return ret;
| ^~~
ovpn-cli.c:1939:12: note: initialize the variable 'ret' to silence this warning

 1939 |         int n, ret;
      |                   ^
      |
Fixes 959bc330a439 ("testing/selftests: add test tool and scripts for ovpn module")

ovpn module")

---

v5:
- Assign -ENOMEM to ret inside if block.
- Assign -EINVAL to ret inside case block.
v4:
- Move changelog below sign-off.
- Remove double-hyphens in commit description.
v3:
- Use prefix net.
- Remove so_txtime fix as default case calls error().
- Changelog before sign-off.
- Three dashes after sign-off
v2:
- Use subsystem name "net".
- Add fixes tags.
- Remove txtimestamp fix as default case calls error.
- Assign constant error string instead of NULL.

tools/testing/selftests/net/ovpn/ovpn-cli.c +2 -0
index 9201f2905f2c..8d0f2f61923c 100644
@@ -1586,6 +1586,7 @@ static int ovpn_listen_mcast(void)
 	sock = nl_socket_alloc();
 	if (!sock) {
 		fprintf(stderr, "cannot allocate netlink socket\n");
+		ret = -ENOMEM;
 		goto err_free;
 	}
 
@@ -2105,6 +2106,7 @@ static int ovpn_run_cmd(struct ovpn_ctx *ovpn)
 		ret = ovpn_listen_mcast();
 		break;
 	case CMD_INVALID:
+		ret = -EINVAL;
 		break;
 	}
 
Signature · 1 line
2.47.3
#2 lore raw
In reply to Sidharth Seela

Since it's now only to ovpn, better prefix, which matches other patches in that directory, is "selftest/net/ovpn:"

Btw, review the posting rules. Leave 24 hours between reposts:

https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

Quoted 30 lines · Sidharth Seela

Fix functions that return undefined values. These issues were caught by running clang using LLVM=1 option.

Clang warnings are as follows:
ovpn-cli.c:1587:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]

 1587 |         if (!sock) {
      |             ^~~~~

ovpn-cli.c:1635:9: note: uninitialized use occurs here
1635 | return ret;
| ^~~
ovpn-cli.c:1587:2: note: remove the 'if' if its condition is always false

 1587 |         if (!sock) {
      |         ^~~~~~~~~~~~
 1588 |                 fprintf(stderr, "cannot allocate netlink socket\n");
      |                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 1589 |                 goto err_free;
      |                 ~~~~~~~~~~~~~~
 1590 |         }
      |         ~
ovpn-cli.c:1584:15: note: initialize the variable 'ret' to silence this warning
 1584 |         int mcid, ret;
      |                      ^
      |                       = 0
ovpn-cli.c:2107:7: warning: variable 'ret' is used uninitialized whenever switch case is taken [-Wsometimes-uninitialized]
 2107 |         case CMD_INVALID:
      |              ^~~~~~~~~~~

ovpn-cli.c:2111:9: note: uninitialized use occurs here
2111 | return ret;
| ^~~
ovpn-cli.c:1939:12: note: initialize the variable 'ret' to silence this warning

Quoted 6 lines
 1939 |         int n, ret;
      |                   ^
      |
Fixes 959bc330a439 ("testing/selftests: add test tool and scripts for ovpn module")

ovpn module")

stray line

Quoted 43 lines

---

v5:
- Assign -ENOMEM to ret inside if block.
- Assign -EINVAL to ret inside case block.
v4:
- Move changelog below sign-off.
- Remove double-hyphens in commit description.
v3:
- Use prefix net.
- Remove so_txtime fix as default case calls error().
- Changelog before sign-off.
- Three dashes after sign-off
v2:
- Use subsystem name "net".
- Add fixes tags.
- Remove txtimestamp fix as default case calls error.
- Assign constant error string instead of NULL.

tools/testing/selftests/net/ovpn/ovpn-cli.c +2 -0
index 9201f2905f2c..8d0f2f61923c 100644
@@ -1586,6 +1586,7 @@ static int ovpn_listen_mcast(void)
 	sock = nl_socket_alloc();
 	if (!sock) {
 		fprintf(stderr, "cannot allocate netlink socket\n");
+		ret = -ENOMEM;
 		goto err_free;
 	}
 
@@ -2105,6 +2106,7 @@ static int ovpn_run_cmd(struct ovpn_ctx *ovpn)
 		ret = ovpn_listen_mcast();
 		break;
 	case CMD_INVALID:
+		ret = -EINVAL;
 		break;
 	}
 
Signature · 1 line
2.47.3
#3 lore raw
Quoted 2 lines · Willem de Bruijn

Since it's now only to ovpn, better prefix, which matches other patches in that directory, is "selftest/net/ovpn:"

Alright, this makes sense.

Quoted 2 lines

Btw, review the posting rules. Leave 24 hours between reposts:
https://www.kernel.org/doc/html/latest/process/maintainer-netdev.html

Thankyou for pointing me in the right direction.

Quoted 1 line

stray line

Ah, will remove in the next v6

Signature · 3 lines
Thanks,
Sidharth Seela
www.realtimedesign.org