From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id 1B099A04E7;
	Wed,  4 Nov 2020 02:25:05 +0100 (CET)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 0643BBE43;
	Wed,  4 Nov 2020 02:25:03 +0100 (CET)
Received: from szxga04-in.huawei.com (szxga04-in.huawei.com [45.249.212.190])
 by dpdk.org (Postfix) with ESMTP id B387ABBB4
 for <dev@dpdk.org>; Wed,  4 Nov 2020 02:24:59 +0100 (CET)
Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.58])
 by szxga04-in.huawei.com (SkyGuard) with ESMTP id 4CQpq86TCxzkdRX;
 Wed,  4 Nov 2020 09:24:52 +0800 (CST)
Received: from localhost (10.174.187.156) by DGGEMS401-HUB.china.huawei.com
 (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Wed, 4 Nov 2020
 09:24:50 +0800
From: wangyunjian <wangyunjian@huawei.com>
To: <dev@dpdk.org>
CC: <thomas@monjalon.net>, <ferruh.yigit@intel.com>,
 <andrew.rybchenko@oktetlabs.ru>, <jerry.lilijun@huawei.com>,
 <xudingke@huawei.com>, Yunjian Wang <wangyunjian@huawei.com>
Date: Wed, 4 Nov 2020 09:24:36 +0800
Message-ID: <1604453076-34392-1-git-send-email-wangyunjian@huawei.com>
X-Mailer: git-send-email 1.9.5.msysgit.1
In-Reply-To: <e103e69b3dee3ada2506816b1cf6e42dbffc72d1.1604409065.git.wangyunjian@huawei.com>
References: <e103e69b3dee3ada2506816b1cf6e42dbffc72d1.1604409065.git.wangyunjian@huawei.com>
MIME-Version: 1.0
Content-Type: text/plain
X-Originating-IP: [10.174.187.156]
X-CFilter-Loop: Reflected
Subject: [dpdk-dev]  [PATCH v2] ethdev: fix check of rx configure
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

From: Yunjian Wang <wangyunjian@huawei.com>

Coverity flags that 'rx_conf' variable is used before
it's checked for NULL. This patch fixes this issue.

Coverity issue: 363570
Fixes: 4ff702b5dfa9 ("ethdev: introduce Rx buffer split")

Signed-off-by: Yunjian Wang <wangyunjian@huawei.com>
---
v2:
    fix code styles suggested by Ferruh Yigit
---
 lib/librte_ethdev/rte_ethdev.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c
index b12bb3854d..1ac59a39e3 100644
--- a/lib/librte_ethdev/rte_ethdev.c
+++ b/lib/librte_ethdev/rte_ethdev.c
@@ -1978,9 +1978,8 @@ rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
 			return -EINVAL;
 		}
 	} else {
-		const struct rte_eth_rxseg_split *rx_seg =
-			(const struct rte_eth_rxseg_split *)rx_conf->rx_seg;
-		uint16_t n_seg = rx_conf->rx_nseg;
+		const struct rte_eth_rxseg_split *rx_seg;
+		uint16_t n_seg;
 
 		/* Extended multi-segment configuration check. */
 		if (rx_conf == NULL || rx_conf->rx_seg == NULL || rx_conf->rx_nseg == 0) {
@@ -1988,6 +1987,10 @@ rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
 				       "Memory pool is null and no extended configuration provided\n");
 			return -EINVAL;
 		}
+
+		rx_seg = (const struct rte_eth_rxseg_split *)rx_conf->rx_seg;
+		n_seg = rx_conf->rx_nseg;
+
 		if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) {
 			ret = rte_eth_rx_queue_check_split(rx_seg, n_seg,
 							   &mbp_buf_size,
-- 
2.18.1