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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 libibverbs/verbs.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

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:
-- 
2.29.2





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux