git: 027d0c1c043a - main - mana: fix misc minor handlding issues when error happens.

From: Wei Hu <whu_at_FreeBSD.org>
Date: Thu, 13 Jan 2022 07:26:27 UTC
The branch main has been updated by whu:

URL: https://cgit.FreeBSD.org/src/commit/?id=027d0c1c043ab274f00e51b826c0d4ebea219623

commit 027d0c1c043ab274f00e51b826c0d4ebea219623
Author:     Wei Hu <whu@FreeBSD.org>
AuthorDate: 2022-01-13 06:17:31 +0000
Commit:     Wei Hu <whu@FreeBSD.org>
CommitDate: 2022-01-13 07:22:21 +0000

    mana: fix misc minor handlding issues when error happens.
    
    - In mana_create_txq(), if test fails we must free some resources
      as in all the other handling paths of this function.
    - In mana_gd_read_cqe(), add warning log in case of CQE read
      overflow, instead of failing silently.
    - Fix error handling in mana_create_rxq() when
      cq->gdma_id >= gc->max_num_cqs.
    - In mana_init_port(), use the correct port index rather than 0.
    - In mana_hwc_create_wq(), If allocating the DMA buffer fails,
      mana_hwc_destroy_wq was called without previously storing the
      pointer to the queue. In order to avoid leaking the pointer to
      the queue, store it as soon as it is allocated.
    
    MFC after:      2 weeks
    Sponsored by:   Microsoft
---
 sys/dev/mana/gdma_main.c  |  6 +++++-
 sys/dev/mana/hw_channel.c | 10 +++++-----
 sys/dev/mana/mana_en.c    | 10 +++++++---
 3 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/sys/dev/mana/gdma_main.c b/sys/dev/mana/gdma_main.c
index b879695825b1..aa5d5fd5b507 100644
--- a/sys/dev/mana/gdma_main.c
+++ b/sys/dev/mana/gdma_main.c
@@ -1359,8 +1359,12 @@ mana_gd_read_cqe(struct gdma_queue *cq, struct gdma_comp *comp)
 
 	new_bits = (cq->head / num_cqe) & GDMA_CQE_OWNER_MASK;
 	/* Return -1 if overflow detected. */
-	if (owner_bits != new_bits)
+	if (owner_bits != new_bits) {
+		mana_warn(NULL,
+		    "overflow detected! owner_bits %u != new_bits %u\n",
+		    owner_bits, new_bits);
 		return -1;
+	}
 
 	comp->wq_num = cqe->cqe_info.wq_num;
 	comp->is_sq = cqe->cqe_info.is_sq;
diff --git a/sys/dev/mana/hw_channel.c b/sys/dev/mana/hw_channel.c
index 16b644d6c6b7..dbb5b54d9ad1 100644
--- a/sys/dev/mana/hw_channel.c
+++ b/sys/dev/mana/hw_channel.c
@@ -569,16 +569,16 @@ mana_hwc_create_wq(struct hw_channel_context *hwc,
 	if (err)
 		goto out;
 
-	err = mana_hwc_alloc_dma_buf(hwc, q_depth, max_msg_size,
-	    &hwc_wq->msg_buf);
-	if (err)
-		goto out;
-
 	hwc_wq->hwc = hwc;
 	hwc_wq->gdma_wq = queue;
 	hwc_wq->queue_depth = q_depth;
 	hwc_wq->hwc_cq = hwc_cq;
 
+	err = mana_hwc_alloc_dma_buf(hwc, q_depth, max_msg_size,
+	    &hwc_wq->msg_buf);
+	if (err)
+		goto out;
+
 	*hwc_wq_ptr = hwc_wq;
 	return 0;
 out:
diff --git a/sys/dev/mana/mana_en.c b/sys/dev/mana/mana_en.c
index e57a2622d09f..bba6e8a4aeb5 100644
--- a/sys/dev/mana/mana_en.c
+++ b/sys/dev/mana/mana_en.c
@@ -1935,7 +1935,8 @@ mana_create_txq(struct mana_port_context *apc, struct ifnet *net)
 
 		if (cq->gdma_id >= gc->max_num_cqs) {
 			if_printf(net, "CQ id %u too large.\n", cq->gdma_id);
-			return EINVAL;
+			err = EINVAL;
+			goto out;
 		}
 
 		gc->cq_table[cq->gdma_id] = cq->gdma_cq;
@@ -2249,8 +2250,10 @@ mana_create_rxq(struct mana_port_context *apc, uint32_t rxq_idx,
 	if (err)
 		goto out;
 
-	if (cq->gdma_id >= gc->max_num_cqs)
+	if (cq->gdma_id >= gc->max_num_cqs) {
+		err = EINVAL;
 		goto out;
+	}
 
 	gc->cq_table[cq->gdma_id] = cq->gdma_cq;
 
@@ -2393,7 +2396,8 @@ mana_init_port(struct ifnet *ndev)
 	err = mana_query_vport_cfg(apc, port_idx, &max_txq, &max_rxq,
 	    &num_indirect_entries);
 	if (err) {
-		if_printf(ndev, "Failed to query info for vPort 0\n");
+		if_printf(ndev, "Failed to query info for vPort %d\n",
+		    port_idx);
 		goto reset_apc;
 	}