[<prev] [next>] [day] [month] [year] [list]
Message-Id: <71ea0c365383e038b7eb6a638faf45a7345fcb33.1658195984.git.Thinh.Nguyen@synopsys.com>
Date: Mon, 18 Jul 2022 19:07:19 -0700
From: Thinh Nguyen <Thinh.Nguyen@...opsys.com>
To: linux-kernel@...r.kernel.org, linux-scsi@...r.kernel.org,
target-devel@...r.kernel.org,
"Martin K. Petersen" <martin.petersen@...cle.com>
Cc: John Youn <John.Youn@...opsys.com>,
Felipe Balbi <balbi@...nel.org>,
Greg KH <gregkh@...uxfoundation.org>,
Thinh Nguyen <Thinh.Nguyen@...opsys.com>,
linux-usb@...r.kernel.org
Subject: [PATCH v2 4/4] target: Properly set Sense data length when copy sense
The transport_get_sense_buffer() sets sense data length to be the
allocated sense buffer length TRANSPORT_SENSE_BUFFER. However, the sense
data length is depending on the sense data description. Check the sense
data for cmd->scsi_sense_length.
See SPC4-R37 section 4.5.2.1.
Signed-off-by: Thinh Nguyen <Thinh.Nguyen@...opsys.com>
---
Changes in v2:
- Only memcpy sense data length rather than the entire TRANSPORT_SENSE_BUFFER.
drivers/target/target_core_transport.c | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
index db53b326048d..95b7788e7cbc 100644
--- a/drivers/target/target_core_transport.c
+++ b/drivers/target/target_core_transport.c
@@ -771,8 +771,6 @@ static unsigned char *transport_get_sense_buffer(struct se_cmd *cmd)
if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION)
return NULL;
- cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER;
-
pr_debug("HBA_[%u]_PLUG[%s]: Requesting sense for SAM STATUS: 0x%02x\n",
dev->se_hba->hba_id, dev->transport->name, cmd->scsi_status);
return cmd->sense_buffer;
@@ -791,6 +789,11 @@ void transport_copy_sense_to_cmd(struct se_cmd *cmd, unsigned char *sense)
}
cmd->se_cmd_flags |= SCF_TRANSPORT_TASK_SENSE;
+
+ /* Sense data length = min sense data + additional sense data length */
+ cmd->scsi_sense_length = min_t(u16, cmd_sense_buf[7] + 8,
+ TRANSPORT_SENSE_BUFFER);
+
memcpy(cmd_sense_buf, sense, cmd->scsi_sense_length);
spin_unlock_irqrestore(&cmd->t_state_lock, flags);
}
--
2.28.0
Powered by blists - more mailing lists