net/mlx5: fix interface name parameter definition
PATCH 1/1 net/mlx5: fix interface name parameter definition
The patch fixes ifname parameter as a character buffer.
--- 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(-)
drivers/net/mlx5/linux/mlx5_ethdev_os.c +5 -6
@@ -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);
drivers/net/mlx5/linux/mlx5_os.c +1 -1
@@ -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
drivers/net/mlx5/mlx5.h +1 -2
@@ -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);
drivers/net/mlx5/windows/mlx5_ethdev_os.c +2 -2
@@ -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 ; }
Signature · 1 line
2.48.1
Quoted 7 lines · On Sun, 10 Aug 2025 16:22:59 +0300 Gregory Etelson <[email protected]> wrote:
The patch fixes
ifnameparameter as a character buffer.Fixes 1256805dd54d ("net/mlx5: move Linux-specific functions")Signed-off-by Gregory Etelson <[email protected]>---
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.
Hello Stephen,
Quoted 8 lines
Quoted 7 lines
The patch fixes
ifnameparameter as a character buffer.Fixes 1256805dd54d ("net/mlx5: move Linux-specific functions")Signed-off-by Gregory Etelson <[email protected]>---
Quoted 8 lines
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 = 65Because 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.hMLX5_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
Hi,
Quoted 6 lines · Gregory Etelson
The patch fixes
ifnameparameter as a character buffer.Fixes 1256805dd54d ("net/mlx5: move Linux-specific functions")Signed-off-by Gregory Etelson <[email protected]>
Patch applied to next-net-mlx,
Kindest regards
Raslan Darawsheh