[PATCH v4] scsi: ufs: Change the error check sequence for auto hibern8
From: HOYOUNG SEO
Date: Mon Oct 26 2026 - 01:31:15 EST
Auto-hibern8 enter and exit are performed by the host controller without
a UIC command, and the auto-hibern8 idle timer only runs while no UIC
command is outstanding. An auto-hibern8 error (IS.UHES or IS.UHXS) is
therefore usually reported while hba->active_uic_cmd is NULL.
Since commit fcd8b0450a9a ("scsi: ufs: core: Make ufshcd_uic_cmd_compl()
easier to analyze"), ufshcd_uic_cmd_compl() returns early when
hba->active_uic_cmd is NULL, before ufshcd_is_auto_hibern8_error() is
called. Such auto-hibern8 errors are no longer recorded in hba->errors,
so ufshcd_check_errors() is not called for them and the error handler is
not scheduled.
Check for auto-hibern8 errors before checking for an active UIC command,
as was done before that commit, but keep returning early when there is
no active UIC command so that a NULL cmd is never dereferenced. Only
report the missing UIC command if no auto-hibern8 error was found.
Fixes: fcd8b0450a9a ("scsi: ufs: core: Make ufshcd_uic_cmd_compl() easier to analyze")
---
Changes in v4:
- Change patch version
Changes in v3:
- Check auto-hibern8 errors before the NULL check again, so that errors
reported while a non-hibernate UIC command is active are still
detected (Sashiko review).
- Return early when no UIC command is active instead of falling
through, to avoid dereferencing a NULL cmd (Sashiko review).
- Add Fixes tag, reword subject and commit message.
Changes in v2:
- Check UFSHCD_UIC_HIBERN8_MASK for auto-hibern8 only when cmd is NULL.
v2: https://lore.kernel.org/linux-scsi/20261022074249.3098100-1-hy50.seo@xxxxxxxxxxx/
Signed-off-by: HOYOUNG SEO <hy50.seo@xxxxxxxxxxx>
---
drivers/ufs/core/ufshcd.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index d085d394858f..4541776e8d38 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -5941,16 +5941,22 @@ static irqreturn_t ufshcd_uic_cmd_compl(struct ufs_hba *hba, u32 intr_status)
struct uic_command *cmd;
guard(spinlock_irqsave)(&hba->host->host_lock);
+
+ /*
+ * Auto-hibern8 is performed without a UIC command, so check for
+ * auto-hibern8 errors before checking for an active UIC command.
+ */
+ if (ufshcd_is_auto_hibern8_error(hba, intr_status)) {
+ hba->errors |= (UFSHCD_UIC_HIBERN8_MASK & intr_status);
+
cmd = hba->active_uic_cmd;
if (!cmd) {
- dev_err(hba->dev,
- "No active UIC command. Maybe a timeout occurred?\n");
+ if (!(hba->errors & UFSHCD_UIC_HIBERN8_MASK))
+ dev_err(hba->dev,
+ "No active UIC command. Maybe a timeout occurred?\n");
return retval;
}
- if (ufshcd_is_auto_hibern8_error(hba, intr_status))
- hba->errors |= (UFSHCD_UIC_HIBERN8_MASK & intr_status);
-
if (intr_status & UIC_COMMAND_COMPL) {
/*
* Store the UIC command result in the lowest byte of
--
2.34.1