* [PATCH] net/mlx5: fix interface name parameter definition
@ 2025-08-10 13:22 Gregory Etelson
2025-08-11 4:44 ` Stephen Hemminger
0 siblings, 1 reply; 3+ messages in thread
From: Gregory Etelson @ 2025-08-10 13:22 UTC (permalink / raw)
To: dev
Cc: getelson, ,
rasland, Dariusz Sosnowski, Viacheslav Ovsiienko, Bing Zhao,
Ori Kam, Suanming Mou, Matan Azrad, Ophir Munk
The patch fixes `ifname` parameter as a character buffer.
Fixes: 1256805dd54d ("net/mlx5: move Linux-specific functions")
Signed-off-by: Gregory Etelson <getelson@nvidia.com>
Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
---
drivers/net/mlx5/linux/mlx5_ethdev_os.c | 11 +++++------
drivers/net/mlx5/linux/mlx5_os.c | 2 +-
drivers/net/mlx5/mlx5.h | 3 +--
drivers/net/mlx5/windows/mlx5_ethdev_os.c | 4 ++--
4 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/drivers/net/mlx5/linux/mlx5_ethdev_os.c b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
index 9daeda5435..eeb95bead0 100644
--- a/drivers/net/mlx5/linux/mlx5_ethdev_os.c
+++ b/drivers/net/mlx5/linux/mlx5_ethdev_os.c
@@ -73,7 +73,7 @@ mlx5_auxiliary_get_ifindex(const char *sf_name)
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
int
-mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[MLX5_NAMESIZE])
+mlx5_get_ifname(const struct rte_eth_dev *dev, char ifname[MLX5_NAMESIZE])
{
struct mlx5_priv *priv = dev->data->dev_private;
unsigned int ifindex;
@@ -87,12 +87,11 @@ mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[MLX5_NAMESIZE])
ifindex = mlx5_ifindex(dev);
if (!ifindex) {
if (!priv->representor)
- return mlx5_get_ifname_sysfs(priv->sh->ibdev_path,
- *ifname);
+ return mlx5_get_ifname_sysfs(priv->sh->ibdev_path, ifname);
rte_errno = ENXIO;
return -rte_errno;
}
- if (if_indextoname(ifindex, &(*ifname)[0]))
+ if (if_indextoname(ifindex, ifname))
return 0;
rte_errno = errno;
return -rte_errno;
@@ -150,10 +149,10 @@ mlx5_ifreq_by_ifname(const char *ifname, int req, struct ifreq *ifr)
static int
mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr)
{
- char ifname[sizeof(ifr->ifr_name)];
+ char ifname[MLX5_NAMESIZE];
int ret;
- ret = mlx5_get_ifname(dev, &ifname);
+ ret = mlx5_get_ifname(dev, ifname);
if (ret)
return -rte_errno;
return mlx5_ifreq_by_ifname(ifname, req, ifr);
diff --git a/drivers/net/mlx5/linux/mlx5_os.c b/drivers/net/mlx5/linux/mlx5_os.c
index 696a3e12c7..03c5191095 100644
--- a/drivers/net/mlx5/linux/mlx5_os.c
+++ b/drivers/net/mlx5/linux/mlx5_os.c
@@ -1578,7 +1578,7 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
{
char ifname[MLX5_NAMESIZE];
- if (mlx5_get_ifname(eth_dev, &ifname) == 0)
+ if (mlx5_get_ifname(eth_dev, ifname) == 0)
DRV_LOG(DEBUG, "port %u ifname is \"%s\"",
eth_dev->data->port_id, ifname);
else
diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index c08894cd03..3e293216bb 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -2336,8 +2336,7 @@ uint64_t mlx5_get_restore_flags(struct rte_eth_dev *dev,
/* mlx5_ethdev_os.c */
-int mlx5_get_ifname(const struct rte_eth_dev *dev,
- char (*ifname)[MLX5_NAMESIZE]);
+int mlx5_get_ifname(const struct rte_eth_dev *dev, char ifname[MLX5_NAMESIZE]);
unsigned int mlx5_ifindex(const struct rte_eth_dev *dev);
int mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN]);
int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu);
diff --git a/drivers/net/mlx5/windows/mlx5_ethdev_os.c b/drivers/net/mlx5/windows/mlx5_ethdev_os.c
index 49f750be68..2e9c9d5b3f 100644
--- a/drivers/net/mlx5/windows/mlx5_ethdev_os.c
+++ b/drivers/net/mlx5/windows/mlx5_ethdev_os.c
@@ -56,7 +56,7 @@ mlx5_get_mac(struct rte_eth_dev *dev, uint8_t (*mac)[RTE_ETHER_ADDR_LEN])
* 0 on success, a negative errno value otherwise and rte_errno is set.
*/
int
-mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[MLX5_NAMESIZE])
+mlx5_get_ifname(const struct rte_eth_dev *dev, char ifname[MLX5_NAMESIZE])
{
struct mlx5_priv *priv;
mlx5_context_st *context_obj;
@@ -67,7 +67,7 @@ mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[MLX5_NAMESIZE])
}
priv = dev->data->dev_private;
context_obj = (mlx5_context_st *)priv->sh->cdev->ctx;
- strncpy(*ifname, context_obj->mlx5_dev.name, MLX5_NAMESIZE);
+ strncpy(ifname, context_obj->mlx5_dev.name, MLX5_NAMESIZE);
return 0;
}
--
2.48.1
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net/mlx5: fix interface name parameter definition
2025-08-10 13:22 [PATCH] net/mlx5: fix interface name parameter definition Gregory Etelson
@ 2025-08-11 4:44 ` Stephen Hemminger
2025-08-11 10:13 ` Etelson, Gregory
0 siblings, 1 reply; 3+ messages in thread
From: Stephen Hemminger @ 2025-08-11 4:44 UTC (permalink / raw)
To: Gregory Etelson
Cc: dev, ,
rasland, Dariusz Sosnowski, Viacheslav Ovsiienko, Bing Zhao,
Ori Kam, Suanming Mou, Matan Azrad, Ophir Munk
On Sun, 10 Aug 2025 16:22:59 +0300
Gregory Etelson <getelson@nvidia.com> wrote:
> The patch fixes `ifname` parameter as a character buffer.
>
> Fixes: 1256805dd54d ("net/mlx5: move Linux-specific functions")
>
> Signed-off-by: Gregory Etelson <getelson@nvidia.com>
> Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
> ---
This looks better but did you know that the ifname can never be as big as MLX5_NAMESIZE.
Kernel limits to IFNAMSIZ (ie 16). The largest allowable interface name in Linux is 15 characters.
Looks like:
MLX5_NAMESIZE := MXL5_FS_NAME_MAX := IBV_SYSFS_NAME_MAX + 1 = 64 + 1 = 65
Because Linux interface name length is fixed by BSD legacy ABI's it will never be longer.
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] net/mlx5: fix interface name parameter definition
2025-08-11 4:44 ` Stephen Hemminger
@ 2025-08-11 10:13 ` Etelson, Gregory
0 siblings, 0 replies; 3+ messages in thread
From: Etelson, Gregory @ 2025-08-11 10:13 UTC (permalink / raw)
To: Stephen Hemminger
Cc: Gregory Etelson, dev, ,
rasland, Dariusz Sosnowski, Viacheslav Ovsiienko, Bing Zhao,
Ori Kam, Suanming Mou, Matan Azrad, Ophir Munk
[-- Attachment #1: Type: text/plain, Size: 1422 bytes --]
Hello Stephen,
>> The patch fixes `ifname` parameter as a character buffer.
>>
>> Fixes: 1256805dd54d ("net/mlx5: move Linux-specific functions")
>>
>> Signed-off-by: Gregory Etelson <getelson@nvidia.com>
>> Acked-by: Dariusz Sosnowski <dsosnowski@nvidia.com>
>> ---
>
> This looks better but did you know that the ifname can never be as big as MLX5_NAMESIZE.
> Kernel limits to IFNAMSIZ (ie 16). The largest allowable interface name in Linux is 15 characters.
>
> Looks like:
> MLX5_NAMESIZE := MXL5_FS_NAME_MAX := IBV_SYSFS_NAME_MAX + 1 = 64 + 1 = 65
>
> Because Linux interface name length is fixed by BSD legacy ABI's it will never be longer.
>
The MLX5 PMD defines MLX5_NAMESIZE macro for Linux and Windows.
The Linux definition is in the drivers/net/mlx5/linux/mlx5_os.h:
#define MLX5_NAMESIZE IF_NAMESIZE
Linux API sets IF_NAMESIZE to 16.
The Windows definition is in the drivers/net/mlx5/windows/mlx5_os.h:
#define MLX5_NAMESIZE MLX5_FS_NAME_MAX.
The MLX5_FS_NAME_MAX macro also has different definitions for Linux and Windows:
drivers/common/mlx5/linux/mlx5_common_os.h
MLX5_FS_NAME_MAX = IBV_SYSFS_NAME_MAX + 1
IB verbs API sets IBV_SYSFS_NAME_MAX to 265.
drivers/common/mlx5/windows/mlx5_common_os.h:
MLX5_FS_NAME_MAX = MLX5_DEVX_DEVICE_NAME_SIZE + 1
MLX5_DEVX_DEVICE_NAME_SIZE is defined by NVIDIA/Mellanox’s DevX (WinOF2)
user-space headers for Windows and is set to 64.
Regards,
Gregory
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-08-11 10:13 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-10 13:22 [PATCH] net/mlx5: fix interface name parameter definition Gregory Etelson
2025-08-11 4:44 ` Stephen Hemminger
2025-08-11 10:13 ` Etelson, Gregory
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).