net/mlx5: fix build with recent compilers

With some higher GCC/CLANG version, it is not recommended to use a
structure with a tailing flexible array inside another structure.
Accessing this array may be considered as a risk to corrupt the
following field even if it is by intention.

The error below was observed:

  drivers/net/mlx5/linux/mlx5_ethdev_os.c: In function 'mlx5_get_flag_dropless_rq':
  drivers/net/mlx5/linux/mlx5_ethdev_os.c:1679:42: error:
  invalid use of structure with flexible array member [-Werror=pedantic]
  1679 | struct ethtool_sset_info hdr;
       | ^~~

Changing it to memory dynamic allocation method will help to get
rid of this complain.

Fixes: e848218741 ("net/mlx5: check delay drop settings in kernel driver")
Cc: stable@dpdk.org

Signed-off-by: Bing Zhao <bingz@nvidia.com>
Acked-by: Thomas Monjalon <thomas@monjalon.net>
This commit is contained in:
Bing Zhao 2022-10-31 20:24:56 +02:00 committed by Thomas Monjalon
parent 6a88cbc541
commit ccc6ea5d9c

View File

@ -1675,10 +1675,7 @@ mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN])
*/ */
int mlx5_get_flag_dropless_rq(struct rte_eth_dev *dev) int mlx5_get_flag_dropless_rq(struct rte_eth_dev *dev)
{ {
struct { struct ethtool_sset_info *sset_info = NULL;
struct ethtool_sset_info hdr;
uint32_t buf[1];
} sset_info;
struct ethtool_drvinfo drvinfo; struct ethtool_drvinfo drvinfo;
struct ifreq ifr; struct ifreq ifr;
struct ethtool_gstrings *strings = NULL; struct ethtool_gstrings *strings = NULL;
@ -1689,15 +1686,21 @@ int mlx5_get_flag_dropless_rq(struct rte_eth_dev *dev)
int32_t i; int32_t i;
int ret; int ret;
sset_info.hdr.cmd = ETHTOOL_GSSET_INFO; sset_info = mlx5_malloc(0, sizeof(struct ethtool_sset_info) +
sset_info.hdr.reserved = 0; sizeof(uint32_t), 0, SOCKET_ID_ANY);
sset_info.hdr.sset_mask = 1ULL << ETH_SS_PRIV_FLAGS; if (sset_info == NULL) {
rte_errno = ENOMEM;
return -rte_errno;
}
sset_info->cmd = ETHTOOL_GSSET_INFO;
sset_info->reserved = 0;
sset_info->sset_mask = 1ULL << ETH_SS_PRIV_FLAGS;
ifr.ifr_data = (caddr_t)&sset_info; ifr.ifr_data = (caddr_t)&sset_info;
ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr); ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
if (!ret) { if (!ret) {
const uint32_t *sset_lengths = sset_info.hdr.data; const uint32_t *sset_lengths = sset_info->data;
len = sset_info.hdr.sset_mask ? sset_lengths[0] : 0; len = sset_info->sset_mask ? sset_lengths[0] : 0;
} else if (ret == -EOPNOTSUPP) { } else if (ret == -EOPNOTSUPP) {
drvinfo.cmd = ETHTOOL_GDRVINFO; drvinfo.cmd = ETHTOOL_GDRVINFO;
ifr.ifr_data = (caddr_t)&drvinfo; ifr.ifr_data = (caddr_t)&drvinfo;
@ -1770,5 +1773,6 @@ int mlx5_get_flag_dropless_rq(struct rte_eth_dev *dev)
ret = !!(flags.data & (1U << i)); ret = !!(flags.data & (1U << i));
exit: exit:
mlx5_free(strings); mlx5_free(strings);
mlx5_free(sset_info);
return ret; return ret;
} }