Skip to contentSkip to conversation

mfd/intel-lpss: Fix DebugFS initialization

PATCH Superseded Maria Lisina 2 participants 2 messages Sep 13

Subsystems (2)

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 mfd/intel-lpss: Fix DebugFS initialization

The original code defers DebugFS check with unnecessary warning message which also appears when DebugFS is simply disabled.

Therefore it spams dmesg with these messages:

intel-lpss 0000:00:15.0: Failed to create debugfs entries intel-lpss 0000:00:15.3: Failed to create debugfs entries intel-lpss 0000:00:1e.0: Failed to create debugfs entries intel-lpss 0000:00:1e.2: Failed to create debugfs entries

This patch adds proper checks to intel_lpss_exit() and intel_lpss_debugfs_add() functions and removes warning message.

---
Changes in v2:
- Fixed function name in comment section.
- Link to v1: https://lore.kernel.org/r/[email protected]

---
 drivers/mfd/intel-lpss.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/mfd/intel-lpss.c +13 -6
index 63d6694f71457b2e09d238af0a9bfb897a169a64..c2cb58c0f98a996d5a2718956092e74139f2a286 100644
@@ -146,9 +146,12 @@ static int intel_lpss_debugfs_add(struct intel_lpss *lpss)
 {
 	struct dentry *dir;
 
+	if (!intel_lpss_debugfs) {
+		lpss->debugfs = NULL;
+		return 0;
+	}
+
 	dir = debugfs_create_dir(dev_name(lpss->dev), intel_lpss_debugfs);
-	if (IS_ERR(dir))
-		return PTR_ERR(dir);
 
 	/* Cache the values into lpss structure */
 	intel_lpss_cache_ltr(lpss);
@@ -432,10 +435,7 @@ int intel_lpss_probe(struct device *dev,
 		goto err_clk_register;
 
 	intel_lpss_ltr_expose(lpss);
-
-	ret = intel_lpss_debugfs_add(lpss);
-	if (ret)
-		dev_warn(dev, "Failed to create debugfs entries\n");
+	intel_lpss_debugfs_add(lpss);
 
 	if (intel_lpss_has_idma(lpss)) {
 		ret = mfd_add_devices(dev, lpss->devid, &intel_lpss_idma64_cell,
@@ -539,6 +539,13 @@ EXPORT_NS_GPL_DEV_PM_OPS(intel_lpss_pm_ops, INTEL_LPSS) = {
 static int __init intel_lpss_init(void)
 {
 	intel_lpss_debugfs = debugfs_create_dir("intel_lpss", NULL);
+
+	/* Ensure intel_lpss_debugfs stays NULL on error,
+	 * so intel_lpss_debugfs_add() exits properly.
+	 */
+	if (IS_ERR(intel_lpss_debugfs))
+		intel_lpss_debugfs = NULL;
+
 	return 0;
 }
 module_init(intel_lpss_init);

---
base-commit: 2f0c1cf72f4682178506f513bbf015e591b1aa4a
change-id: 20260913-intel-lpss-debugfs-eff3580d1295

Best regards,

Signature · 1 line
Maria Lisina <[email protected]>
#1 lore raw
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:

New issues:
- [Medium] The commit message inaccurately claims to add checks to intel_lpss_exit(), whereas the patch actually modifies intel_lpss_init().
- [Low] The commit message uses a non-standard prefix format that violates MFD subsystem guidelines.

Pre-existing issues:
- [High] The intel_lpss_probe() error path fails to call mfd_remove_devices(), leaving the previously added IDMA child device permanently registered if the main MFD cell registration fails, causing a resource leak and use-after-free.
- [High] Leaked clock gate resource on the error path of intel_lpss_register_clock_divider().
--

commit 268d7b5a570b7b03f10365238994919c9ea9264b
Author: Maria Lisina <[email protected]>

mfd/intel-lpss: Fix DebugFS initialization

This commit fixes a spammy warning message in dmesg when DebugFS is disabled. It removes the warning from the probe path and adds checks to handle a disabled DebugFS gracefully.

Quoted 1 line

mfd/intel-lpss: Fix DebugFS initialization

[Severity: Low]
This isn't a bug, but does this commit prefix violate the MFD subsystem guidelines which require "mfd: intel-lpss:" instead of "mfd/intel-lpss:"?

Quoted 2 lines

This patch adds proper checks to intel_lpss_exit() and intel_lpss_debugfs_add() functions and removes warning message.

[Severity: Medium]
Is this description accurate? The patch actually applies the check to intel_lpss_init() and does not touch intel_lpss_exit(). Could the commit message be more precise about the modified functions?

Quoted 9 lines
drivers/mfd/intel-lpss.c +0 -0
index 63d6694f71457..c2cb58c0f98a9 100644
 
[ ... ]
@@ -432,10 +435,7 @@ int intel_lpss_probe(struct device *dev,
 		goto err_clk_register;

drivers/mfd/intel-lpss.c int intel_lpss_probe(struct device *dev, · line 441

Quoted 10 lines
drivers/mfd/intel-lpss.c +1 -4
 
 	intel_lpss_ltr_expose(lpss);
-
-	ret = intel_lpss_debugfs_add(lpss);
-	if (ret)
-		dev_warn(dev, "Failed to create debugfs entries\n");
+	intel_lpss_debugfs_add(lpss);
 
 	if (intel_lpss_has_idma(lpss)) {
 		ret = mfd_add_devices(dev, lpss->devid, &intel_lpss_idma64_cell,

[Severity: High]
This is a pre-existing issue, but does intel_lpss_probe() in drivers/mfd/intel-lpss.c leak the IDMA child device if the second mfd_add_devices() call fails?

If the first mfd_add_devices() call above succeeds, but the second one fails:

	ret = mfd_add_devices(dev, lpss->devid, lpss->cell,
			      1, info->mem, info->irq, NULL);
	if (ret)
		goto err_remove_ltr;

The error path skips unwinding the first child device:

err_remove_ltr:

	intel_lpss_debugfs_remove(lpss);
	intel_lpss_ltr_hide(lpss);
	intel_lpss_unregister_clock(lpss);

This seems to lack the required mfd_remove_devices(dev) call, leaving the previously added IDMA child device permanently registered. Could this cause a use-after-free when devres frees the parent driver structures?

[Severity: High]
This is a pre-existing issue, but can a clock gate resource be leaked on the error path of intel_lpss_register_clock_divider() in drivers/mfd/intel-lpss.c?

When registering the clock divider, the gate clock is successfully registered:

	tmp = clk_register_gate(NULL, name, __clk_get_name(tmp), 0,
				lpss->priv, 0, 0, NULL);
	if (IS_ERR(tmp))
		return PTR_ERR(tmp);

If the subsequent fractional divider registration fails:

	tmp = clk_register_fractional_divider(NULL, name, __clk_get_name(tmp),
					      0, lpss->priv, 1, 15, 16, 15,
					      CLK_FRAC_DIVIDER_POWER_OF_TWO_PS,
					      NULL);
	if (IS_ERR(tmp))
		return PTR_ERR(tmp);

The tmp pointer is overwritten with an error pointer, and the previously registered gate clock is lost and permanently leaked. Since the clock was registered without devres (NULL device pointer) and the error path unregistration function only walks up the clock tree from an unassigned pointer, the child gate clock cannot be unregistered.

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1