Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <michael.christie@oracle.com>
Signed-off-by: Sudhakar Panneerselvam <sudhakar.panneerselvam@oracle.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>

authored by

Sudhakar Panneerselvam and committed by
Martin K. Petersen
f98c2ddf 06b43f96

+13 -4
+12 -4
drivers/target/target_core_transport.c
··· 1410 1410 } 1411 1411 1412 1412 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) 1414 1414 { 1415 - struct se_device *dev = cmd->se_dev; 1416 - sense_reason_t ret; 1417 - 1418 1415 /* 1419 1416 * Ensure that the received CDB is less than the max (252 + 8) bytes 1420 1417 * for VARIABLE_LENGTH_CMD ··· 1445 1448 memcpy(cmd->t_task_cdb, cdb, scsi_command_size(cdb)); 1446 1449 1447 1450 trace_target_sequencer_start(cmd); 1451 + return 0; 1452 + } 1453 + EXPORT_SYMBOL(target_cmd_init_cdb); 1454 + 1455 + sense_reason_t 1456 + target_setup_cmd_from_cdb(struct se_cmd *cmd, unsigned char *cdb) 1457 + { 1458 + struct se_device *dev = cmd->se_dev; 1459 + sense_reason_t ret; 1460 + 1461 + target_cmd_init_cdb(cmd, cdb); 1448 1462 1449 1463 ret = dev->transport->parse_cdb(cmd); 1450 1464 if (ret == TCM_UNSUPPORTED_SCSI_OPCODE)
+1
include/target/target_core_fabric.h
··· 152 152 const struct target_core_fabric_ops *, 153 153 struct se_session *, u32, int, int, unsigned char *); 154 154 sense_reason_t transport_lookup_cmd_lun(struct se_cmd *, u64); 155 + sense_reason_t target_cmd_init_cdb(struct se_cmd *, unsigned char *); 155 156 sense_reason_t target_setup_cmd_from_cdb(struct se_cmd *, unsigned char *); 156 157 int target_submit_cmd_map_sgls(struct se_cmd *, struct se_session *, 157 158 unsigned char *, unsigned char *, u64, u32, int, int, int,