net/virtio: fix incorrect cast of void *
[dpdk.git] / lib / librte_lpm / rte_lpm.c
index 24fec4b..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>
@@ -219,6 +217,7 @@ rte_lpm_create_v20(const char *name, int socket_id, int max_rules,
        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;
        }
 
@@ -228,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;
        }
 
@@ -293,6 +293,7 @@ rte_lpm_create_v1604(const char *name, int socket_id,
        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;
        }
 
@@ -302,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;
        }
 
@@ -313,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;
        }
 
@@ -321,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;
        }
 
@@ -402,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);
@@ -940,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;
                }
 
                /*
@@ -1037,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,
@@ -1071,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;
                }
 
                /*
@@ -1088,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,