diff --git a/drivers/target/target_core_sbc.c b/drivers/target/target_core_sbc.c index 5c822fdc8f6f5eb346e3873ed0fc6df5f983666e..2cd9acdeb5434a57f10fbdeebc59ae7bcb7ef9ae 100644 --- a/drivers/target/target_core_sbc.c +++ b/drivers/target/target_core_sbc.c @@ -372,6 +372,13 @@ static sense_reason_t compare_and_write_callback(struct se_cmd *cmd) sense_reason_t ret = TCM_NO_SENSE; int rc, i; + /* + * Handle early failure in transport_generic_request_failure(), + * which will not have taken ->caw_mutex yet.. + */ + if (!cmd->t_data_sg || !cmd->t_bidi_data_sg) + return TCM_NO_SENSE; + buf = kzalloc(cmd->data_length, GFP_KERNEL); if (!buf) { pr_err("Unable to allocate compare_and_write buf\n"); diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c index e53c59ba745aa18c77230ba02b4e414be705e722..bcbc3d397badc9cdc5873c260ee9f9092924aeb1 100644 --- a/drivers/target/target_core_transport.c +++ b/drivers/target/target_core_transport.c @@ -1559,6 +1559,13 @@ void transport_generic_request_failure(struct se_cmd *cmd, * For SAM Task Attribute emulation for failed struct se_cmd */ transport_complete_task_attr(cmd); + /* + * Handle special case for COMPARE_AND_WRITE failure, where the + * callback is expected to drop the per device ->caw_mutex. + */ + if ((cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE) && + cmd->transport_complete_callback) + cmd->transport_complete_callback(cmd); switch (sense_reason) { case TCM_NON_EXISTENT_LUN: