From: Sasha Levin <sashal@kernel.org>
To: stable@vger.kernel.org
Cc: Stanley Jhu <stanleyjhu@google.com>,
Bart Van Assche <bvanassche@acm.org>,
Peter Wang <peter.wang@mediatek.com>,
"Martin K. Petersen (Oracle)" <mkp@kernel.org>,
Sasha Levin <sashal@kernel.org>
Subject: [PATCH 6.18.y 2/2] scsi: ufs: sysfs: Propagate runtime PM resume errors
Date: Fri, 4 Dec 2026 00:22:43 -0500 [thread overview]
Message-ID: <20261204052236.2756612-2-sashal@kernel.org> (raw)
In-Reply-To: <20261204052236.2756612-1-sashal@kernel.org>
From: Stanley Jhu <stanleyjhu@google.com>
[ Upstream commit 93891d1c486efcef2267c32e6e73ca2fd243704e ]
All 14 ufshcd_rpm_get_sync() callers in ufs-sysfs.c resume the UFS device
W-LUN and ignore the return value. For example, for a UFS descriptor read:
1. The W-LUN is runtime suspended.
2. User space reads a UFS descriptor attribute in sysfs.
3. ufs_sysfs_read_desc_param() calls ufshcd_rpm_get_sync().
4. The W-LUN runtime resume fails and the W-LUN stays suspended.
5. ufshcd_rpm_get_sync() returns a negative errno, which is ignored.
6. ufs_sysfs_read_desc_param() sends a query UPIU while the W-LUN is
still suspended.
The other sysfs callers follow the same sequence. They send other query
UPIUs, or read a host register in ufshcd_read_hci_reg().
Switch all 14 sysfs callers to ufshcd_rpm_resume_and_get() and return the
error after releasing any held buffer and hba->host_sem.
Fixes: aef80fd1da32 ("scsi: ufs: sysfs: Resume the proper SCSI device")
Fixes: b9d104465a6c ("scsi: ufs: Prepare to add HCI capabilities sysfs")
Fixes: 600edc6620a4 ("scsi: ufs: sysfs: Make max_number_of_rtt read-write")
Fixes: 6c4148ce7cc1 ("scsi: ufs: wb: Add explicit flush sysfs attribute")
Fixes: 500d4b742e0c ("scsi: ufs: core: Add WB buffer resize support")
Fixes: ae7795a8c258 ("scsi: ufs: core: Add HID support")
Fixes: 1fd2e77b8897 ("scsi: ufs: core: Add device level exception support")
Cc: stable@vger.kernel.org # needs "scsi: ufs: core: Introduce ufshcd_rpm_resume_and_get() helper"
Signed-off-by: Stanley Jhu <stanleyjhu@google.com>
Reviewed-by: Bart Van Assche <bvanassche@acm.org>
Reviewed-by: Peter Wang <peter.wang@mediatek.com>
Link: https://patch.msgid.link/20261029040003.2100003-4-stanleyjhu@google.com
Signed-off-by: Martin K. Petersen (Oracle) <mkp@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
drivers/ufs/core/ufs-sysfs.c | 67 ++++++++++++++++++++++++++++--------
1 file changed, 53 insertions(+), 14 deletions(-)
diff --git a/drivers/ufs/core/ufs-sysfs.c b/drivers/ufs/core/ufs-sysfs.c
index c00ae7282fe1f..18433c2050c46 100644
--- a/drivers/ufs/core/ufs-sysfs.c
+++ b/drivers/ufs/core/ufs-sysfs.c
@@ -248,13 +248,19 @@ static u32 ufshcd_us_to_ahit(unsigned int timer)
static int ufshcd_read_hci_reg(struct ufs_hba *hba, u32 *val, unsigned int reg)
{
+ int ret;
+
down(&hba->host_sem);
if (!ufshcd_is_user_access_allowed(hba)) {
up(&hba->host_sem);
return -EBUSY;
}
- ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_rpm_resume_and_get(hba);
+ if (ret) {
+ up(&hba->host_sem);
+ return ret;
+ }
ufshcd_hold(hba);
*val = ufshcd_readl(hba, reg);
ufshcd_release(hba);
@@ -348,7 +354,9 @@ static ssize_t wb_on_store(struct device *dev, struct device_attribute *attr,
goto out;
}
- ufshcd_rpm_get_sync(hba);
+ res = ufshcd_rpm_resume_and_get(hba);
+ if (res)
+ goto out;
res = ufshcd_wb_toggle(hba, wb_enable);
ufshcd_rpm_put_sync(hba);
out:
@@ -419,7 +427,9 @@ static ssize_t enable_wb_buf_flush_store(struct device *dev,
goto out;
}
- ufshcd_rpm_get_sync(hba);
+ res = ufshcd_rpm_resume_and_get(hba);
+ if (res)
+ goto out;
res = ufshcd_wb_toggle_buf_flush(hba, enable_wb_buf_flush);
ufshcd_rpm_put_sync(hba);
@@ -488,7 +498,9 @@ static ssize_t wb_resize_enable_store(struct device *dev,
goto out;
}
- ufshcd_rpm_get_sync(hba);
+ res = ufshcd_rpm_resume_and_get(hba);
+ if (res)
+ goto out;
res = ufshcd_wb_set_resize_en(hba, mode);
ufshcd_rpm_put_sync(hba);
@@ -596,7 +608,9 @@ static ssize_t device_lvl_exception_id_show(struct device *dev,
if (hba->dev_info.wspecversion < 0x410)
return -EOPNOTSUPP;
- ufshcd_rpm_get_sync(hba);
+ err = ufshcd_rpm_resume_and_get(hba);
+ if (err)
+ return err;
err = ufshcd_query_attr_qword(hba, UPIU_QUERY_OPCODE_READ_ATTR,
QUERY_ATTR_IDN_DEV_LVL_EXCEPTION_ID,
0, 0, &exception_id);
@@ -1069,7 +1083,9 @@ static ssize_t ufs_sysfs_read_desc_param(struct ufs_hba *hba,
goto out;
}
- ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_rpm_resume_and_get(hba);
+ if (ret)
+ goto out;
ret = ufshcd_read_desc_param(hba, desc_id, desc_index,
param_offset, desc_buf, param_size);
ufshcd_rpm_put_sync(hba);
@@ -1450,7 +1466,12 @@ static ssize_t _name##_show(struct device *dev, \
up(&hba->host_sem); \
return -ENOMEM; \
} \
- ufshcd_rpm_get_sync(hba); \
+ ret = ufshcd_rpm_resume_and_get(hba); \
+ if (ret) { \
+ kfree(desc_buf); \
+ up(&hba->host_sem); \
+ return ret; \
+ } \
ret = ufshcd_query_descriptor_retry(hba, \
UPIU_QUERY_OPCODE_READ_DESC, QUERY_DESC_IDN_DEVICE, \
0, 0, desc_buf, &desc_len); \
@@ -1516,7 +1537,9 @@ static ssize_t _name##_show(struct device *dev, \
} \
if (ufshcd_is_wb_flags(QUERY_FLAG_IDN##_uname)) \
index = ufshcd_wb_get_query_index(hba); \
- ufshcd_rpm_get_sync(hba); \
+ ret = ufshcd_rpm_resume_and_get(hba); \
+ if (ret) \
+ goto out; \
ret = ufshcd_query_flag(hba, UPIU_QUERY_OPCODE_READ_FLAG, \
QUERY_FLAG_IDN##_uname, index, &flag); \
ufshcd_rpm_put_sync(hba); \
@@ -1576,7 +1599,9 @@ static ssize_t max_number_of_rtt_show(struct device *dev,
return -EBUSY;
}
- ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_rpm_resume_and_get(hba);
+ if (ret)
+ goto out;
ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
QUERY_ATTR_IDN_MAX_NUM_OF_RTT, 0, 0, &rtt);
ufshcd_rpm_put_sync(hba);
@@ -1616,7 +1641,9 @@ static ssize_t max_number_of_rtt_store(struct device *dev,
goto out;
}
- ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_rpm_resume_and_get(hba);
+ if (ret)
+ goto out;
memflags = memalloc_noio_save();
shost_for_each_device(sdev, hba->host)
@@ -1668,7 +1695,11 @@ static int wb_read_resize_attrs(struct ufs_hba *hba,
}
index = ufshcd_wb_get_query_index(hba);
- ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_rpm_resume_and_get(hba);
+ if (ret) {
+ up(&hba->host_sem);
+ return ret;
+ }
ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
idn, index, 0, attr_val);
ufshcd_rpm_put_sync(hba);
@@ -1728,7 +1759,9 @@ static ssize_t _name##_show(struct device *dev, \
} \
if (ufshcd_is_wb_attrs(QUERY_ATTR_IDN##_uname)) \
index = ufshcd_wb_get_query_index(hba); \
- ufshcd_rpm_get_sync(hba); \
+ ret = ufshcd_rpm_resume_and_get(hba); \
+ if (ret) \
+ goto out; \
if (ufshcd_is_qword_attr(QUERY_ATTR_IDN##_uname)) \
ret = ufshcd_query_attr_qword(hba, \
UPIU_QUERY_OPCODE_READ_ATTR, \
@@ -1816,7 +1849,11 @@ static int hid_query_attr(struct ufs_hba *hba, enum query_opcode opcode,
return -EBUSY;
}
- ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_rpm_resume_and_get(hba);
+ if (ret) {
+ up(&hba->host_sem);
+ return ret;
+ }
ret = ufshcd_query_attr(hba, opcode, idn, 0, 0, attr_val);
ufshcd_rpm_put_sync(hba);
@@ -2085,7 +2122,9 @@ static ssize_t dyn_cap_needed_attribute_show(struct device *dev,
goto out;
}
- ufshcd_rpm_get_sync(hba);
+ ret = ufshcd_rpm_resume_and_get(hba);
+ if (ret)
+ goto out;
ret = ufshcd_query_attr(hba, UPIU_QUERY_OPCODE_READ_ATTR,
QUERY_ATTR_IDN_DYN_CAP_NEEDED, lun, 0, &value);
ufshcd_rpm_put_sync(hba);
--
2.53.0
prev parent reply other threads:[~2026-12-04 5:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 13:54 FAILED: patch "[PATCH] scsi: ufs: sysfs: Propagate runtime PM resume errors" failed to apply to 6.18-stable tree gregkh
2026-12-04 5:22 ` [PATCH 6.18.y 1/2] scsi: ufs: core: Introduce function ufshcd_query_attr_qword() Sasha Levin
2026-12-04 5:22 ` Sasha Levin [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261204052236.2756612-2-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=bvanassche@acm.org \
--cc=mkp@kernel.org \
--cc=peter.wang@mediatek.com \
--cc=stable@vger.kernel.org \
--cc=stanleyjhu@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox