remove useless memzone includes
[dpdk.git] / lib / librte_lpm / rte_lpm.c
index bd3563f..e1f1fad 100644 (file)
@@ -36,7 +36,6 @@
 #include <errno.h>
 #include <stdarg.h>
 #include <stdio.h>
-#include <errno.h>
 #include <sys/queue.h>
 
 #include <rte_log.h>
@@ -44,7 +43,6 @@
 #include <rte_common.h>
 #include <rte_memory.h>        /* for definition of RTE_CACHE_LINE_SIZE */
 #include <rte_malloc.h>
-#include <rte_memzone.h>
 #include <rte_eal.h>
 #include <rte_eal_memconfig.h>
 #include <rte_per_lcore.h>
@@ -209,13 +207,17 @@ 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);
        if (te == NULL) {
                RTE_LOG(ERR, LPM, "Failed to allocate tailq entry\n");
+               rte_errno = ENOMEM;
                goto exit;
        }
 
@@ -225,6 +227,7 @@ rte_lpm_create_v20(const char *name, int socket_id, int max_rules,
        if (lpm == NULL) {
                RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
                rte_free(te);
+               rte_errno = ENOMEM;
                goto exit;
        }
 
@@ -280,13 +283,17 @@ 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);
        if (te == NULL) {
                RTE_LOG(ERR, LPM, "Failed to allocate tailq entry\n");
+               rte_errno = ENOMEM;
                goto exit;
        }
 
@@ -296,6 +303,7 @@ rte_lpm_create_v1604(const char *name, int socket_id,
        if (lpm == NULL) {
                RTE_LOG(ERR, LPM, "LPM memory allocation failed\n");
                rte_free(te);
+               rte_errno = ENOMEM;
                goto exit;
        }
 
@@ -307,6 +315,7 @@ rte_lpm_create_v1604(const char *name, int socket_id,
                rte_free(lpm);
                lpm = NULL;
                rte_free(te);
+               rte_errno = ENOMEM;
                goto exit;
        }
 
@@ -315,9 +324,11 @@ rte_lpm_create_v1604(const char *name, int socket_id,
 
        if (lpm->tbl8 == NULL) {
                RTE_LOG(ERR, LPM, "LPM tbl8 memory allocation failed\n");
+               rte_free(lpm->rules_tbl);
                rte_free(lpm);
                lpm = NULL;
                rte_free(te);
+               rte_errno = ENOMEM;
                goto exit;
        }
 
@@ -367,7 +378,6 @@ rte_lpm_free_v20(struct rte_lpm_v20 *lpm)
 
        rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
 
-       rte_free(lpm->rules_tbl);
        rte_free(lpm);
        rte_free(te);
 }
@@ -397,6 +407,7 @@ rte_lpm_free_v1604(struct rte_lpm *lpm)
 
        rte_rwlock_write_unlock(RTE_EAL_TAILQ_RWLOCK);
 
+       rte_free(lpm->tbl8);
        rte_free(lpm->rules_tbl);
        rte_free(lpm);
        rte_free(te);
@@ -935,14 +946,9 @@ add_depth_big_v20(struct rte_lpm_v20 *lpm, uint32_t ip_masked, uint8_t depth,
 
                /* Insert new rule into the tbl8 entry. */
                for (i = tbl8_index; i < tbl8_index + tbl8_range; i++) {
-                       if (!lpm->tbl8[i].valid ||
-                                       lpm->tbl8[i].depth <= depth) {
-                               lpm->tbl8[i].valid = VALID;
-                               lpm->tbl8[i].depth = depth;
-                               lpm->tbl8[i].next_hop = next_hop;
-
-                               continue;
-                       }
+                       lpm->tbl8[i].valid = VALID;
+                       lpm->tbl8[i].depth = depth;
+                       lpm->tbl8[i].next_hop = next_hop;
                }
 
                /*
@@ -1032,7 +1038,7 @@ add_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
                 */
 
                struct rte_lpm_tbl_entry new_tbl24_entry = {
-                       .group_idx = (uint8_t)tbl8_group_index,
+                       .group_idx = tbl8_group_index,
                        .valid = VALID,
                        .valid_group = 1,
                        .depth = 0,
@@ -1066,14 +1072,9 @@ add_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
 
                /* Insert new rule into the tbl8 entry. */
                for (i = tbl8_index; i < tbl8_index + tbl8_range; i++) {
-                       if (!lpm->tbl8[i].valid ||
-                                       lpm->tbl8[i].depth <= depth) {
-                               lpm->tbl8[i].valid = VALID;
-                               lpm->tbl8[i].depth = depth;
-                               lpm->tbl8[i].next_hop = next_hop;
-
-                               continue;
-                       }
+                       lpm->tbl8[i].valid = VALID;
+                       lpm->tbl8[i].depth = depth;
+                       lpm->tbl8[i].next_hop = next_hop;
                }
 
                /*
@@ -1083,7 +1084,7 @@ add_depth_big_v1604(struct rte_lpm *lpm, uint32_t ip_masked, uint8_t depth,
                 */
 
                struct rte_lpm_tbl_entry new_tbl24_entry = {
-                               .group_idx = (uint8_t)tbl8_group_index,
+                               .group_idx = tbl8_group_index,
                                .valid = VALID,
                                .valid_group = 1,
                                .depth = 0,
@@ -1528,7 +1529,7 @@ tbl8_recycle_check_v20(struct rte_lpm_tbl_entry_v20 *tbl8,
                 * and if so check the rest of the entries to verify that they
                 * are all of this depth.
                 */
-               if (tbl8[tbl8_group_start].depth < MAX_DEPTH_TBL24) {
+               if (tbl8[tbl8_group_start].depth <= MAX_DEPTH_TBL24) {
                        for (i = (tbl8_group_start + 1); i < tbl8_group_end;
                                        i++) {
 
@@ -1575,7 +1576,7 @@ tbl8_recycle_check_v1604(struct rte_lpm_tbl_entry *tbl8,
                 * and if so check the rest of the entries to verify that they
                 * are all of this depth.
                 */
-               if (tbl8[tbl8_group_start].depth < MAX_DEPTH_TBL24) {
+               if (tbl8[tbl8_group_start].depth <= MAX_DEPTH_TBL24) {
                        for (i = (tbl8_group_start + 1); i < tbl8_group_end;
                                        i++) {