diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c index dfb6603eab4d..5c822fdc8f6f 100644 --- a/drivers/target/target_core_sbc.c +++ b/drivers/target/target_core_sbc.c @@ -375,7 +375,8 @@ static sense_reason_t compare_and_write_callback(struct se_cmd *cmd) buf = kzalloc(cmd->data_length, GFP_KERNEL); if (!buf) { pr_err("Unable to allocate compare_and_write buf\n"); - return TCM_OUT_OF_RESOURCES; + ret = TCM_OUT_OF_RESOURCES; + goto out; } write_sg = kzalloc(sizeof(struct scatterlist) * cmd->t_data_nents, diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index 672cb37a43c5..e53c59ba745a 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1909,17 +1909,18 @@ static void target_complete_ok_work(struct work_struct *work) sense_reason_t rc; rc = cmd->transport_complete_callback(cmd); - if (!rc) + if (!rc && !(cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE_POST)) { return; + } else if (rc) { + ret = transport_send_check_condition_and_sense(cmd, + rc, 0); + if (ret == -EAGAIN || ret == -ENOMEM) + goto queue_full; - ret = transport_send_check_condition_and_sense(cmd, - rc, 0); - if (ret == -EAGAIN || ret == -ENOMEM) - goto queue_full; - - transport_lun_remove_cmd(cmd); - transport_cmd_check_stop_to_fabric(cmd); - return; + transport_lun_remove_cmd(cmd); + transport_cmd_check_stop_to_fabric(cmd); + return; + } } switch (cmd->data_direction) {