Commit f98c2ddf authored by Sudhakar Panneerselvam's avatar Sudhakar Panneerselvam Committed by Martin K. Petersen

scsi: target: Factor out a new helper, target_cmd_init_cdb()

target_setup_cmd_from_cdb() is called after a successful call to
transport_lookup_cmd_lun(). The new helper factors out the code that can be
called before the call to transport_lookup_cmd_lun(). This helper will be
used in an upcoming commit to address NULL pointer dereference.

Link: https://lore.kernel.org/r/1591559913-8388-2-git-send-email-sudhakar.panneerselvam@oracle.comReviewed-by: default avatarMike Christie <michael.christie@oracle.com>
Signed-off-by: default avatarSudhakar Panneerselvam <sudhakar.panneerselvam@oracle.com>
Signed-off-by: default avatarMartin K. Petersen <martin.petersen@oracle.com>
parent 06b43f96
...@@ -1410,11 +1410,8 @@ transport_check_alloc_task_attr(struct se_cmd *cmd) ...@@ -1410,11 +1410,8 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
} }
sense_reason_t sense_reason_t
target_setup_cmd_from_cdb(struct se_cmd *cmd, unsigned char *cdb) target_cmd_init_cdb(struct se_cmd *cmd, unsigned char *cdb)
{ {
struct se_device *dev = cmd->se_dev;
sense_reason_t ret;
/* /*
* Ensure that the received CDB is less than the max (252 + 8) bytes * Ensure that the received CDB is less than the max (252 + 8) bytes
* for VARIABLE_LENGTH_CMD * for VARIABLE_LENGTH_CMD
...@@ -1448,6 +1445,17 @@ target_setup_cmd_from_cdb(struct se_cmd *cmd, unsigned char *cdb) ...@@ -1448,6 +1445,17 @@ target_setup_cmd_from_cdb(struct se_cmd *cmd, unsigned char *cdb)
memcpy(cmd->t_task_cdb, cdb, scsi_command_size(cdb)); memcpy(cmd->t_task_cdb, cdb, scsi_command_size(cdb));
trace_target_sequencer_start(cmd); trace_target_sequencer_start(cmd);
return 0;
}
EXPORT_SYMBOL(target_cmd_init_cdb);
sense_reason_t
target_setup_cmd_from_cdb(struct se_cmd *cmd, unsigned char *cdb)
{
struct se_device *dev = cmd->se_dev;
sense_reason_t ret;
target_cmd_init_cdb(cmd, cdb);
ret = dev->transport->parse_cdb(cmd); ret = dev->transport->parse_cdb(cmd);
if (ret == TCM_UNSUPPORTED_SCSI_OPCODE) if (ret == TCM_UNSUPPORTED_SCSI_OPCODE)
......
...@@ -152,6 +152,7 @@ void transport_init_se_cmd(struct se_cmd *, ...@@ -152,6 +152,7 @@ void transport_init_se_cmd(struct se_cmd *,
const struct target_core_fabric_ops *, const struct target_core_fabric_ops *,
struct se_session *, u32, int, int, unsigned char *); struct se_session *, u32, int, int, unsigned char *);
sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u64); sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u64);
sense_reason_t target_cmd_init_cdb(struct se_cmd *, unsigned char *);
sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *); sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *);
int target_submit_cmd_map_sgls(struct se_cmd *, struct se_session *, int target_submit_cmd_map_sgls(struct se_cmd *, struct se_session *,
unsigned char *, unsigned char *, u64, u32, int, int, int, unsigned char *, unsigned char *, u64, u32, int, int, int,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment