From: Bing Zhao <bingz@nvidia.com>
To: <viacheslavo@nvidia.com>, <matan@nvidia.com>, <thomas@monjalon.net>
Cc: <dev@dpdk.org>, <rasland@nvidia.com>, <alialnu@nvidia.com>,
<stable@dpdk.org>
Subject: [PATCH] net/mlx5: fix the building with flexible array
Date: Mon, 31 Oct 2022 20:24:56 +0200 [thread overview]
Message-ID: <20221031182456.432384-1-bingz@nvidia.com> (raw)
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
next reply other threads:[~2022-10-31 18:25 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-10-31 18:24 Bing Zhao [this message]
2022-10-31 20:13 ` Thomas Monjalon
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221031182456.432384-1-bingz@nvidia.com \
--to=bingz@nvidia.com \
--cc=alialnu@nvidia.com \
--cc=dev@dpdk.org \
--cc=matan@nvidia.com \
--cc=rasland@nvidia.com \
--cc=stable@dpdk.org \
--cc=thomas@monjalon.net \
--cc=viacheslavo@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).