net/virtio: fix memory leak when reinitializing device
[dpdk.git] / drivers / net / i40e / i40e_ethdev.c
index 9dad227..277c1a8 100644 (file)
@@ -16,7 +16,7 @@
 #include <rte_pci.h>
 #include <rte_bus_pci.h>
 #include <rte_ether.h>
-#include <rte_ethdev.h>
+#include <rte_ethdev_driver.h>
 #include <rte_ethdev_pci.h>
 #include <rte_memzone.h>
 #include <rte_malloc.h>
@@ -7188,11 +7188,13 @@ i40e_dev_tunnel_filter_set(struct i40e_pf *pf,
        node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
        if (add && node) {
                PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
+               rte_free(cld_filter);
                return -EINVAL;
        }
 
        if (!add && !node) {
                PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
+               rte_free(cld_filter);
                return -EINVAL;
        }
 
@@ -7201,16 +7203,26 @@ i40e_dev_tunnel_filter_set(struct i40e_pf *pf,
                                        vsi->seid, &cld_filter->element, 1);
                if (ret < 0) {
                        PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
+                       rte_free(cld_filter);
                        return -ENOTSUP;
                }
                tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
+               if (tunnel == NULL) {
+                       PMD_DRV_LOG(ERR, "Failed to alloc memory.");
+                       rte_free(cld_filter);
+                       return -ENOMEM;
+               }
+
                rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
                ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
+               if (ret < 0)
+                       rte_free(tunnel);
        } else {
                ret = i40e_aq_remove_cloud_filters(hw, vsi->seid,
                                                   &cld_filter->element, 1);
                if (ret < 0) {
                        PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
+                       rte_free(cld_filter);
                        return -ENOTSUP;
                }
                ret = i40e_sw_tunnel_filter_del(pf, &node->input);
@@ -7639,6 +7651,7 @@ i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
        else {
                if (tunnel_filter->vf_id >= pf->vf_num) {
                        PMD_DRV_LOG(ERR, "Invalid argument.");
+                       rte_free(cld_filter);
                        return -EINVAL;
                }
                vf = &pf->vfs[tunnel_filter->vf_id];
@@ -7653,11 +7666,13 @@ i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
        node = i40e_sw_tunnel_filter_lookup(tunnel_rule, &check_filter.input);
        if (add && node) {
                PMD_DRV_LOG(ERR, "Conflict with existing tunnel rules!");
+               rte_free(cld_filter);
                return -EINVAL;
        }
 
        if (!add && !node) {
                PMD_DRV_LOG(ERR, "There's no corresponding tunnel filter!");
+               rte_free(cld_filter);
                return -EINVAL;
        }
 
@@ -7670,11 +7685,20 @@ i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
                                        vsi->seid, &cld_filter->element, 1);
                if (ret < 0) {
                        PMD_DRV_LOG(ERR, "Failed to add a tunnel filter.");
+                       rte_free(cld_filter);
                        return -ENOTSUP;
                }
                tunnel = rte_zmalloc("tunnel_filter", sizeof(*tunnel), 0);
+               if (tunnel == NULL) {
+                       PMD_DRV_LOG(ERR, "Failed to alloc memory.");
+                       rte_free(cld_filter);
+                       return -ENOMEM;
+               }
+
                rte_memcpy(tunnel, &check_filter, sizeof(check_filter));
                ret = i40e_sw_tunnel_filter_insert(pf, tunnel);
+               if (ret < 0)
+                       rte_free(tunnel);
        } else {
                if (big_buffer)
                        ret = i40e_aq_remove_cloud_filters_big_buffer(
@@ -7684,6 +7708,7 @@ i40e_dev_consistent_tunnel_filter_set(struct i40e_pf *pf,
                                                   &cld_filter->element, 1);
                if (ret < 0) {
                        PMD_DRV_LOG(ERR, "Failed to delete a tunnel filter.");
+                       rte_free(cld_filter);
                        return -ENOTSUP;
                }
                ret = i40e_sw_tunnel_filter_del(pf, &node->input);
@@ -9295,9 +9320,16 @@ i40e_ethertype_filter_set(struct i40e_pf *pf,
        if (add) {
                ethertype_filter = rte_zmalloc("ethertype_filter",
                                       sizeof(*ethertype_filter), 0);
+               if (ethertype_filter == NULL) {
+                       PMD_DRV_LOG(ERR, "Failed to alloc memory.");
+                       return -ENOMEM;
+               }
+
                rte_memcpy(ethertype_filter, &check_filter,
                           sizeof(check_filter));
                ret = i40e_sw_ethertype_filter_insert(pf, ethertype_filter);
+               if (ret < 0)
+                       rte_free(ethertype_filter);
        } else {
                ret = i40e_sw_ethertype_filter_del(pf, &node->input);
        }
@@ -11326,99 +11358,104 @@ i40e_update_customized_ptype(struct rte_eth_dev *dev, uint8_t *pkg,
                                        continue;
                                memset(name, 0, sizeof(name));
                                strcpy(name, proto[n].name);
-                               if (!strncmp(name, "PPPOE", 5))
+                               if (!strncasecmp(name, "PPPOE", 5))
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L2_ETHER_PPPOE;
-                               else if (!strncmp(name, "IPV4FRAG", 8) &&
+                               else if (!strncasecmp(name, "IPV4FRAG", 8) &&
                                         !in_tunnel) {
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L4_FRAG;
-                               } else if (!strncmp(name, "IPV4FRAG", 8) &&
+                               } else if (!strncasecmp(name, "IPV4FRAG", 8) &&
                                           in_tunnel) {
                                        ptype_mapping[i].sw_ptype |=
                                            RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_INNER_L4_FRAG;
-                               } else if (!strncmp(name, "OIPV4", 5)) {
+                               } else if (!strncasecmp(name, "OIPV4", 5)) {
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
                                        in_tunnel = true;
-                               } else if (!strncmp(name, "IPV4", 4) &&
+                               } else if (!strncasecmp(name, "IPV4", 4) &&
                                           !in_tunnel)
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L3_IPV4_EXT_UNKNOWN;
-                               else if (!strncmp(name, "IPV4", 4) &&
+                               else if (!strncasecmp(name, "IPV4", 4) &&
                                         in_tunnel)
                                        ptype_mapping[i].sw_ptype |=
                                            RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN;
-                               else if (!strncmp(name, "IPV6FRAG", 8) &&
+                               else if (!strncasecmp(name, "IPV6FRAG", 8) &&
                                         !in_tunnel) {
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L4_FRAG;
-                               } else if (!strncmp(name, "IPV6FRAG", 8) &&
+                               } else if (!strncasecmp(name, "IPV6FRAG", 8) &&
                                           in_tunnel) {
                                        ptype_mapping[i].sw_ptype |=
                                            RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_INNER_L4_FRAG;
-                               } else if (!strncmp(name, "OIPV6", 5)) {
+                               } else if (!strncasecmp(name, "OIPV6", 5)) {
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
                                        in_tunnel = true;
-                               } else if (!strncmp(name, "IPV6", 4) &&
+                               } else if (!strncasecmp(name, "IPV6", 4) &&
                                           !in_tunnel)
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L3_IPV6_EXT_UNKNOWN;
-                               else if (!strncmp(name, "IPV6", 4) &&
+                               else if (!strncasecmp(name, "IPV6", 4) &&
                                         in_tunnel)
                                        ptype_mapping[i].sw_ptype |=
                                            RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN;
-                               else if (!strncmp(name, "UDP", 3) && !in_tunnel)
+                               else if (!strncasecmp(name, "UDP", 3) &&
+                                        !in_tunnel)
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L4_UDP;
-                               else if (!strncmp(name, "UDP", 3) && in_tunnel)
+                               else if (!strncasecmp(name, "UDP", 3) &&
+                                        in_tunnel)
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_INNER_L4_UDP;
-                               else if (!strncmp(name, "TCP", 3) && !in_tunnel)
+                               else if (!strncasecmp(name, "TCP", 3) &&
+                                        !in_tunnel)
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L4_TCP;
-                               else if (!strncmp(name, "TCP", 3) && in_tunnel)
+                               else if (!strncasecmp(name, "TCP", 3) &&
+                                        in_tunnel)
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_INNER_L4_TCP;
-                               else if (!strncmp(name, "SCTP", 4) &&
+                               else if (!strncasecmp(name, "SCTP", 4) &&
                                         !in_tunnel)
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L4_SCTP;
-                               else if (!strncmp(name, "SCTP", 4) && in_tunnel)
+                               else if (!strncasecmp(name, "SCTP", 4) &&
+                                        in_tunnel)
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_INNER_L4_SCTP;
-                               else if ((!strncmp(name, "ICMP", 4) ||
-                                         !strncmp(name, "ICMPV6", 6)) &&
+                               else if ((!strncasecmp(name, "ICMP", 4) ||
+                                         !strncasecmp(name, "ICMPV6", 6)) &&
                                         !in_tunnel)
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_L4_ICMP;
-                               else if ((!strncmp(name, "ICMP", 4) ||
-                                         !strncmp(name, "ICMPV6", 6)) &&
+                               else if ((!strncasecmp(name, "ICMP", 4) ||
+                                         !strncasecmp(name, "ICMPV6", 6)) &&
                                         in_tunnel)
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_INNER_L4_ICMP;
-                               else if (!strncmp(name, "GTPC", 4)) {
+                               else if (!strncasecmp(name, "GTPC", 4)) {
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_TUNNEL_GTPC;
                                        in_tunnel = true;
-                               } else if (!strncmp(name, "GTPU", 4)) {
+                               } else if (!strncasecmp(name, "GTPU", 4)) {
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_TUNNEL_GTPU;
                                        in_tunnel = true;
-                               } else if (!strncmp(name, "GRENAT", 6)) {
+                               } else if (!strncasecmp(name, "GRENAT", 6)) {
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_TUNNEL_GRENAT;
                                        in_tunnel = true;
-                               } else if (!strncmp(name, "L2TPv2CTL", 9)) {
+                               } else if (!strncasecmp(name, "L2TPV2CTL", 9)) {
                                        ptype_mapping[i].sw_ptype |=
                                                RTE_PTYPE_TUNNEL_L2TP;
                                        in_tunnel = true;