summaryrefslogtreecommitdiff
path: root/drivers/net/mlx5/mlx5_ethdev.c
diff options
context:
space:
mode:
authorAdrien Mazarguil <adrien.mazarguil@6wind.com>2018-07-25 13:24:33 +0200
committerThomas Monjalon <thomas@monjalon.net>2018-07-26 14:05:52 +0200
commit3f8cb05df5407369025fbc8b67f0f9595b781f73 (patch)
treedf034f95920adc55cdcc397723aa83695eebe5cf /drivers/net/mlx5/mlx5_ethdev.c
parent919d53ad78d20a47054641eaa1ba7491e644e5c9 (diff)
downloaddpdk-3f8cb05df5407369025fbc8b67f0f9595b781f73.zip
dpdk-3f8cb05df5407369025fbc8b67f0f9595b781f73.tar.gz
dpdk-3f8cb05df5407369025fbc8b67f0f9595b781f73.tar.xz
net/mlx5: fix invalid network interface index
Network interface indices being unsigned, an invalid index or error is normally expressed through a zero value (see if_nametoindex()). mlx5_ifindex() has a signed return type for negative values in case of error. Since mlx5_nl.c does not check for errors, these may be fed back as invalid interfaces indices to subsequent system calls. This usage would have been correct if mlx5_ifindex() returned a zero value instead. This patch makes mlx5_ifindex() unsigned for convenience. Fixes: ccdcba53a3f4 ("net/mlx5: use Netlink to add/remove MAC addresses") Cc: stable@dpdk.org Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com> Acked-by: Nelio Laranjeiro <nelio.laranjeiro@6wind.com> Acked-by: Yongseok Koh <yskoh@mellanox.com>
Diffstat (limited to 'drivers/net/mlx5/mlx5_ethdev.c')
-rw-r--r--drivers/net/mlx5/mlx5_ethdev.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 4a24f80..34c5b95 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -245,24 +245,20 @@ mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE])
* Pointer to Ethernet device.
*
* @return
- * Interface index on success, a negative errno value otherwise and
- * rte_errno is set.
+ * Nonzero interface index on success, zero otherwise and rte_errno is set.
*/
-int
+unsigned int
mlx5_ifindex(const struct rte_eth_dev *dev)
{
char ifname[IF_NAMESIZE];
- unsigned int ret;
+ unsigned int ifindex;
- ret = mlx5_get_ifname(dev, &ifname);
- if (ret)
- return ret;
- ret = if_nametoindex(ifname);
- if (ret == 0) {
+ if (mlx5_get_ifname(dev, &ifname))
+ return 0;
+ ifindex = if_nametoindex(ifname);
+ if (!ifindex)
rte_errno = errno;
- return -rte_errno;
- }
- return ret;
+ return ifindex;
}
/**