From patchwork Fri May 15 14:28:08 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kevin Traynor X-Patchwork-Id: 70333 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from dpdk.org (dpdk.org [92.243.14.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2F5E0A00C3; Fri, 15 May 2020 16:28:43 +0200 (CEST) Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 5B6901DA4B; Fri, 15 May 2020 16:28:41 +0200 (CEST) Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [205.139.110.120]) by dpdk.org (Postfix) with ESMTP id 8CC421DA15 for ; Fri, 15 May 2020 16:28:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1589552918; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=I40OIAx6P8d2B5yNq37AyOqpPlklVPCUpAYOpGxY37o=; b=WR5DqLAHUA2/4ncvqQIFXiqnh79jnPiJ21zrNrESm83cCgjblHcsbhb5Tk/G/JigPbs15K uQStl3APBvV1GGK45oL1Hzu52F0KKS3kTU2IdrQWdrKgrf+ZiCXlpn4XybDVZG9cEdOEYN wfeKOKdyimgsjhg5N9W+FUya7kiFirU= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-136-2ReA8LMQO_iccliIyot9ew-1; Fri, 15 May 2020 10:28:35 -0400 X-MC-Unique: 2ReA8LMQO_iccliIyot9ew-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id F186B1800D4A; Fri, 15 May 2020 14:28:33 +0000 (UTC) Received: from rh.redhat.com (unknown [10.33.36.145]) by smtp.corp.redhat.com (Postfix) with ESMTP id EC3892E170; Fri, 15 May 2020 14:28:27 +0000 (UTC) From: Kevin Traynor To: dev@dpdk.org, yipeng1.wang@intel.com, sameh.gobriel@intel.com, bruce.richardson@intel.com Cc: honnappa.nagarahalli@arm.com, ferruh.yigit@intel.com, david.marchand@redhat.com, Kevin Traynor , stable@dpdk.org Date: Fri, 15 May 2020 15:28:08 +0100 Message-Id: <20200515142808.14064-1-ktraynor@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Subject: [dpdk-dev] [PATCH] hash: fix gcc 10 maybe-uninitialized warning 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" 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 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 38767a8a1..90cb99b0e 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -940,6 +940,6 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, 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; @@ -1096,5 +1096,6 @@ __rte_hash_add_key_with_hash(const struct rte_hash *h, const void *key, */ 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;