DPDK patches and discussions
 help / color / mirror / Atom feed
From: Xiaoyu Min <jackmin@mellanox.com>
To: Shahaf Shuler <shahafs@mellanox.com>, Yongseok Koh <yskoh@mellanox.com>
Cc: dev@dpdk.org, xuemingl@mellanox.com
Subject: [dpdk-dev] [PATCH] net/mlx5: handle expected errno properly
Date: Thu, 23 Aug 2018 14:38:51 +0800	[thread overview]
Message-ID: <20180823063851.32559-1-jackmin@mellanox.com> (raw)

rte_errno is a per thread variable and is widely used as an
error indicator, which means a function could affect
other functions' results by setting rte_errno carelessly

During rxq setup, an EINVAL rte_errno is expected since
the queues are not created yet
So rte_errno is cleared when it is EINVAL as expected

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
 drivers/net/mlx5/mlx5_rxq.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_rxq.c b/drivers/net/mlx5/mlx5_rxq.c
index 1f7bfd4..e7056e8 100644
--- a/drivers/net/mlx5/mlx5_rxq.c
+++ b/drivers/net/mlx5/mlx5_rxq.c
@@ -443,6 +443,7 @@
 	struct mlx5_rxq_data *rxq = (*priv->rxqs)[idx];
 	struct mlx5_rxq_ctrl *rxq_ctrl =
 		container_of(rxq, struct mlx5_rxq_ctrl, rxq);
+	int ret = 0;
 
 	if (!rte_is_power_of_2(desc)) {
 		desc = 1 << log2above(desc);
@@ -459,13 +460,21 @@
 		rte_errno = EOVERFLOW;
 		return -rte_errno;
 	}
-	if (!mlx5_rxq_releasable(dev, idx)) {
+	ret = mlx5_rxq_releasable(dev, idx);
+	if (!ret) {
 		DRV_LOG(ERR, "port %u unable to release queue index %u",
 			dev->data->port_id, idx);
 		rte_errno = EBUSY;
 		return -rte_errno;
+	} else if (ret == -EINVAL) {
+		/**
+		 * on the first time, rx queue doesn't exist,
+		 * so just ignore this error and reset rte_errno.
+		 */
+		rte_errno = 0;
+	} else {
+		mlx5_rxq_release(dev, idx);
 	}
-	mlx5_rxq_release(dev, idx);
 	rxq_ctrl = mlx5_rxq_new(dev, idx, desc, socket, conf, mp);
 	if (!rxq_ctrl) {
 		DRV_LOG(ERR, "port %u unable to allocate queue index %u",
@@ -1543,11 +1552,12 @@ struct mlx5_rxq_ctrl *
  * @param dev
  *   Pointer to Ethernet device.
  * @param idx
- *   TX queue index.
+ *   RX queue index.
  *
  * @return
- *   1 if the queue can be released, negative errno otherwise and rte_errno is
- *   set.
+ *   1 if the queue can be released
+ *   0 if the queue can not be released
+ *   -EINVAL if the queue doesn't exist
  */
 int
 mlx5_rxq_releasable(struct rte_eth_dev *dev, uint16_t idx)
-- 
1.8.3.1

             reply	other threads:[~2018-08-23  6:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-23  6:38 Xiaoyu Min [this message]
2018-08-23 21:08 ` Yongseok Koh
2018-08-24  6:45   ` Jack MIN
2018-08-28 20:42     ` Yongseok Koh
2018-08-29  3:52       ` Jack MIN
2018-08-31 21:48         ` Yongseok Koh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180823063851.32559-1-jackmin@mellanox.com \
    --to=jackmin@mellanox.com \
    --cc=dev@dpdk.org \
    --cc=shahafs@mellanox.com \
    --cc=xuemingl@mellanox.com \
    --cc=yskoh@mellanox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).