]> git.droids-corp.org - dpdk.git/commitdiff
lpm: fix allocation of an existing object
authorOlivier Matz <olivier.matz@6wind.com>
Wed, 6 Apr 2016 13:27:58 +0000 (15:27 +0200)
committerThomas Monjalon <thomas.monjalon@6wind.com>
Wed, 6 Apr 2016 15:30:06 +0000 (17:30 +0200)
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>
app/test/test_lpm6.c
doc/guides/rel_notes/release_16_04.rst
lib/librte_lpm/rte_lpm.c
lib/librte_lpm/rte_lpm6.c

index 1f88d7ad46994b4d16b504867166bf27e8046191..b464342c2690327e7e45764f1c8237b0ec43cbfd 100644 (file)
@@ -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);
index 1acc63a5271cdca0a1eb53b64656cd73591735e5..b0f3dbabf42e05aaa3016d57be86deb5a81a1913 100644 (file)
@@ -434,6 +434,15 @@ Libraries
   however a custom compare function (not in the jump table) can only
   be used in single-process mode.
 
+* **lpm: Fixed return value when allocating an existing object.**
+
+  Changed the ``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.
+  The previous behavior was to return a pointer to the existing object in
+  that case, preventing the caller to know if the object had to be freed
+  or not.
+
 * **librte_port: Fixed segmentation fault for ring and ethdev writer nodrop.**
 
   Fixed core dump issue on txq and swq when dropless is set to yes.
index bd3563f3a822be3657bd97268987e5418da74e4d..8bdf60657f8a069da5a6dd221cd89d3577f74037 100644 (file)
@@ -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);
index 4c44cd754192bb7764ae1a61d54df67572bc0b6c..ba4353cedfdf1c807f5a6a578e9aa22aa4e16a68 100644 (file)
@@ -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);