net/mlx5: fix clang build
authorNélio Laranjeiro <nelio.laranjeiro@6wind.com>
Wed, 30 Aug 2017 14:47:06 +0000 (16:47 +0200)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 6 Oct 2017 00:49:47 +0000 (02:49 +0200)
On redhat 7.2 clang reports the following error:
   CC mlx5_rxmode.o
 /drivers/net/mlx5/mlx5_ethdev.c:820:32: error: field 'edata' with
 variable sized type 'struct ethtool_link_settings' not at the end
 of a struct or class is a GNU extension
 [-Werror,-Wgnu-variable-sized-type-not-at-end]
      struct ethtool_link_settings edata;

Use alternative approach to reserve buffer space on the stack.

Fixes: ef09a7fc7620 ("net/mlx5: fix inconsistent link status query")
Cc: stable@dpdk.org
Signed-off-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
Acked-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
drivers/net/mlx5/mlx5_ethdev.c

index 57f6237..0d2dae4 100644 (file)
@@ -49,6 +49,7 @@
 #include <linux/sockios.h>
 #include <linux/version.h>
 #include <fcntl.h>
+#include <stdalign.h>
 
 #include <rte_atomic.h>
 #include <rte_ethdev.h>
@@ -804,12 +805,11 @@ static int
 mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev, int wait_to_complete)
 {
        struct priv *priv = mlx5_get_priv(dev);
-       __extension__ struct {
-               struct ethtool_link_settings edata;
-               uint32_t link_mode_data[3 *
-                                       ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32];
-       } ecmd;
-
+       alignas(struct ethtool_link_settings)
+       uint8_t data[offsetof(struct ethtool_link_settings, link_mode_masks) +
+                    sizeof(uint32_t) *
+                    ETHTOOL_LINK_MODE_MASK_MAX_KERNEL_NU32 * 3];
+       struct ethtool_link_settings *ecmd = (void *)data;
        struct ifreq ifr;
        struct rte_eth_link dev_link;
        uint64_t sc;
@@ -822,23 +822,23 @@ mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev, int wait_to_complete)
        memset(&dev_link, 0, sizeof(dev_link));
        dev_link.link_status = ((ifr.ifr_flags & IFF_UP) &&
                                (ifr.ifr_flags & IFF_RUNNING));
-       memset(&ecmd, 0, sizeof(ecmd));
-       ecmd.edata.cmd = ETHTOOL_GLINKSETTINGS;
-       ifr.ifr_data = (void *)&ecmd;
+       memset(ecmd, 0, sizeof(*ecmd));
+       ecmd->cmd = ETHTOOL_GLINKSETTINGS;
+       ifr.ifr_data = (void *)ecmd;
        if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
                DEBUG("ioctl(SIOCETHTOOL, ETHTOOL_GLINKSETTINGS) failed: %s",
                      strerror(errno));
                return -1;
        }
-       ecmd.edata.link_mode_masks_nwords = -ecmd.edata.link_mode_masks_nwords;
+       ecmd->link_mode_masks_nwords = -ecmd->link_mode_masks_nwords;
        if (priv_ifreq(priv, SIOCETHTOOL, &ifr)) {
                DEBUG("ioctl(SIOCETHTOOL, ETHTOOL_GLINKSETTINGS) failed: %s",
                      strerror(errno));
                return -1;
        }
-       dev_link.link_speed = ecmd.edata.speed;
-       sc = ecmd.edata.link_mode_masks[0] |
-               ((uint64_t)ecmd.edata.link_mode_masks[1] << 32);
+       dev_link.link_speed = ecmd->speed;
+       sc = ecmd->link_mode_masks[0] |
+               ((uint64_t)ecmd->link_mode_masks[1] << 32);
        priv->link_speed_capa = 0;
        if (sc & ETHTOOL_LINK_MODE_Autoneg_BIT)
                priv->link_speed_capa |= ETH_LINK_SPEED_AUTONEG;
@@ -874,7 +874,7 @@ mlx5_link_update_unlocked_gs(struct rte_eth_dev *dev, int wait_to_complete)
                  ETHTOOL_LINK_MODE_100000baseCR4_Full_BIT |
                  ETHTOOL_LINK_MODE_100000baseLR4_ER4_Full_BIT))
                priv->link_speed_capa |= ETH_LINK_SPEED_100G;
-       dev_link.link_duplex = ((ecmd.edata.duplex == DUPLEX_HALF) ?
+       dev_link.link_duplex = ((ecmd->duplex == DUPLEX_HALF) ?
                                ETH_LINK_HALF_DUPLEX : ETH_LINK_FULL_DUPLEX);
        dev_link.link_autoneg = !(dev->data->dev_conf.link_speeds &
                                  ETH_LINK_SPEED_FIXED);