[PATCH v2 1/2] scsi: ufs: core: Defer debugfs init until after device init
From: Po-Wen Kao
Date: Mon Nov 23 2026 - 20:30:11 EST
From: Brian Kao <powenkao@xxxxxxxxxx>
ufshcd_hba_init() currently creates the debugfs hierarchy and fault
injection attributes before the controller version (hba->ufs_version),
controller locks, and device descriptor (hba->dev_info.wspecversion) are
initialized.
Move ufs_debugfs_hba_init() and ufs_fault_inject_hba_init() into
ufshcd_init() alongside ufs_sysfs_add_nodes(), and move the matching
ufs_debugfs_hba_exit() from ufshcd_hba_exit() into ufshcd_remove()
alongside ufs_sysfs_remove_nodes(). Use disable_delayed_work_sync() in
ufs_debugfs_hba_exit() so an in-flight exception event cannot re-queue
debugfs_ee_work while scsi_remove_host() is still tearing down devices.
Moving the exit call symmetrically keeps probe error paths from tearing
down uncreated debugfs state, drains debugfs readers before
scsi_remove_host() removes the WLUN during unbind, and lets debugfs
initialization inspect both hba->ufs_version and
hba->dev_info.wspecversion directly.
Suggested-by: Peter Wang <peter.wang@xxxxxxxxxxxx>
Signed-off-by: Brian Kao <powenkao@xxxxxxxxxx>
---
drivers/ufs/core/ufs-debugfs.c | 2 +-
drivers/ufs/core/ufshcd.c | 7 +++----
2 files changed, 4 insertions(+), 5 deletions(-)
diff --git a/drivers/ufs/core/ufs-debugfs.c b/drivers/ufs/core/ufs-debugfs.c
index 9f83628f3e2c..e62b942b37dc 100644
--- a/drivers/ufs/core/ufs-debugfs.c
+++ b/drivers/ufs/core/ufs-debugfs.c
@@ -529,5 +529,5 @@ 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);
+ disable_delayed_work_sync(&hba->debugfs_ee_work);
}
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 56a77f4a2a6e..f1df1d6734d9 100644
--- a/drivers/ufs/core/ufshcd.c
+++ b/drivers/ufs/core/ufshcd.c
@@ -10115,9 +10115,6 @@ static int ufshcd_hba_init(struct ufs_hba *hba)
if (err)
goto out_disable_vreg;
- ufs_debugfs_hba_init(hba);
- ufs_fault_inject_hba_init(hba);
-
hba->is_powered = true;
goto out;
@@ -10139,7 +10136,6 @@ static void ufshcd_hba_exit(struct ufs_hba *hba)
ufshcd_exit_clk_gating(hba);
if (hba->eh_wq)
destroy_workqueue(hba->eh_wq);
- ufs_debugfs_hba_exit(hba);
ufshcd_vops_exit(hba);
ufshcd_setup_vreg(hba, false);
ufshcd_setup_clocks(hba, false);
@@ -11027,6 +11023,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);
@@ -11505,6 +11502,8 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
ufs_sysfs_add_nodes(hba->dev);
hba->dme_qos_sysfs_handle = sysfs_get_dirent(hba->dev->kobj.sd,
"dme_qos_notification");
+ ufs_debugfs_hba_init(hba);
+ ufs_fault_inject_hba_init(hba);
async_schedule(ufshcd_async_scan, hba);
device_enable_async_suspend(dev);
--
2.56.1.809.ga0b61035b5-goog