summaryrefslogtreecommitdiff
path: root/lib/librte_lpm
diff options
context:
space:
mode:
authorOlivier Matz <olivier.matz@6wind.com>2016-04-06 15:27:58 +0200
committerThomas Monjalon <thomas.monjalon@6wind.com>2016-04-06 17:30:06 +0200
commitf82f705b635d31a63446a16bc4526dbebf293c5a (patch)
treee7e91433e292d5cbce7193d7569d3c8d0a4adc58 /lib/librte_lpm
parent4c50e2f6bf412544ae02a1fe4e04622d12953fd9 (diff)
downloaddpdk-f82f705b635d31a63446a16bc4526dbebf293c5a.zip
dpdk-f82f705b635d31a63446a16bc4526dbebf293c5a.tar.gz
dpdk-f82f705b635d31a63446a16bc4526dbebf293c5a.tar.xz
lpm: fix allocation of an existing object
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: 916e4f4f4e ("memory: fix for multi process support") Signed-off-by: Olivier Matz <olivier.matz@6wind.com> Acked-by: Pablo de Lara <pablo.de.lara.guarch@intel.com>
Diffstat (limited to 'lib/librte_lpm')
-rw-r--r--lib/librte_lpm/rte_lpm.c10
-rw-r--r--lib/librte_lpm/rte_lpm6.c5
2 files changed, 12 insertions, 3 deletions
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);