From dc94ba7d76c714a5f434313f372c918e744f62b3 Mon Sep 17 00:00:00 2001 From: Bart Van Assche Date: Wed, 2 May 2012 15:18:24 +0000 Subject: [PATCH] ib_srpt: Simplify login error handling code git-svn-id: http://svn.code.sf.net/p/scst/svn/trunk@4269 d57e44dd-8a1f-0410-8b47-8ef2f437770f --- srpt/src/ib_srpt.c | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/srpt/src/ib_srpt.c b/srpt/src/ib_srpt.c index 3595140f8..9b78a1f9f 100644 --- a/srpt/src/ib_srpt.c +++ b/srpt/src/ib_srpt.c @@ -2342,7 +2342,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id, struct srp_login_rsp *rsp; struct srp_login_rej *rej; struct ib_cm_rep_param *rep_param; - struct srpt_rdma_ch *ch; + struct srpt_rdma_ch *ch = NULL; struct task_struct *thread; u32 it_iu_len; int i; @@ -2535,7 +2535,7 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id, rej->reason = cpu_to_be32(SRP_LOGIN_REJ_INSUFFICIENT_RESOURCES); PRINT_ERROR("rejected SRP_LOGIN_REQ because enabling" " RTR failed (error code = %d)", ret); - goto reject_and_close; + goto reject; } TRACE_DBG("Establish connection sess=%p name=%s cm_id=%p", @@ -2575,34 +2575,16 @@ static int srpt_cm_req_recv(struct ib_cm_id *cm_id, case 0: break; case -ECONNABORTED: - goto out_keep_cm_id; + goto reject; default: rej->reason = cpu_to_be32(SRP_LOGIN_REJ_INSUFFICIENT_RESOURCES); PRINT_ERROR("sending SRP_LOGIN_REQ response failed" " (error code = %d)", ret); - goto reject_and_close; + goto reject; } goto out; -reject_and_close: - PRINT_INFO("Rejecting login with reason %#x", be32_to_cpu(rej->reason)); - rej->opcode = SRP_LOGIN_REJ; - rej->tag = req->tag; - rej->buf_fmt = cpu_to_be16(SRP_BUF_FORMAT_DIRECT | - SRP_BUF_FORMAT_INDIRECT); - ib_send_cm_rej(cm_id, IB_CM_REJ_CONSUMER_DEFINED, NULL, 0, - (void *)rej, sizeof *rej); - - srpt_close_ch(ch); -out_keep_cm_id: - /* - * Tell the caller not to free cm_id since srpt_compl_thread() will do - * that. - */ - ret = 0; - goto out; - unreg_ch: scst_unregister_session(ch->scst_sess, true, NULL); @@ -2618,16 +2600,25 @@ free_ch: cm_id->context = NULL; kfree(ch); + BUG_ON(ret == 0); + reject: PRINT_INFO("Rejecting login with reason %#x", be32_to_cpu(rej->reason)); rej->opcode = SRP_LOGIN_REJ; rej->tag = req->tag; rej->buf_fmt = cpu_to_be16(SRP_BUF_FORMAT_DIRECT | SRP_BUF_FORMAT_INDIRECT); - ib_send_cm_rej(cm_id, IB_CM_REJ_CONSUMER_DEFINED, NULL, 0, - (void *)rej, sizeof *rej); + ib_send_cm_rej(cm_id, IB_CM_REJ_CONSUMER_DEFINED, NULL, 0, rej, + sizeof(*rej)); - BUG_ON(ret == 0); + if (ch && ch->thread) { + srpt_close_ch(ch); + /* + * Tell the caller not to free cm_id since + * srpt_compl_thread() will do that. + */ + ret = 0; + } out: kfree(rep_param);