[dpdk-stable] patch 'net/mlx5: fix invalid network interface index' has been queued to stable release 18.05.1

Christian Ehrhardt christian.ehrhardt at canonical.com
Mon Jul 30 18:13:20 CEST 2018


Hi,

FYI, your patch has been queued to stable release 18.05.1

Note it hasn't been pushed to http://dpdk.org/browse/dpdk-stable yet.
It will be pushed if I get no objections before 08/01/18. So please
shout if anyone has objections.

Thanks.

Christian Ehrhardt <christian.ehrhardt at canonical.com>

---
>From 2049afe07c264d2e4e3754588a264dd17cadaf4f Mon Sep 17 00:00:00 2001
From: Adrien Mazarguil <adrien.mazarguil at 6wind.com>
Date: Wed, 25 Jul 2018 13:24:33 +0200
Subject: [PATCH] net/mlx5: fix invalid network interface index

[ upstream commit 3f8cb05df5407369025fbc8b67f0f9595b781f73 ]

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")

Signed-off-by: Adrien Mazarguil <adrien.mazarguil at 6wind.com>
Acked-by: Nelio Laranjeiro <nelio.laranjeiro at 6wind.com>
Acked-by: Yongseok Koh <yskoh at mellanox.com>
---
 drivers/net/mlx5/mlx5.h        |  1 +
 drivers/net/mlx5/mlx5_ethdev.c | 20 ++++++++------------
 drivers/net/mlx5/mlx5_nl.c     |  6 +++---
 3 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index 997b04a33..8f1335200 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -211,6 +211,7 @@ int mlx5_getenv_int(const char *);
 
 int mlx5_get_ifname(const struct rte_eth_dev *dev, char (*ifname)[IF_NAMESIZE]);
 int mlx5_ifindex(const struct rte_eth_dev *dev);
+unsigned int mlx5_ifindex(const struct rte_eth_dev *dev);
 int mlx5_ifreq(const struct rte_eth_dev *dev, int req, struct ifreq *ifr);
 int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu);
 int mlx5_set_flags(struct rte_eth_dev *dev, unsigned int keep,
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index ebe5cb6e3..f04385307 100644
--- a/drivers/net/mlx5/mlx5_ethdev.c
+++ b/drivers/net/mlx5/mlx5_ethdev.c
@@ -185,24 +185,20 @@ try_dev_id:
  *   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;
 }
 
 /**
diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c
index dca85835a..87110795d 100644
--- a/drivers/net/mlx5/mlx5_nl.c
+++ b/drivers/net/mlx5/mlx5_nl.c
@@ -311,7 +311,7 @@ mlx5_nl_mac_addr_list(struct rte_eth_dev *dev, struct ether_addr (*mac)[],
 		      int *mac_n)
 {
 	struct priv *priv = dev->data->dev_private;
-	int iface_idx = mlx5_ifindex(dev);
+	unsigned int iface_idx = mlx5_ifindex(dev);
 	struct {
 		struct nlmsghdr	hdr;
 		struct ifinfomsg ifm;
@@ -370,7 +370,7 @@ mlx5_nl_mac_addr_modify(struct rte_eth_dev *dev, struct ether_addr *mac,
 			int add)
 {
 	struct priv *priv = dev->data->dev_private;
-	int iface_idx = mlx5_ifindex(dev);
+	unsigned int iface_idx = mlx5_ifindex(dev);
 	struct {
 		struct nlmsghdr hdr;
 		struct ndmsg ndm;
@@ -549,7 +549,7 @@ static int
 mlx5_nl_device_flags(struct rte_eth_dev *dev, uint32_t flags, int enable)
 {
 	struct priv *priv = dev->data->dev_private;
-	int iface_idx = mlx5_ifindex(dev);
+	unsigned int iface_idx = mlx5_ifindex(dev);
 	struct {
 		struct nlmsghdr hdr;
 		struct ifinfomsg ifi;
-- 
2.17.1



More information about the stable mailing list