Linux PCI subsystem development
 help / color / mirror / Atom feed
* [v2] PCI: tegra194: Fix debugfs directory creation when CONFIG_PCIEASPM is disabled
@ 2025-04-06 13:43 Hans Zhang
  2025-04-06 18:10 ` Christophe JAILLET
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Zhang @ 2025-04-06 13:43 UTC (permalink / raw)
  To: lpieralisi
  Cc: christophe.jaillet, manivannan.sadhasivam, thierry.reding, kw,
	robh, bhelgaas, jonathanh, linux-pci, linux-kernel, linux-tegra,
	Hans Zhang

Previously, the debugfs directory was unconditionally created in
tegra_pcie_config_rp() regardless of the CONFIG_PCIEASPM setting.
This led to unnecessary directory creation when ASPM support was disabled.

Move the debugfs directory creation into init_debugfs() which is
conditionally compiled based on CONFIG_PCIEASPM. This ensures:
- The directory is only created when ASPM-related debugfs entries are
  needed.
- Proper error handling for directory creation failures.
- Avoids cluttering debugfs with empty directories when ASPM is disabled.

Signed-off-by: Hans Zhang <18255117159@163.com>
---
Changes since v1:
https://lore.kernel.org/linux-pci/20250405145459.26800-1-18255117159@163.com

- The first version was committed incorrectly because the judgment
  parameter in "debugfs_remove_recursive" was not noticed.
---
 drivers/pci/controller/dwc/pcie-tegra194.c | 27 +++++++++++++---------
 1 file changed, 16 insertions(+), 11 deletions(-)

diff --git a/drivers/pci/controller/dwc/pcie-tegra194.c b/drivers/pci/controller/dwc/pcie-tegra194.c
index 5103995cd6c7..f048b2342af4 100644
--- a/drivers/pci/controller/dwc/pcie-tegra194.c
+++ b/drivers/pci/controller/dwc/pcie-tegra194.c
@@ -711,16 +711,27 @@ static void init_host_aspm(struct tegra_pcie_dw *pcie)
 	dw_pcie_writel_dbi(pci, PCIE_PORT_AFR, val);
 }
 
-static void init_debugfs(struct tegra_pcie_dw *pcie)
+static int init_debugfs(struct tegra_pcie_dw *pcie)
 {
-	debugfs_create_devm_seqfile(pcie->dev, "aspm_state_cnt", pcie->debugfs,
+	struct device *dev = pcie->dev;
+	char *name;
+
+	name = devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node);
+	if (!name)
+		return -ENOMEM;
+
+	pcie->debugfs = debugfs_create_dir(name, NULL);
+
+	debugfs_create_devm_seqfile(dev, "aspm_state_cnt", pcie->debugfs,
 				    aspm_state_cnt);
+
+	return 0;
 }
 #else
 static inline void disable_aspm_l12(struct tegra_pcie_dw *pcie) { return; }
 static inline void disable_aspm_l11(struct tegra_pcie_dw *pcie) { return; }
 static inline void init_host_aspm(struct tegra_pcie_dw *pcie) { return; }
-static inline void init_debugfs(struct tegra_pcie_dw *pcie) { return; }
+static inline int init_debugfs(struct tegra_pcie_dw *pcie) { return 0; }
 #endif
 
 static void tegra_pcie_enable_system_interrupts(struct dw_pcie_rp *pp)
@@ -1634,7 +1645,6 @@ static void tegra_pcie_deinit_controller(struct tegra_pcie_dw *pcie)
 static int tegra_pcie_config_rp(struct tegra_pcie_dw *pcie)
 {
 	struct device *dev = pcie->dev;
-	char *name;
 	int ret;
 
 	pm_runtime_enable(dev);
@@ -1664,14 +1674,9 @@ static int tegra_pcie_config_rp(struct tegra_pcie_dw *pcie)
 		goto fail_host_init;
 	}
 
-	name = devm_kasprintf(dev, GFP_KERNEL, "%pOFP", dev->of_node);
-	if (!name) {
-		ret = -ENOMEM;
+	ret = init_debugfs(pcie);
+	if (ret < 0)
 		goto fail_host_init;
-	}
-
-	pcie->debugfs = debugfs_create_dir(name, NULL);
-	init_debugfs(pcie);
 
 	return ret;
 

base-commit: a8662bcd2ff152bfbc751cab20f33053d74d0963
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-04-07  1:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-06 13:43 [v2] PCI: tegra194: Fix debugfs directory creation when CONFIG_PCIEASPM is disabled Hans Zhang
2025-04-06 18:10 ` Christophe JAILLET
2025-04-07  1:16   ` Hans Zhang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox