From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from proxy.6wind.com (host.76.145.23.62.rev.coltfrance.com [62.23.145.76]) by dpdk.org (Postfix) with ESMTP id AC2102C0F for ; Wed, 30 Mar 2016 17:31:06 +0200 (CEST) Received: from glumotte.dev.6wind.com (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id AB45628003; Wed, 30 Mar 2016 17:30:23 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Cc: bruce.richardson@intel.com Date: Wed, 30 Mar 2016 17:30:25 +0200 Message-Id: <1459351827-3346-3-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1459351827-3346-1-git-send-email-olivier.matz@6wind.com> References: <1458044745-32764-1-git-send-email-olivier.matz@6wind.com> <1459351827-3346-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH 2/4] hash: allocation of an existing object should fail X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 30 Mar 2016 15:31:06 -0000 Change the API of rte_hash*_create() functions to return NULL and set rte_errno to EEXIST when the object name already exists. These functions were returning a pointer to the existing object in that case, but it is a problem as the caller did not know if the object had to be freed or not. Doing this change also makes the hash API more consistent with the other APIs (mempool, rings, ...). Signed-off-by: Olivier Matz --- lib/librte_hash/rte_cuckoo_hash.c | 6 ++++-- lib/librte_hash/rte_fbk_hash.c | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/librte_hash/rte_cuckoo_hash.c b/lib/librte_hash/rte_cuckoo_hash.c index 71b5b76..ccec2db 100644 --- a/lib/librte_hash/rte_cuckoo_hash.c +++ b/lib/librte_hash/rte_cuckoo_hash.c @@ -230,8 +230,10 @@ rte_hash_create(const struct rte_hash_parameters *params) /* Guarantee there's no existing */ h = rte_hash_find_existing(params->name); - if (h != NULL) - return h; + if (h != NULL) { + rte_errno = EEXIST; + return NULL; + } te = rte_zmalloc("HASH_TAILQ_ENTRY", sizeof(*te), 0); if (te == NULL) { diff --git a/lib/librte_hash/rte_fbk_hash.c b/lib/librte_hash/rte_fbk_hash.c index 8752a47..ba1e475 100644 --- a/lib/librte_hash/rte_fbk_hash.c +++ b/lib/librte_hash/rte_fbk_hash.c @@ -140,8 +140,11 @@ rte_fbk_hash_create(const struct rte_fbk_hash_params *params) if (strncmp(params->name, ht->name, RTE_FBK_HASH_NAMESIZE) == 0) break; } - if (te != NULL) + if (te != NULL) { + ht = NULL; + rte_errno = EEXIST; goto exit; + } te = rte_zmalloc("FBK_HASH_TAILQ_ENTRY", sizeof(*te), 0); if (te == NULL) { -- 2.1.4