From: Nicholas Bellinger <n...@linux-iscsi.org>

Cc: Chris Boot <bo...@bootc.net>
Cc: Christoph Hellwig <h...@lst.de>
Cc: Hannes Reinecke <h...@suse.de>
Signed-off-by: Nicholas Bellinger <n...@linux-iscsi.org>
---
 drivers/target/sbp/sbp_target.c | 30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
index 756e87f..251d532 100644
--- a/drivers/target/sbp/sbp_target.c
+++ b/drivers/target/sbp/sbp_target.c
@@ -893,7 +893,6 @@ static void tgt_agent_process_work(struct work_struct *work)
                                        STATUS_BLOCK_SBP_STATUS(
                                                SBP_STATUS_REQ_TYPE_NOTSUPP));
                        sbp_send_status(req);
-                       sbp_free_request(req);
                        return;
                case 3: /* Dummy ORB */
                        req->status.status |= cpu_to_be32(
@@ -904,7 +903,6 @@ static void tgt_agent_process_work(struct work_struct *work)
                                        STATUS_BLOCK_SBP_STATUS(
                                                SBP_STATUS_DUMMY_ORB_COMPLETE));
                        sbp_send_status(req);
-                       sbp_free_request(req);
                        return;
                default:
                        BUG();
@@ -988,7 +986,6 @@ static void tgt_agent_fetch_work(struct work_struct *work)
                        spin_unlock_bh(&agent->lock);
 
                        sbp_send_status(req);
-                       sbp_free_request(req);
                        return;
                }
 
@@ -1235,7 +1232,7 @@ static void sbp_handle_command(struct sbp_target_request 
*req)
        req->se_cmd.tag = req->orb_pointer;
        if (target_submit_cmd(&req->se_cmd, sess->se_sess, req->cmd_buf,
                              req->sense_buf, unpacked_lun, data_length,
-                             TCM_SIMPLE_TAG, data_dir, 0))
+                             TCM_SIMPLE_TAG, data_dir, TARGET_SCF_ACK_KREF))
                goto err;
 
        return;
@@ -1247,7 +1244,6 @@ err:
                STATUS_BLOCK_LEN(1) |
                STATUS_BLOCK_SBP_STATUS(SBP_STATUS_UNSPECIFIED_ERROR));
        sbp_send_status(req);
-       sbp_free_request(req);
 }
 
 /*
@@ -1346,22 +1342,29 @@ static int sbp_rw_data(struct sbp_target_request *req)
 
 static int sbp_send_status(struct sbp_target_request *req)
 {
-       int ret, length;
+       int rc, ret = 0, length;
        struct sbp_login_descriptor *login = req->login;
 
        length = (((be32_to_cpu(req->status.status) >> 24) & 0x07) + 1) * 4;
 
-       ret = sbp_run_request_transaction(req, TCODE_WRITE_BLOCK_REQUEST,
+       rc = sbp_run_request_transaction(req, TCODE_WRITE_BLOCK_REQUEST,
                        login->status_fifo_addr, &req->status, length);
-       if (ret != RCODE_COMPLETE) {
-               pr_debug("sbp_send_status: write failed: 0x%x\n", ret);
-               return -EIO;
+       if (rc != RCODE_COMPLETE) {
+               pr_debug("sbp_send_status: write failed: 0x%x\n", rc);
+               ret = -EIO;
+               goto put_ref;
        }
 
        pr_debug("sbp_send_status: status write complete for ORB: 0x%llx\n",
                        req->orb_pointer);
-
-       return 0;
+       /*
+        * Drop the extra ACK_KREF reference taken by target_submit_cmd()
+        * ahead of sbp_check_stop_free() -> transport_generic_free_cmd()
+        * final se_cmd->cmd_kref put.
+        */
+put_ref:
+       target_put_sess_cmd(&req->se_cmd);
+       return ret;
 }
 
 static void sbp_sense_mangle(struct sbp_target_request *req)
@@ -1826,8 +1829,7 @@ static int sbp_check_stop_free(struct se_cmd *se_cmd)
        struct sbp_target_request *req = container_of(se_cmd,
                        struct sbp_target_request, se_cmd);
 
-       transport_generic_free_cmd(&req->se_cmd, 0);
-       return 1;
+       return transport_generic_free_cmd(&req->se_cmd, 0);
 }
 
 static int sbp_count_se_tpg_luns(struct se_portal_group *tpg)
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-scsi" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to