Currently bits in hba->outstanding_tasks are cleared only after their corresponding task management commands are successfully done by __ufshcd_issue_tm_cmd(). If timeout happens in a task management command, its corresponding bit in hba->outstanding_tasks will not be cleared until next task management command with the same tag used successfully finishes. This is wrong and can lead to some issues, like power issue. For example, ufshcd_release() and ufshcd_gate_work() will do nothing if hba->outstanding_tasks is not zero even if both UFS host and devices are actually idle. Referring to error handling flow of hba->outstanding_reqs, all timed-out bits will be cleared by ufshcd_reset_and_restore() => ufshcd_transfer_req_compl() after reset is done. Therefore similar handling for hba->outstanding_tasks could be applied, for example, by ufshcd_reset_and_restore() => ufshcd_tmc_handler(). This patch tries to "re-factor" cleanup jobs first, and then add fixed flow to make the whole patch more readable. Stanley Chu (3): scsi: ufs: clean-up task resource immediately only if task is responded scsi: ufs: introduce ufshcd_tm_cmd_compl() to refactor task cleanup scsi: ufs: fix broken hba->outstanding_tasks drivers/scsi/ufs/ufshcd.c | 41 ++++++++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 7 deletions(-) -- 2.18.0