From patchwork Wed Oct 11 11:28:17 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bruce Richardson X-Patchwork-Id: 30116 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id AA9621B1A9; Wed, 11 Oct 2017 13:28:57 +0200 (CEST) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 9A0851B199 for ; Wed, 11 Oct 2017 13:28:56 +0200 (CEST) Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Oct 2017 04:28:55 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.43,361,1503385200"; d="scan'208";a="161407814" Received: from silpixa00399126.ir.intel.com (HELO silpixa00399126.ger.corp.intel.com) ([10.237.223.223]) by fmsmga005.fm.intel.com with ESMTP; 11 Oct 2017 04:28:53 -0700 From: Bruce Richardson To: yliu@fridaylinux.org Cc: dev@dpdk.org, Thomas Monjalon , Bruce Richardson , Maxime Coquelin Date: Wed, 11 Oct 2017 12:28:17 +0100 Message-Id: <20171011112817.3357-1-bruce.richardson@intel.com> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20171011095907.229893-1-bruce.richardson@intel.com> References: <20171011095907.229893-1-bruce.richardson@intel.com> Subject: [dpdk-dev] [PATCH v2] vhost: fix false-positive warning from clang 5 X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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") CC: Maxime Coquelin Signed-off-by: Bruce Richardson --- V2: remove ret variable completely, to avoid unused var warnings when compiling with the build-time numa option disabled. --- 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 066c37a73..05c278040 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);