Bart said that lrbp->cmd could be changed before ufshcd_clear_cmd() was
called, so lrbp->cmd check was moved to ufshcd_clear_cmd().
In the case of legacy mode, spin_lock is used to protect before clear cmd,
but spin_lock cannot be used due to mcq mode, so it is necessary to check
the status of lrbp->cmd.
Change-Id: Id8412190e60286d00a30820591566835cefbf47e
diff --git a/drivers/ufs/core/ufs-mcq.c b/drivers/ufs/core/ufs-mcq.c
index 2ba8ec254dce..deb6dac724c8 100644
--- a/drivers/ufs/core/ufs-mcq.c
+++ b/drivers/ufs/core/ufs-mcq.c
@@ -507,6 +507,10 @@ int ufshcd_mcq_sq_cleanup(struct ufs_hba *hba, int task_tag)
if (hba->quirks & UFSHCD_QUIRK_MCQ_BROKEN_RTC)
return -ETIMEDOUT;
+ if (!ufshcd_cmd_inflight(cmd) ||
+ test_bit(SCMD_STATE_COMPLETE, &cmd->state))
+ return 0;
+
if (task_tag != hba->nutrs - UFSHCD_NUM_RESERVED) {
if (!cmd)
return -EINVAL;