net/mlx5: add more checks on MAC addresses
authorNélio Laranjeiro <nelio.laranjeiro@6wind.com>
Mon, 23 Apr 2018 11:09:26 +0000 (13:09 +0200)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 27 Apr 2018 16:34:43 +0000 (17:34 +0100)
Verify MAC address before further process.

Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
drivers/net/mlx5/mlx5_mac.c

index edc7a32..f24b5f7 100644 (file)
@@ -71,7 +71,10 @@ mlx5_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
        const int vf = priv->config.vf;
        int ret;
 
-       assert(index < MLX5_MAX_MAC_ADDRESSES);
+       if (index >= MLX5_MAX_MAC_ADDRESSES)
+               return;
+       if (is_zero_ether_addr(&dev->data->mac_addrs[index]))
+               return;
        if (vf)
                mlx5_nl_mac_addr_remove(dev, &dev->data->mac_addrs[index],
                                        index);
@@ -107,7 +110,14 @@ mlx5_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac,
        const int vf = priv->config.vf;
        unsigned int i;
 
-       assert(index < MLX5_MAX_MAC_ADDRESSES);
+       if (index >= MLX5_MAX_MAC_ADDRESSES) {
+               rte_errno = EINVAL;
+               return -rte_errno;
+       }
+       if (is_zero_ether_addr(mac)) {
+               rte_errno = EINVAL;
+               return -rte_errno;
+       }
        /* First, make sure this address isn't already configured. */
        for (i = 0; (i != MLX5_MAX_MAC_ADDRESSES); ++i) {
                /* Skip this index, it's going to be reconfigured. */