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 91A3AA0545; Fri, 2 Sep 2022 17:06:36 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 5D48E40693; Fri, 2 Sep 2022 17:06:35 +0200 (CEST) Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com [67.231.148.174]) by mails.dpdk.org (Postfix) with ESMTP id 8B8EF40685; Fri, 2 Sep 2022 17:06:33 +0200 (CEST) Received: from pps.filterd (m0045849.ppops.net [127.0.0.1]) by mx0a-0016f401.pphosted.com (8.17.1.5/8.17.1.5) with ESMTP id 282E5eZl010549; Fri, 2 Sep 2022 08:06:29 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=pfpt0220; bh=ZMM2s41xKERHqvQ0AaFS/J+ds7m4LZ6f3cS+oLtxXEk=; b=K5h3wS4HDq4s8ekFRZ3c3Spsk3FvsDmCG0Qc+dWG346BFDEAw5fPbaugYgv/ADw4Haju TmlKqV/pMoaDiQOvknOoY6Wt55GCePpYTYBvUP3cJjODfeIg1Vn/vTC/3S5H+qICrf7O p9WzTCrVsiuUDJ+wYfLgTBGm6n64AeUfbW+vgiEWjFpEk2i7jR16fHfKaicXk2LbEpYJ ibw7mJVvNhEaBAGui6oPlUIccaWqbGLX7i49zOweWZspnLyRAyNyOcyIx3Ytw81sxA/S qc3CayExLSeiYd6eg3Bl09SHDXdAgy4ltms/TWGOK0/O4hc15vhf02U6q8pi/BfzIWBR 5Q== Received: from dc5-exch01.marvell.com ([199.233.59.181]) by mx0a-0016f401.pphosted.com (PPS) with ESMTPS id 3jb3kukd0u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Fri, 02 Sep 2022 08:06:29 -0700 Received: from DC5-EXCH02.marvell.com (10.69.176.39) by DC5-EXCH01.marvell.com (10.69.176.38) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Fri, 2 Sep 2022 08:06:27 -0700 Received: from maili.marvell.com (10.69.176.80) by DC5-EXCH02.marvell.com (10.69.176.39) with Microsoft SMTP Server id 15.0.1497.18 via Frontend Transport; Fri, 2 Sep 2022 08:06:27 -0700 Received: from localhost.localdomain (unknown [10.28.36.157]) by maili.marvell.com (Postfix) with ESMTP id AFF925B6935; Fri, 2 Sep 2022 08:06:25 -0700 (PDT) From: Amit Prakash Shukla To: Maxime Coquelin , Chenbo Xia CC: , , , , Amit Prakash Shukla Subject: [PATCH v3] vhost: compilation fix for GCC-12 Date: Fri, 2 Sep 2022 20:36:22 +0530 Message-ID: <20220902150622.3233855-1-amitprakashs@marvell.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220901084943.3075710-1-amitprakashs@marvell.com> References: <20220901084943.3075710-1-amitprakashs@marvell.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Proofpoint-ORIG-GUID: 6xex4YVvlY-TKMHOVbXUfpAjSVCmjppa X-Proofpoint-GUID: 6xex4YVvlY-TKMHOVbXUfpAjSVCmjppa X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.205,Aquarius:18.0.895,Hydra:6.0.517,FMLib:17.11.122.1 definitions=2022-09-02_02,2022-08-31_03,2022-06-22_01 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 GCC-12 complains about the possible use of un-initialized array. At compile time it seems like it is not able to evaluate the size as it involves run-time variable and at compile time it seems like gcc assumes value of "size" variable to be zero which makes gcc-12 to jump the while loop. "size = pkt->pkt_len + sizeof(struct virtio_net_hdr_mrg_rxbuf);" As part of the fix, "while (){}" is replaced by "do {} while()" which make the compiler to generate a code in which buf_vec will never be used un-initialized. ../lib/vhost/virtio_net.c:941:35: error: 'buf_vec[0].buf_len' may be used uninitialized [-Werror=maybe-uninitialized] 941 | buf_len = buf_vec[vec_idx].buf_len; | ~~~~~~~~~~~~~~~~^~~~~~~~ ../lib/vhost/virtio_net.c: In function 'virtio_dev_rx_packed': ../lib/vhost/virtio_net.c:1285:27: note: 'buf_vec' declared here 1285 | struct buf_vector buf_vec[BUF_VECTOR_MAX]; | ^~~~~~~ cc1: all warnings being treated as errors Fixes: 93520085efda ("vhost: add packed ring single enqueue") Cc: stable@dpdk.org Signed-off-by: Amit Prakash Shukla --- v2: - Changes for code review suggestion v3: - Added a description lib/vhost/virtio_net.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c index b3d954aab4..9b77d3d10f 100644 --- a/lib/vhost/virtio_net.c +++ b/lib/vhost/virtio_net.c @@ -1069,7 +1069,7 @@ vhost_enqueue_single_packed(struct virtio_net *dev, else max_tries = 1; - while (size > 0) { + do { /* * if we tried all available ring items, and still * can't get enough buf, it means something abnormal @@ -1097,7 +1097,7 @@ vhost_enqueue_single_packed(struct virtio_net *dev, avail_idx += desc_count; if (avail_idx >= vq->size) avail_idx -= vq->size; - } + } while (size > 0); if (mbuf_to_desc(dev, vq, pkt, buf_vec, nr_vec, num_buffers, false) < 0) return -1; @@ -1574,7 +1574,7 @@ vhost_enqueue_async_packed(struct virtio_net *dev, else max_tries = 1; - while (size > 0) { + do { /* * if we tried all available ring items, and still * can't get enough buf, it means something abnormal @@ -1601,7 +1601,7 @@ vhost_enqueue_async_packed(struct virtio_net *dev, avail_idx += desc_count; if (avail_idx >= vq->size) avail_idx -= vq->size; - } + } while (size > 0); if (unlikely(mbuf_to_desc(dev, vq, pkt, buf_vec, nr_vec, *nr_buffers, true) < 0)) return -1; -- 2.25.1