Message ID | 20221209101321.30671-1-mason.zhang@mediatek.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | [v3,1/1] scsi: ufs: core: fix device management cmd timeout flow | expand |
On 12/9/22 02:13, Mason Zhang wrote: > diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c > index b1f59a5fe632..6fe51b8d41f9 100644 > --- a/drivers/ufs/core/ufshcd.c > +++ b/drivers/ufs/core/ufshcd.c > @@ -2979,35 +2979,31 @@ static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba, > err = -ETIMEDOUT; > dev_dbg(hba->dev, "%s: dev_cmd request timedout, tag %d\n", > __func__, lrbp->task_tag); > - if (ufshcd_clear_cmds(hba, 1U << lrbp->task_tag) == 0) { > + if (ufshcd_clear_cmds(hba, 1U << lrbp->task_tag) == 0) > /* successfully cleared the command, retry if needed */ > err = -EAGAIN; > + /* > + * in case of an error, after clearing the doorbell, > + * we also need to clear the task tag bit from the > + * outstanding_reqs variable. > + */ > + spin_lock_irqsave(&hba->outstanding_lock, flags); > + pending = test_bit(lrbp->task_tag, > + &hba->outstanding_reqs); > + if (pending) { > + hba->dev_cmd.complete = NULL; > + __clear_bit(lrbp->task_tag, > + &hba->outstanding_reqs); > + } > + spin_unlock_irqrestore(&hba->outstanding_lock, flags); This patch causes the 'task_tag' bit to be cleared from outstanding_reqs even if ufshcd_clear_cmds() failed. I think that's wrong. Bart.
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c index b1f59a5fe632..6fe51b8d41f9 100644 --- a/drivers/ufs/core/ufshcd.c +++ b/drivers/ufs/core/ufshcd.c @@ -2979,35 +2979,31 @@ static int ufshcd_wait_for_dev_cmd(struct ufs_hba *hba, err = -ETIMEDOUT; dev_dbg(hba->dev, "%s: dev_cmd request timedout, tag %d\n", __func__, lrbp->task_tag); - if (ufshcd_clear_cmds(hba, 1U << lrbp->task_tag) == 0) { + if (ufshcd_clear_cmds(hba, 1U << lrbp->task_tag) == 0) /* successfully cleared the command, retry if needed */ err = -EAGAIN; + /* + * in case of an error, after clearing the doorbell, + * we also need to clear the task tag bit from the + * outstanding_reqs variable. + */ + spin_lock_irqsave(&hba->outstanding_lock, flags); + pending = test_bit(lrbp->task_tag, + &hba->outstanding_reqs); + if (pending) { + hba->dev_cmd.complete = NULL; + __clear_bit(lrbp->task_tag, + &hba->outstanding_reqs); + } + spin_unlock_irqrestore(&hba->outstanding_lock, flags); + + if (!pending) { /* - * Since clearing the command succeeded we also need to - * clear the task tag bit from the outstanding_reqs - * variable. + * The completion handler ran while we tried to + * clear the command. */ - spin_lock_irqsave(&hba->outstanding_lock, flags); - pending = test_bit(lrbp->task_tag, - &hba->outstanding_reqs); - if (pending) { - hba->dev_cmd.complete = NULL; - __clear_bit(lrbp->task_tag, - &hba->outstanding_reqs); - } - spin_unlock_irqrestore(&hba->outstanding_lock, flags); - - if (!pending) { - /* - * The completion handler ran while we tried to - * clear the command. - */ - time_left = 1; - goto retry; - } - } else { - dev_err(hba->dev, "%s: failed to clear tag %d\n", - __func__, lrbp->task_tag); + time_left = 1; + goto retry; } }