From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id B20AEA04B5; Tue, 27 Oct 2020 13:51:41 +0100 (CET) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 873504C8B; Tue, 27 Oct 2020 13:51:40 +0100 (CET) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by dpdk.org (Postfix) with ESMTP id 346144C89; Tue, 27 Oct 2020 13:51:38 +0100 (CET) Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4CLBRG3JjbzLn9y; Tue, 27 Oct 2020 20:51:38 +0800 (CST) Received: from localhost (10.174.187.156) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server id 14.3.487.0; Tue, 27 Oct 2020 20:51:26 +0800 From: wangyunjian To: , , CC: , , , , Yunjian Wang , Date: Tue, 27 Oct 2020 20:51:25 +0800 Message-ID: <166b4a84232777b5ff3dd5d659140dab104e3f77.1603782481.git.wangyunjian@huawei.com> X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.187.156] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH] hash: fix dereference before null check 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" From: Yunjian Wang Coverity flags that 'h' variable is used before it's checked for NULL. This patch fixes this issue. Coverity issue: 363625 Fixes: 769b2de7fb52 ("hash: implement RCU resources reclamation") Cc: stable@dpdk.org Signed-off-by: Yunjian Wang --- lib/librte_hash/rte_cuckoo_hash.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 7514e33aa9..1191dfd81a 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -1515,15 +1515,16 @@ rte_hash_rcu_qsbr_add(struct rte_hash *h, struct rte_hash_rcu_config *cfg) struct rte_rcu_qsbr_dq_parameters params = {0}; char rcu_dq_name[RTE_RCU_QSBR_DQ_NAMESIZE]; struct rte_hash_rcu_config *hash_rcu_cfg = NULL; - const uint32_t total_entries = h->use_local_cache ? - h->entries + (RTE_MAX_LCORE - 1) * (LCORE_CACHE_SIZE - 1) + 1 - : h->entries + 1; if (h == NULL || cfg == NULL || cfg->v == NULL) { rte_errno = EINVAL; return 1; } + const uint32_t total_entries = h->use_local_cache ? + h->entries + (RTE_MAX_LCORE - 1) * (LCORE_CACHE_SIZE - 1) + 1 + : h->entries + 1; + if (h->hash_rcu_cfg) { rte_errno = EEXIST; return 1; -- 2.23.0