From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id C283DA0542; Mon, 29 Aug 2022 10:29:27 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5D4014069D; Mon, 29 Aug 2022 10:29:27 +0200 (CEST) Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by mails.dpdk.org (Postfix) with ESMTP id 5B09640694 for ; Mon, 29 Aug 2022 10:29:24 +0200 (CEST) Received: from localhost.localdomain (unknown [10.2.5.185]) by localhost.localdomain (Coremail) with SMTP id AQAAf8CxYOLceAxjIcYLAA--.52536S2; Mon, 29 Aug 2022 16:29:20 +0800 (CST) From: Min Zhou To: david.marchand@redhat.com, maxime.coquelin@redhat.com, chenbo.xia@intel.com, zhoumin@loongson.cn Cc: dev@dpdk.org, maobibo@loongson.cn Subject: [PATCH v2] vhost: fix build Date: Mon, 29 Aug 2022 16:29:15 +0800 Message-Id: <20220829082915.1056865-1-zhoumin@loongson.cn> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-CM-TRANSID: AQAAf8CxYOLceAxjIcYLAA--.52536S2 X-Coremail-Antispam: 1UD129KBjvJXoW7KF43Cw4fAFW8uF4xXF1rCrg_yoW8KFyDpF 43JwnrAFyxKF4I9a1rZFs7C348Aas7C347WrsxWw17CFW5Kr9rJFyv9Fy0yrsrArWUC348 Xr10qFWUJ34DuaDanT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDU0xBIdaVrnUUvcSsGvfC2KfnxnUUI43ZEXa7xR_UUUUUUUUU== X-CM-SenderInfo: 52kr3ztlq6z05rqj20fqof0/ X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org On CentOS 8 or Debian 10.4 systems using gcc 12.1 to cross compile DPDK, gcc shows a following warning which will cause build to fail when build is run with -werror: In function 'mbuf_to_desc', inlined from 'vhost_enqueue_async_packed' at ../lib/vhost/virtio_net.c:1826:6, inlined from 'virtio_dev_rx_async_packed' at ../lib/vhost/virtio_net.c:1840:6, inlined from 'virtio_dev_rx_async_submit_packed.constprop' at ../lib/vhost/virtio_net.c:1900:7: ../lib/vhost/virtio_net.c:1161:35: error: 'buf_vec[0].buf_len' may be used uninitialized [-Werror=maybe-uninitialized] 1161 | buf_len = buf_vec[vec_idx].buf_len; | ~~~~~~~~~~~~~~~~^~~~~~~~ ../lib/vhost/virtio_net.c: In function 'virtio_dev_rx_async_submit_packed.constprop': ../lib/vhost/virtio_net.c:1838:27: note: 'buf_vec' declared here 1838 | struct buf_vector buf_vec[BUF_VECTOR_MAX]; | ^~~~~~~ cc1: all warnings being treated as errors Actually, there are eight places to see the same codes in the file lib/vhost/virtio_net.c, and all these `buf_vec` arraies are initialized by sub-function calls under various conditions. Although It's hard to understand why gcc just emits warning at one of the eight places, adding validity checks for array length is reasonable and can also fix the warning. Signed-off-by: David Marchand Signed-off-by: Min Zhou --- lib/vhost/virtio_net.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index 35fa4670fd..99233f1759 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1153,7 +1153,7 @@ mbuf_to_desc(struct virtio_net *dev, struct vhost_virtqueue *vq, struct virtio_net_hdr_mrg_rxbuf tmp_hdr, *hdr = NULL; struct vhost_async *async = vq->async; - if (unlikely(m == NULL)) + if (unlikely(m == NULL || nr_vec == 0)) return -1; buf_addr = buf_vec[vec_idx].buf_addr; @@ -2673,6 +2673,9 @@ desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq, struct vhost_async *async = vq->async; struct async_inflight_info *pkts_info; + if (unlikely(nr_vec == 0)) + return -1; + buf_addr = buf_vec[vec_idx].buf_addr; buf_iova = buf_vec[vec_idx].buf_iova; buf_len = buf_vec[vec_idx].buf_len; -- 2.31.1