[PATCH v3 2/3] scsi: ufs: core: Defer debugfs init until after device init

From: Po-Wen Kao

Date: Wed Nov 25 2026 - 06:35:19 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),
locks (hba->host_sem, hba->ee_ctrl_mutex), UniPro link, and device
descriptor are initialized.

Move ufs_debugfs_hba_init() and ufs_fault_inject_hba_init() into
ufshcd_init() alongside ufs_sysfs_add_nodes(), and remove the now
redundant ufs_debugfs_hba_exit() call from ufshcd_hba_exit() since
probe failures occur before ufs_debugfs_hba_init(). Split out
ufs_debugfs_ee_init() to initialize hba->debugfs_ee_work and
hba->debugfs_ee_rate_limit_ms in ufshcd_init() next to hba->eeh_work,
before interrupts are enabled.

Note that hba->trigger_eh_attr and hba->timeout_attr are now
initialized after device init. Until then the zero-initialized
fault_attr has probability 0, so should_fail() returns false and
module-parameter fault injection takes effect after device init rather
than during early probe device-management commands.

Suggested-by: Peter Wang <peter.wang@xxxxxxxxxxxx>
Signed-off-by: Brian Kao <powenkao@xxxxxxxxxx>
---
drivers/ufs/core/ufs-debugfs.c | 11 +++++++----
drivers/ufs/core/ufs-debugfs.h | 2 ++
drivers/ufs/core/ufshcd.c | 7 +++----
3 files changed, 12 insertions(+), 8 deletions(-)

diff --git a/drivers/ufs/core/ufs-debugfs.c b/drivers/ufs/core/ufs-debugfs.c
index 89753c40b27b..a3731dea11c7 100644
--- a/drivers/ufs/core/ufs-debugfs.c
+++ b/drivers/ufs/core/ufs-debugfs.c
@@ -472,14 +472,17 @@ static const struct ufs_debugfs_attr ufs_tx_eqtr_attrs[] = {
{ }
};

-void ufs_debugfs_hba_init(struct ufs_hba *hba)
+void ufs_debugfs_ee_init(struct ufs_hba *hba)
{
- const struct ufs_debugfs_attr *attr;
- struct dentry *root;
-
/* Set default exception event rate limit period to 20ms */
hba->debugfs_ee_rate_limit_ms = 20;
INIT_DELAYED_WORK(&hba->debugfs_ee_work, ufs_debugfs_restart_ee);
+}
+
+void ufs_debugfs_hba_init(struct ufs_hba *hba)
+{
+ const struct ufs_debugfs_attr *attr;
+ struct dentry *root;

root = debugfs_create_dir(dev_name(hba->dev), ufs_debugfs_root);
if (IS_ERR_OR_NULL(root))
diff --git a/drivers/ufs/core/ufs-debugfs.h b/drivers/ufs/core/ufs-debugfs.h
index e5bba9671862..d0acfd045a8b 100644
--- a/drivers/ufs/core/ufs-debugfs.h
+++ b/drivers/ufs/core/ufs-debugfs.h
@@ -13,12 +13,14 @@ struct ufs_hba;
#ifdef CONFIG_DEBUG_FS
void __init ufs_debugfs_init(void);
void ufs_debugfs_exit(void);
+void ufs_debugfs_ee_init(struct ufs_hba *hba);
void ufs_debugfs_hba_init(struct ufs_hba *hba);
void ufs_debugfs_hba_exit(struct ufs_hba *hba);
void ufs_debugfs_exception_event(struct ufs_hba *hba, u16 status);
#else
static inline void ufs_debugfs_init(void) {}
static inline void ufs_debugfs_exit(void) {}
+static inline void ufs_debugfs_ee_init(struct ufs_hba *hba) {}
static inline void ufs_debugfs_hba_init(struct ufs_hba *hba) {}
static inline void ufs_debugfs_hba_exit(struct ufs_hba *hba) {}
static inline void ufs_debugfs_exception_event(struct ufs_hba *hba, u16 status) {}
diff --git a/drivers/ufs/core/ufshcd.c b/drivers/ufs/core/ufshcd.c
index 646359d446c3..443dcd7ed12c 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);
@@ -11375,6 +11371,7 @@ int ufshcd_init(struct ufs_hba *hba, void __iomem *mmio_base, unsigned int irq)
}
INIT_WORK(&hba->eh_work, ufshcd_err_handler);
INIT_WORK(&hba->eeh_work, ufshcd_exception_event_handler);
+ ufs_debugfs_ee_init(hba);

sema_init(&hba->host_sem, 1);

@@ -11506,6 +11503,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.839.g22a8290db9-goog