From 572f2a90893d6ae63e01de830e4a18e27746c3e1 Mon Sep 17 00:00:00 2001 From: Kevin Traynor Date: Fri, 15 May 2020 15:28:08 +0100 Subject: [PATCH] hash: fix gcc 10 maybe-uninitialized warning MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit gcc 10.1.1 reports a warning for the ext_bkt_id variable: ../lib/librte_hash/rte_cuckoo_hash.c: In function ‘__rte_hash_add_key_with_hash’: ../lib/librte_hash/rte_cuckoo_hash.c:1104:29: warning: ‘ext_bkt_id’ may be used uninitialized in this function [-Wmaybe-uninitialized] 1104 | (h->buckets_ext[ext_bkt_id - 1]).sig_current[0] = short_sig; | ~~~~~~~~~~~^~~ The return value of rte_ring_sc_dequeue_elem() is already checked, but also initialize ext_bkt_id to zero (invalid value) and check that it also overwritten. Fixes: fbfe568103b0 ("hash: use 32-bit elements rings to save memory") Cc: stable@dpdk.org Signed-off-by: Kevin Traynor Acked-by: Yipeng Wang --- lib/librte_hash/rte_cuckoo_hash.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 38767a8a16..90cb99b0ee 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -939,8 +939,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, uint32_t prim_bucket_idx, sec_bucket_idx; struct rte_hash_bucket *prim_bkt, *sec_bkt, *cur_bkt; struct rte_hash_key *new_k, *keys = h->key_store; + uint32_t ext_bkt_id = 0; uint32_t slot_id; - uint32_t ext_bkt_id; int ret; unsigned n_slots; unsigned lcore_id; @@ -1095,7 +1095,8 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, * extendable bucket. We first get a free bucket from ring. */ if (rte_ring_sc_dequeue_elem(h->free_ext_bkts, &ext_bkt_id, - sizeof(uint32_t)) != 0) { + sizeof(uint32_t)) != 0 || + ext_bkt_id == 0) { ret = -ENOSPC; goto failure; } -- 2.20.1