[PATCH v4 1/6] ufs: core: Set task state before io_schedule_timeout()

Bart Van Assche <[email protected]> Fri, 31 Jul 2026 14:52:06 -0700
Newsgroups org.kernel.vger.linux-scsi
Message-ID <68f3346cab2be570839350831f82b6c9233832ed.1785534721.git.bvanassche@acm.org>
Set the task state to TASK_UNINTERRUPTIBLE before calling
io_schedule_timeout() in ufshcd_wait_for_pending_cmds().
Without setting the task state, io_schedule_timeout() returns
immediately because the task state remains TASK_RUNNING. This
results in a busy loop that wastes CPU cycles.

Fixes: 2000bc309703 ("scsi: ufs: core: Reduce the clock scaling latency")
Reported-by: Sashiko <[email protected]>
Signed-off-by: Bart Van Assche <[email protected]>
---
 drivers/ufs/core/ufshcd.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 1a5a851d43b2..5f99aad26d57 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -1317,6 +1317,7 @@ static int ufshcd_wait_for_pending_cmds(struct ufs_=
hba *hba,
 			break;
 		}
=20
+		__set_current_state(TASK_UNINTERRUPTIBLE);
 		io_schedule_timeout(msecs_to_jiffies(20));
 		if (ktime_to_us(ktime_sub(ktime_get(), start)) >
 		    wait_timeout_us) {