From: Stanley Jhu <stanleyjhu@google.com>
To: "Martin K . Petersen" <mkp@kernel.org>,
"James E . J . Bottomley"
<James.Bottomley@HansenPartnership.com>
Cc: Alim Akhtar <alim.akhtar@samsung.com>,
Bart Van Assche <bvanassche@acm.org>,
Bean Huo <beanhuo@micron.com>,
Can Guo <can.guo@oss.qualcomm.com>,
Peter Wang <peter.wang@mediatek.com>,
linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org,
Stanley Jhu <stanleyjhu@google.com>,
stable@vger.kernel.org
Subject: [PATCH 3/5] scsi: ufs: sysfs: Propagate runtime PM resume errors
Date: Sun, 25 Oct 2026 09:34:44 +0800 [thread overview]
Message-ID: <20261025013446.345974-4-stanleyjhu@google.com> (raw)
In-Reply-To: <20261025013446.345974-1-stanleyjhu@google.com>
All 14 ufshcd_rpm_get_sync() callers in ufs-sysfs.c ignore its return
value:
1. A user-space sysfs read or write runs when W-LUN runtime resume
fails, when power.runtime_error is set from a failed runtime
suspend, or when W-LUN runtime PM is disabled while not active.
2. ufshcd_rpm_get_sync() returns a negative errno without waking the
device or host controller.
3. ufshcd_read_hci_reg() reads an HCI MMIO register on an unresumed
controller, and the remaining handlers issue query UPIUs over a
suspended or broken link.
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>
---
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 cf49ad0258e1..19b62cf52410 100644
--- a/drivers/ufs/core/ufs-sysfs.c
+++ b/drivers/ufs/core/ufs-sysfs.c
@@ -250,13 +250,19 @@ EXPORT_SYMBOL_GPL(ufshcd_us_to_ahit);
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);
@@ -350,7 +356,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:
@@ -421,7 +429,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);
@@ -490,7 +500,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);
@@ -598,7 +610,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);
@@ -1101,7 +1115,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);
@@ -1482,7 +1498,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); \
@@ -1548,7 +1569,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); \
@@ -1608,7 +1631,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);
@@ -1648,7 +1673,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)
@@ -1700,7 +1727,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);
@@ -1760,7 +1791,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, \
@@ -1848,7 +1881,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);
@@ -2121,7 +2158,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.56.0.307.g5fe7bd680c-goog
next prev parent reply other threads:[~2026-10-25 1:34 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-25 1:34 [PATCH 0/5] scsi: ufs: Fix device management timeouts and runtime PM errors Stanley Jhu
2026-10-25 1:34 ` [PATCH 1/5] scsi: ufs: core: Restore jiffies conversion of device management timeouts Stanley Jhu
2026-10-25 1:34 ` [PATCH 2/5] scsi: ufs: core: Introduce ufshcd_rpm_resume_and_get() helper Stanley Jhu
2026-10-25 1:34 ` Stanley Jhu [this message]
2026-10-25 1:34 ` [PATCH 4/5] scsi: ufs: bsg: Abort ufs_bsg_request() when runtime resume fails Stanley Jhu
2026-10-25 1:34 ` [PATCH 5/5] scsi: ufs: hwmon, debugfs: Propagate runtime PM resume errors Stanley Jhu
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=20261025013446.345974-4-stanleyjhu@google.com \
--to=stanleyjhu@google.com \
--cc=James.Bottomley@HansenPartnership.com \
--cc=alim.akhtar@samsung.com \
--cc=beanhuo@micron.com \
--cc=bvanassche@acm.org \
--cc=can.guo@oss.qualcomm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-scsi@vger.kernel.org \
--cc=mkp@kernel.org \
--cc=peter.wang@mediatek.com \
--cc=stable@vger.kernel.org \
/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
all inboxes | Powered by JetHome®