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 BC4B3A0526; Tue, 21 Jul 2020 15:31:48 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 9E0E51BFEB; Tue, 21 Jul 2020 15:31:47 +0200 (CEST) Received: from huawei.com (szxga06-in.huawei.com [45.249.212.32]) by dpdk.org (Postfix) with ESMTP id 6C1C51BFE7; Tue, 21 Jul 2020 15:31:46 +0200 (CEST) Received: from DGGEMS411-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 11B456E0895C1D4B8D71; Tue, 21 Jul 2020 21:31:44 +0800 (CST) Received: from localhost (10.174.185.168) by DGGEMS411-HUB.china.huawei.com (10.3.19.211) with Microsoft SMTP Server id 14.3.487.0; Tue, 21 Jul 2020 21:31:38 +0800 From: wangyunjian To: CC: , , , , , Yunjian Wang , Date: Tue, 21 Jul 2020 21:31:31 +0800 Message-ID: X-Mailer: git-send-email 1.9.5.msysgit.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.174.185.168] X-CFilter-Loop: Reflected Subject: [dpdk-dev] [PATCH] hash: fix return value of null not checked 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 The function rte_zmalloc_socket() could return NULL, the return value need to be checked. Fixes: 5915699153d7 ("hash: fix scaling by reducing contention") Cc: stable@dpdk.org Reported-by: HuangBin Signed-off-by: Yunjian Wang --- lib/librte_hash/rte_cuckoo_hash.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 5f701d579..0a6d47471 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -151,6 +151,7 @@ rte_hash_create(const struct rte_hash_parameters *params) unsigned int no_free_on_del = 0; uint32_t *ext_bkt_to_free = NULL; uint32_t *tbl_chng_cnt = NULL; + struct lcore_cache *local_free_slots = NULL; unsigned int readwrite_concur_lf_support = 0; uint32_t i; @@ -383,9 +384,13 @@ rte_hash_create(const struct rte_hash_parameters *params) #endif if (use_local_cache) { - h->local_free_slots = rte_zmalloc_socket(NULL, + local_free_slots = rte_zmalloc_socket(NULL, sizeof(struct lcore_cache) * RTE_MAX_LCORE, RTE_CACHE_LINE_SIZE, params->socket_id); + if (local_free_slots == NULL) { + RTE_LOG(ERR, HASH, "local free slots memory allocation failed\n"); + goto err_unlock; + } } /* Default hash function */ @@ -416,6 +421,7 @@ rte_hash_create(const struct rte_hash_parameters *params) *h->tbl_chng_cnt = 0; h->hw_trans_mem_support = hw_trans_mem_support; h->use_local_cache = use_local_cache; + h->local_free_slots = local_free_slots; h->readwrite_concur_support = readwrite_concur_support; h->ext_table_support = ext_table_support; h->writer_takes_lock = writer_takes_lock; @@ -461,6 +467,7 @@ rte_hash_create(const struct rte_hash_parameters *params) rte_ring_free(r); rte_ring_free(r_ext); rte_free(te); + rte_free(local_free_slots); rte_free(h); rte_free(buckets); rte_free(buckets_ext); -- 2.23.0