DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH] net/mlx5: fix invalid network interface index value
@ 2018-07-25 11:24 Adrien Mazarguil
  2018-07-25 17:04 ` Yongseok Koh
  0 siblings, 1 reply; 3+ messages in thread
From: Adrien Mazarguil @ 2018-07-25 11:24 UTC (permalink / raw)
  To: Shahaf Shuler; +Cc: dev, Nelio Laranjeiro, stable

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: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
Cc: stable@dpdk.org

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

diff --git a/drivers/net/mlx5/mlx5.h b/drivers/net/mlx5/mlx5.h
index db8a5fa01..25345baea 100644
--- a/drivers/net/mlx5/mlx5.h
+++ b/drivers/net/mlx5/mlx5.h
@@ -243,7 +243,7 @@ int mlx5_getenv_int(const char *);
 int mlx5_get_master_ifname(const struct rte_eth_dev *dev,
 			   char (*ifname)[IF_NAMESIZE]);
 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 master);
 int mlx5_get_mtu(struct rte_eth_dev *dev, uint16_t *mtu);
diff --git a/drivers/net/mlx5/mlx5_ethdev.c b/drivers/net/mlx5/mlx5_ethdev.c
index 9cf2dc5f1..a1c1b50a6 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;
 }
 
 /**
diff --git a/drivers/net/mlx5/mlx5_nl.c b/drivers/net/mlx5/mlx5_nl.c
index 008cd2c31..cc562dfc9 100644
--- a/drivers/net/mlx5/mlx5_nl.c
+++ b/drivers/net/mlx5/mlx5_nl.c
@@ -365,7 +365,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;
@@ -424,7 +424,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;
@@ -603,7 +603,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.11.0

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] net/mlx5: fix invalid network interface index value
  2018-07-25 11:24 [dpdk-dev] [PATCH] net/mlx5: fix invalid network interface index value Adrien Mazarguil
@ 2018-07-25 17:04 ` Yongseok Koh
  2018-07-26  5:38   ` Shahaf Shuler
  0 siblings, 1 reply; 3+ messages in thread
From: Yongseok Koh @ 2018-07-25 17:04 UTC (permalink / raw)
  To: Adrien Mazarguil; +Cc: Shahaf Shuler, dev, Nélio Laranjeiro, stable


> On Jul 25, 2018, at 4:24 AM, Adrien Mazarguil <adrien.mazarguil@6wind.com> wrote:
> 
> 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: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
> 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>
 
Thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [dpdk-dev] [PATCH] net/mlx5: fix invalid network interface index value
  2018-07-25 17:04 ` Yongseok Koh
@ 2018-07-26  5:38   ` Shahaf Shuler
  0 siblings, 0 replies; 3+ messages in thread
From: Shahaf Shuler @ 2018-07-26  5:38 UTC (permalink / raw)
  To: Yongseok Koh, Adrien Mazarguil; +Cc: dev, Nélio Laranjeiro, stable

Wednesday, July 25, 2018 8:05 PM, Yongseok Koh:
> Subject: Re: [dpdk-dev] [PATCH] net/mlx5: fix invalid network interface
> index value
> 
> 
> > On Jul 25, 2018, at 4:24 AM, Adrien Mazarguil
> <adrien.mazarguil@6wind.com> wrote:
> >
> > 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: Nelio Laranjeiro <nelio.laranjeiro@6wind.com>
> > 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>

Applied to next-net-mlx, thanks. 

> 
> Thanks

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-07-26  5:38 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-25 11:24 [dpdk-dev] [PATCH] net/mlx5: fix invalid network interface index value Adrien Mazarguil
2018-07-25 17:04 ` Yongseok Koh
2018-07-26  5:38   ` Shahaf Shuler

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