diff mbox series

[2/4] verbs: Simplify the logic assigning vid in ibv_resolve_eth_l2_from_gid()

Message ID 2-v1-f03f70229014+144-fix_lto_jgg@nvidia.com (mailing list archive)
State Not Applicable
Headers show
Series Enable LTO support for rdma-core | expand

Commit Message

Jason Gunthorpe Nov. 16, 2020, 8:16 p.m. UTC
gcc 10 with LTO reports:

../libibverbs/verbs.c:1040:8: error: 'ret_vid' may be used uninitialized in this function [-Werror=maybe-uninitialized]
 1040 |   *vid = ret_vid;

Which seems like a compiler bug as there is obviously no way for this to
be true, nor is it clear how LTO has any impact here since
neigh_get_vlan_id_from_dev() always returns a defined value.

Nevertheless, the logic is tortured, so simplify it by combining
everything into one if.

Signed-off-by: Jason Gunthorpe <jgg@nvidia.com>
---
 libibverbs/verbs.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/libibverbs/verbs.c b/libibverbs/verbs.c
index 7fc10240cf9def..2b0ede84e8d635 100644
--- a/libibverbs/verbs.c
+++ b/libibverbs/verbs.c
@@ -973,7 +973,6 @@  int ibv_resolve_eth_l2_from_gid(struct ibv_context *context,
 	int ether_len;
 	struct peer_address src;
 	struct peer_address dst;
-	uint16_t ret_vid;
 	int ret = -EINVAL;
 	int err;
 
@@ -1022,10 +1021,11 @@  int ibv_resolve_eth_l2_from_gid(struct ibv_context *context,
 		goto free_resources;
 
 	if (vid) {
-		ret_vid = neigh_get_vlan_id_from_dev(&neigh_handler);
+		uint16_t ret_vid = neigh_get_vlan_id_from_dev(&neigh_handler);
 
 		if (ret_vid <= 0xfff)
 			neigh_set_vlan_id(&neigh_handler, ret_vid);
+		*vid = ret_vid;
 	}
 
 	/* We are using only Ethernet here */
@@ -1036,9 +1036,6 @@  int ibv_resolve_eth_l2_from_gid(struct ibv_context *context,
 	if (ether_len <= 0)
 		goto free_resources;
 
-	if (vid)
-		*vid = ret_vid;
-
 	ret = 0;
 
 free_resources: