DPDK patches and discussions
 help / color / mirror / Atom feed
* [PATCH] net/mlx5: fix the building with flexible array
@ 2022-10-31 18:24 Bing Zhao
  2022-10-31 20:13 ` Thomas Monjalon
  0 siblings, 1 reply; 2+ messages in thread
From: Bing Zhao @ 2022-10-31 18:24 UTC (permalink / raw)
  To: viacheslavo, matan, thomas; +Cc: dev, rasland, alialnu, stable

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: e848218741ea ("net/mlx5: check delay drop settings in kernel driver")
Cc: stable@dpdk.org

Signed-off-by: Bing Zhao <bingz@nvidia.com>
---
 drivers/net/mlx5/linux/mlx5_ethdev_os.c | 22 +++++++++++++---------
 1 file changed, 13 insertions(+), 9 deletions(-)

diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
index 661d362dc0..d8bb03b875 100644
--- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c
+++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
@@ -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)
 {
-	struct {
-		struct ethtool_sset_info hdr;
-		uint32_t buf[1];
-	} sset_info;
+	struct ethtool_sset_info *sset_info = NULL;
 	struct ethtool_drvinfo drvinfo;
 	struct ifreq ifr;
 	struct ethtool_gstrings *strings = NULL;
@@ -1689,15 +1686,21 @@ int mlx5_get_flag_dropless_rq(struct rte_eth_dev *dev)
 	int32_t i;
 	int ret;
 
-	sset_info.hdr.cmd = ETHTOOL_GSSET_INFO;
-	sset_info.hdr.reserved = 0;
-	sset_info.hdr.sset_mask = 1ULL << ETH_SS_PRIV_FLAGS;
+	sset_info = mlx5_malloc(0, sizeof(struct ethtool_sset_info) +
+				sizeof(uint32_t), 0, SOCKET_ID_ANY);
+	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;
 	ret = mlx5_ifreq(dev, SIOCETHTOOL, &ifr);
 	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) {
 		drvinfo.cmd = ETHTOOL_GDRVINFO;
 		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));
 exit:
 	mlx5_free(strings);
+	mlx5_free(sset_info);
 	return ret;
 }
-- 
2.21.0


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-10-31 20:13 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-10-31 18:24 [PATCH] net/mlx5: fix the building with flexible array Bing Zhao
2022-10-31 20:13 ` Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).