[PATCH v3 1/3] scsi: ufs: core: Remove debugfs before removing SCSI host
From: Po-Wen Kao
Date: Wed Nov 25 2026 - 06:35:10 EST
From: Brian Kao <powenkao@xxxxxxxxxx>
ufs_debugfs_hba_exit() is currently called only from ufshcd_hba_exit(),
after scsi_remove_host() has removed hba->ufs_device_wlun. Active
debugfs write handlers (e.g. exception_event_mask) and
hba->debugfs_ee_work call ufs_debugfs_get_user_access() ->
ufshcd_rpm_get_sync(), which can dereference a NULL or freed
hba->ufs_device_wlun during unbind.
Call ufs_debugfs_hba_exit() from ufshcd_remove() alongside
ufs_sysfs_remove_nodes(), before scsi_remove_host(), so in-flight
debugfs file operations are drained while the WLUN is still present.
Switch cancel_delayed_work_sync() to disable_delayed_work_sync()
(introduced in v6.10) so an in-flight exception event cannot re-queue
debugfs_ee_work during teardown, and clear hba->debugfs_root so the
existing ufs_debugfs_hba_exit() call in ufshcd_hba_exit() remains safe
on both normal remove and probe failure paths.
Fixes: b294ff3e3449 ("scsi: ufs: core: Enable power management for wlun")
Cc: stable@xxxxxxxxxxxxxxx # v6.10+
Signed-off-by: Brian Kao <powenkao@xxxxxxxxxx>
---
drivers/ufs/core/ufs-debugfs.c | 3 ++-
drivers/ufs/core/ufshcd.c | 1 +
2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/ufs/core/ufs-debugfs.c b/drivers/ufs/core/ufs-debugfs.c
index 9f83628f3e2c..89753c40b27b 100644
--- a/drivers/ufs/core/ufs-debugfs.c
+++ b/drivers/ufs/core/ufs-debugfs.c
@@ -529,5 +529,6 @@ void ufs_debugfs_hba_init(struct ufs_hba *hba)
void ufs_debugfs_hba_exit(struct ufs_hba *hba)
{
debugfs_remove_recursive(hba->debugfs_root);
- cancel_delayed_work_sync(&hba->debugfs_ee_work);
+ hba->debugfs_root = NULL;
+ disable_delayed_work_sync(&hba->debugfs_ee_work);
}
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 56a77f4a2a6e..646359d446c3 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -11027,6 +11027,7 @@ void ufshcd_remove(struct ufs_hba *hba)
ufs_bsg_remove(hba);
ufs_rpmb_remove(hba);
ufs_sysfs_remove_nodes(hba->dev);
+ ufs_debugfs_hba_exit(hba);
cancel_delayed_work_sync(&hba->ufs_rtc_update_work);
blk_mq_destroy_queue(hba->tmf_queue);
blk_put_queue(hba->tmf_queue);
--
2.56.1.839.g22a8290db9-goog