[dpdk-dev] [PATCH] hash: fix return value of null not checked

Honnappa Nagarahalli Honnappa.Nagarahalli at arm.com
Tue Jul 21 19:26:59 CEST 2020



> -----Original Message-----
> From: dev <dev-bounces at dpdk.org> On Behalf Of wangyunjian
> Sent: Tuesday, July 21, 2020 8:32 AM
> To: dev at dpdk.org
> Cc: yipeng1.wang at intel.com; sameh.gobriel at intel.com;
> bruce.richardson at intel.com; jerry.lilijun at huawei.com;
> xudingke at huawei.com; Yunjian Wang <wangyunjian at huawei.com>;
> stable at dpdk.org
> Subject: [dpdk-dev] [PATCH] hash: fix return value of null not checked
> 
> From: Yunjian Wang <wangyunjian at huawei.com>
> 
> 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 at dpdk.org
> 
> Reported-by: HuangBin <brian.huangbin at huawei.com>
> Signed-off-by: Yunjian Wang <wangyunjian at huawei.com>
Good catch
Reviewed-by: Honnappa Nagarahalli <honnappa.nagarahalli at arm.com>

> ---
>  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
> 



More information about the dev mailing list