[PATCH 4/5] scsi: ufs: bsg: Abort ufs_bsg_request() when runtime resume fails

From: Stanley Jhu

Date: Sat Oct 24 2026 - 21:36:04 EST


In ufs_bsg_request(), the return value of ufshcd_rpm_get_sync() is
ignored:

1. A user-space BSG request arrives when W-LUN runtime resume fails,
when power.runtime_error is latched, or when W-LUN runtime PM is
disabled while not active.
2. ufshcd_rpm_get_sync() returns a negative errno without resuming the
device.
3. ufs_bsg_request() still dispatches raw query, NOP OUT, task
management, UIC, or advanced RPMB commands to the unresumed host.

Use ufshcd_rpm_resume_and_get() and jump to out_complete on error so the
BSG job is completed via bsg_job_done() with the failure code without
dropping an unacquired runtime PM reference.

Fixes: b294ff3e3449 ("scsi: ufs: core: Enable power management for wlun")
Cc: stable@xxxxxxxxxxxxxxx # needs "scsi: ufs: core: Introduce ufshcd_rpm_resume_and_get() helper"
Signed-off-by: Stanley Jhu <stanleyjhu@xxxxxxxxxx>
---
drivers/ufs/core/ufs_bsg.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/ufs/core/ufs_bsg.c b/drivers/ufs/core/ufs_bsg.c
index baf6ae917d36..8df1a2c6abf6 100644
--- a/drivers/ufs/core/ufs_bsg.c
+++ b/drivers/ufs/core/ufs_bsg.c
@@ -150,7 +150,9 @@ static int ufs_bsg_request(struct bsg_job *job)
goto out_complete;
}

- ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_rpm_resume_and_get(hba);
+ if (ret)
+ goto out_complete;

msgcode = bsg_request->msgcode;
switch (msgcode) {
--
2.56.0.307.g5fe7bd680c-goog