Skip to content

Commit f98c2dd

Browse files
ssudhakarpmartinkpetersen
authored andcommitted
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.com Reviewed-by: Mike Christie <[email protected]> Signed-off-by: Sudhakar Panneerselvam <[email protected]> Signed-off-by: Martin K. Petersen <[email protected]>
1 parent 06b43f9 commit f98c2dd

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

drivers/target/target_core_transport.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1410,11 +1410,8 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
14101410
}
14111411

14121412
sense_reason_t
1413-
target_setup_cmd_from_cdb(struct se_cmd *cmd, unsigned char *cdb)
1413+
target_cmd_init_cdb(struct se_cmd *cmd, unsigned char *cdb)
14141414
{
1415-
struct se_device *dev = cmd->se_dev;
1416-
sense_reason_t ret;
1417-
14181415
/*
14191416
* Ensure that the received CDB is less than the max (252 + 8) bytes
14201417
* for VARIABLE_LENGTH_CMD
@@ -1448,6 +1445,17 @@ target_setup_cmd_from_cdb(struct se_cmd *cmd, unsigned char *cdb)
14481445
memcpy(cmd->t_task_cdb, cdb, scsi_command_size(cdb));
14491446

14501447
trace_target_sequencer_start(cmd);
1448+
return 0;
1449+
}
1450+
EXPORT_SYMBOL(target_cmd_init_cdb);
1451+
1452+
sense_reason_t
1453+
target_setup_cmd_from_cdb(struct se_cmd *cmd, unsigned char *cdb)
1454+
{
1455+
struct se_device *dev = cmd->se_dev;
1456+
sense_reason_t ret;
1457+
1458+
target_cmd_init_cdb(cmd, cdb);
14511459

14521460
ret = dev->transport->parse_cdb(cmd);
14531461
if (ret == TCM_UNSUPPORTED_SCSI_OPCODE)

include/target/target_core_fabric.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ void transport_init_se_cmd(struct se_cmd *,
152152
const struct target_core_fabric_ops *,
153153
struct se_session *, u32, int, int, unsigned char *);
154154
sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u64);
155+
sense_reason_t target_cmd_init_cdb(struct se_cmd *, unsigned char *);
155156
sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *);
156157
int target_submit_cmd_map_sgls(struct se_cmd *, struct se_session *,
157158
unsigned char *, unsigned char *, u64, u32, int, int, int,

0 commit comments

Comments
 (0)