Linux RDMA and InfiniBand development
 help / color / mirror / Atom feed
From: Guoqing Jiang <guoqing.jiang@linux.dev>
To: bmt@zurich.ibm.com, jgg@ziepe.ca, leon@kernel.org
Cc: linux-rdma@vger.kernel.org
Subject: [PATCH V5 12/17] RDMA/siw: Cleanup siw_accept
Date: Mon, 13 Nov 2023 19:57:21 +0800	[thread overview]
Message-ID: <20231113115726.12762-13-guoqing.jiang@linux.dev> (raw)
In-Reply-To: <20231113115726.12762-1-guoqing.jiang@linux.dev>

With the initialization of rv and the two added label, we can
simplifiy code a bit.

Acked-by: Bernard Metzler <bmt@zurich.ibm.com>
Signed-off-by: Guoqing Jiang <guoqing.jiang@linux.dev>
---
 drivers/infiniband/sw/siw/siw_cm.c | 41 ++++++++++--------------------
 1 file changed, 14 insertions(+), 27 deletions(-)

diff --git a/drivers/infiniband/sw/siw/siw_cm.c b/drivers/infiniband/sw/siw/siw_cm.c
index 36fd459b136c..5e9a591eec58 100644
--- a/drivers/infiniband/sw/siw/siw_cm.c
+++ b/drivers/infiniband/sw/siw/siw_cm.c
@@ -1558,7 +1558,7 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)
 	struct siw_cep *cep = (struct siw_cep *)id->provider_data;
 	struct siw_qp *qp;
 	struct siw_qp_attrs qp_attrs;
-	int rv, max_priv_data = MPA_MAX_PRIVDATA;
+	int rv = -EINVAL, max_priv_data = MPA_MAX_PRIVDATA;
 	bool wait_for_peer_rts = false;
 
 	siw_cep_set_inuse(cep);
@@ -1574,24 +1574,17 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)
 
 	if (cep->state != SIW_EPSTATE_RECVD_MPAREQ) {
 		siw_dbg_cep(cep, "out of state\n");
-
-		siw_cep_set_free_and_put(cep);
-
-		return -ECONNRESET;
+		rv = -ECONNRESET;
+		goto free_cep;
 	}
 	qp = siw_qp_id2obj(sdev, params->qpn);
 	if (!qp) {
 		WARN(1, "[QP %d] does not exist\n", params->qpn);
-		siw_cep_set_free_and_put(cep);
-
-		return -EINVAL;
+		goto free_cep;
 	}
 	down_write(&qp->state_lock);
-	if (qp->attrs.state > SIW_QP_STATE_RTR) {
-		rv = -EINVAL;
-		up_write(&qp->state_lock);
-		goto error;
-	}
+	if (qp->attrs.state > SIW_QP_STATE_RTR)
+		goto error_unlock;
 	siw_dbg_cep(cep, "[QP %d]\n", params->qpn);
 
 	if (try_gso && cep->mpa.hdr.params.bits & MPA_RR_FLAG_GSO_EXP) {
@@ -1605,9 +1598,7 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)
 			"[QP %u]: ord %d (max %d), ird %d (max %d)\n",
 			qp_id(qp), params->ord, sdev->attrs.max_ord,
 			params->ird, sdev->attrs.max_ird);
-		rv = -EINVAL;
-		up_write(&qp->state_lock);
-		goto error;
+		goto error_unlock;
 	}
 	if (cep->enhanced_rdma_conn_est)
 		max_priv_data -= sizeof(struct mpa_v2_data);
@@ -1617,9 +1608,7 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)
 			cep,
 			"[QP %u]: private data length: %d (max %d)\n",
 			qp_id(qp), params->private_data_len, max_priv_data);
-		rv = -EINVAL;
-		up_write(&qp->state_lock);
-		goto error;
+		goto error_unlock;
 	}
 	if (cep->enhanced_rdma_conn_est) {
 		if (params->ord > cep->ord) {
@@ -1628,9 +1617,7 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)
 			} else {
 				cep->ird = params->ird;
 				cep->ord = params->ord;
-				rv = -EINVAL;
-				up_write(&qp->state_lock);
-				goto error;
+				goto error_unlock;
 			}
 		}
 		if (params->ird < cep->ird) {
@@ -1639,8 +1626,7 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)
 				params->ird = cep->ird;
 			else {
 				rv = -ENOMEM;
-				up_write(&qp->state_lock);
-				goto error;
+				goto error_unlock;
 			}
 		}
 		if (cep->mpa.v2_ctrl.ord &
@@ -1687,7 +1673,6 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)
 				   SIW_QP_ATTR_ORD | SIW_QP_ATTR_IRD |
 				   SIW_QP_ATTR_MPA);
 	up_write(&qp->state_lock);
-
 	if (rv)
 		goto error;
 
@@ -1710,6 +1695,9 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)
 	siw_cep_set_free(cep);
 
 	return 0;
+
+error_unlock:
+	up_write(&qp->state_lock);
 error:
 	siw_socket_disassoc(cep->sock);
 	sock_release(cep->sock);
@@ -1724,9 +1712,8 @@ int siw_accept(struct iw_cm_id *id, struct iw_cm_conn_param *params)
 	}
 	cep->qp = NULL;
 	siw_qp_put(qp);
-
+free_cep:
 	siw_cep_set_free_and_put(cep);
-
 	return rv;
 }
 
-- 
2.35.3


  parent reply	other threads:[~2023-11-13 11:57 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-13 11:57 [PATCH V5 00/17] Cleanup for siw Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 01/17] RDMA/siw: Introduce siw_get_page Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 02/17] RDMA/siw: Introduce siw_update_skb_rcvd Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 03/17] RDMA/siw: Use iov.iov_len in kernel_sendmsg Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 04/17] RDMA/siw: Remove goto lable in siw_mmap Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 05/17] RDMA/siw: Remove rcu from siw_qp Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 06/17] RDMA/siw: No need to check term_info.valid before call siw_send_terminate Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 07/17] RDMA/siw: Factor out siw_rx_data helper Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 08/17] RDMA/siw: Introduce SIW_STAG_MAX_INDEX Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 09/17] RDMA/siw: Add one parameter to siw_destroy_cpulist Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 10/17] RDMA/siw: Introduce siw_cep_set_free_and_put Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 11/17] RDMA/siw: Introduce siw_free_cm_id Guoqing Jiang
2023-11-13 11:57 ` Guoqing Jiang [this message]
2023-11-13 11:57 ` [PATCH V5 13/17] RDMA/siw: Remove siw_sk_save_upcalls Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 14/17] RDMA/siw: Fix typo Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 15/17] RDMA/siw: Only check attrs->cap.max_send_wr in siw_create_qp Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 16/17] RDMA/siw: Introduce siw_destroy_cep_sock Guoqing Jiang
2023-11-13 11:57 ` [PATCH V5 17/17] RDMA/siw: Update comments for siw_qp_sq_process Guoqing Jiang
2023-11-15 13:58 ` [PATCH V5 00/17] Cleanup for siw Leon Romanovsky

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=20231113115726.12762-13-guoqing.jiang@linux.dev \
    --to=guoqing.jiang@linux.dev \
    --cc=bmt@zurich.ibm.com \
    --cc=jgg@ziepe.ca \
    --cc=leon@kernel.org \
    --cc=linux-rdma@vger.kernel.org \
    /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