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 F21422C08 for ; Tue, 5 Apr 2016 13:54:06 +0200 (CEST) Received: from glumotte.dev.6wind.com (unknown [10.16.0.195]) by proxy.6wind.com (Postfix) with ESMTP id E9A6D260FC; Tue, 5 Apr 2016 13:53:23 +0200 (CEST) From: Olivier Matz To: dev@dpdk.org Cc: bruce.richardson@intel.com, pablo.de.lara.guarch@intel.com Date: Tue, 5 Apr 2016 13:53:46 +0200 Message-Id: <1459857229-9814-2-git-send-email-olivier.matz@6wind.com> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1459857229-9814-1-git-send-email-olivier.matz@6wind.com> References: <1459841759-23296-1-git-send-email-olivier.matz@6wind.com> <1459857229-9814-1-git-send-email-olivier.matz@6wind.com> Subject: [dpdk-dev] [PATCH v3 1/4] lpm: 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: Tue, 05 Apr 2016 11:54:07 -0000 Change rte_lpm*_create() functions to return NULL and set rte_errno to EEXIST when the object name already exists. This is the behavior described in the API documentation in the header file. 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 lpm API more consistent with the other APIs (mempool, rings, ...). Fixes: 899d8bc9b3 ("lpm: make tailq fully local") Signed-off-by: Olivier Matz --- app/test/test_lpm6.c | 2 +- lib/librte_lpm/rte_lpm.c | 10 ++++++++-- lib/librte_lpm/rte_lpm6.c | 5 ++++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/test/test_lpm6.c b/app/test/test_lpm6.c index 1f88d7a..b464342 100644 --- a/app/test/test_lpm6.c +++ b/app/test/test_lpm6.c @@ -222,7 +222,7 @@ test1(void) /* rte_lpm6_create: lpm name == LPM2 */ lpm3 = rte_lpm6_create("LPM1", SOCKET_ID_ANY, &config); - TEST_LPM_ASSERT(lpm3 == lpm1); + TEST_LPM_ASSERT(lpm3 == NULL); rte_lpm6_free(lpm1); rte_lpm6_free(lpm2); diff --git a/lib/librte_lpm/rte_lpm.c b/lib/librte_lpm/rte_lpm.c index bd3563f..8bdf606 100644 --- a/lib/librte_lpm/rte_lpm.c +++ b/lib/librte_lpm/rte_lpm.c @@ -209,8 +209,11 @@ rte_lpm_create_v20(const char *name, int socket_id, int max_rules, if (strncmp(name, lpm->name, RTE_LPM_NAMESIZE) == 0) break; } - if (te != NULL) + lpm = NULL; + if (te != NULL) { + rte_errno = EEXIST; goto exit; + } /* allocate tailq entry */ te = rte_zmalloc("LPM_TAILQ_ENTRY", sizeof(*te), 0); @@ -280,8 +283,11 @@ rte_lpm_create_v1604(const char *name, int socket_id, if (strncmp(name, lpm->name, RTE_LPM_NAMESIZE) == 0) break; } - if (te != NULL) + lpm = NULL; + if (te != NULL) { + rte_errno = EEXIST; goto exit; + } /* allocate tailq entry */ te = rte_zmalloc("LPM_TAILQ_ENTRY", sizeof(*te), 0); diff --git a/lib/librte_lpm/rte_lpm6.c b/lib/librte_lpm/rte_lpm6.c index 4c44cd7..ba4353c 100644 --- a/lib/librte_lpm/rte_lpm6.c +++ b/lib/librte_lpm/rte_lpm6.c @@ -182,8 +182,11 @@ rte_lpm6_create(const char *name, int socket_id, if (strncmp(name, lpm->name, RTE_LPM6_NAMESIZE) == 0) break; } - if (te != NULL) + lpm = NULL; + if (te != NULL) { + rte_errno = EEXIST; goto exit; + } /* allocate tailq entry */ te = rte_zmalloc("LPM6_TAILQ_ENTRY", sizeof(*te), 0); -- 2.1.4