From d65b3b1668f2037745407c3909c43d85a18692a6 Mon Sep 17 00:00:00 2001 From: Bruce Richardson Date: Wed, 11 Oct 2017 12:28:17 +0100 Subject: [PATCH] vhost: fix false-positive warning from clang 5 When compiling with clang extra warning flags, such as used by default with meson, a warning is given in iotlb.c: lib/librte_vhost/iotlb.c:318:6: warning: variable 'socket' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized] This is a false positive, as the socket value will be initialized by the call to get_mempolicy in the case where the NUMA build-time flag is set, and in cases where it is not set, "if (ret)" will always be true as ret is initialized to -1 and never changed. However, this is not immediately obvious, and is perhaps a little fragile, as it will break if other code using ret is subsequently added above the call to get_mempolicy by someone unaware of this subtle dependency. Therefore, we can fix the warning and making the code more robust by explicitly initializing socket to zero, and moving the extra condition check on the return from get_mempolicy() into the #ifdef Fixes: d012d1f293f4 ("vhost: add IOTLB helper functions") Signed-off-by: Bruce Richardson --- lib/librte_vhost/iotlb.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/librte_vhost/iotlb.c b/lib/librte_vhost/iotlb.c index 066c37a734..05c278040f 100644 --- a/lib/librte_vhost/iotlb.c +++ b/lib/librte_vhost/iotlb.c @@ -300,7 +300,7 @@ vhost_user_iotlb_init(struct virtio_net *dev, int vq_index) { char pool_name[RTE_MEMPOOL_NAMESIZE]; struct vhost_virtqueue *vq = dev->virtqueue[vq_index]; - int ret = -1, socket; + int socket = 0; if (vq->iotlb_pool) { /* @@ -313,10 +313,9 @@ vhost_user_iotlb_init(struct virtio_net *dev, int vq_index) } #ifdef RTE_LIBRTE_VHOST_NUMA - ret = get_mempolicy(&socket, NULL, 0, vq, MPOL_F_NODE | MPOL_F_ADDR); -#endif - if (ret) + if (get_mempolicy(&socket, NULL, 0, vq, MPOL_F_NODE | MPOL_F_ADDR) != 0) socket = 0; +#endif rte_rwlock_init(&vq->iotlb_lock); rte_rwlock_init(&vq->iotlb_pending_lock); -- 2.20.1