Skip to contentSkip to conversation

mfd/intel-lpss: Fix DebugFS initialization

PATCH Superseded Maria Lisina 2 participants 2 messages Sep 13

Subsystems (2)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 drivers/mfd/intel-lpss.c | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)
drivers/mfd/intel-lpss.c +13 -6
index 63d6694f71457b2e09d238af0a9bfb897a169a64..51550c1835c695b9081b33c67f81c19fee5e1652 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 claims to modify intel_lpss_exit(), but it actually modifies intel_lpss_init().
- [Low] Non-standard commit message prefix violates MFD subsystem conventions.

Pre-existing issues:
- [High] Missing mfd_remove_devices() in the error path of intel_lpss_probe() causes leaked child devices and a potential Use-After-Free.
- [High] Skipping LTR caching when debugfs is disabled causes incorrect PM QoS hardware writes to be skipped.
--

commit 8da79d835d33133ad4b3fd059be5d350a5d246f0
Author: Maria Lisina <[email protected]>

mfd/intel-lpss: Fix DebugFS initialization

This commit fixes DebugFS initialization in the intel-lpss driver by adding proper checks when debugfs is disabled. It aims to prevent dmesg spam regarding failed debugfs entries.

Quoted 1 line

mfd/intel-lpss: Fix DebugFS initialization

[Severity: Low]
Does this commit message prefix violate the MFD subsystem conventions?

The MFD subsystem guidelines enforce a strict commit prefix format:
mfd: <Driver>: <Capitalized description>. Using a slash instead of a colon after the subsystem name breaks Git history categorization standards.

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 the reference to intel_lpss_exit() correct here?

The commit message states that this patch modifies intel_lpss_exit(), but the code changes actually modify intel_lpss_init() to set intel_lpss_debugfs = NULL on error. intel_lpss_exit() is not modified in the provided diff.

drivers/mfd/intel-lpss.c static int intel_lpss_debugfs_add(struct intel_lpss *lpss) · line 153

Quoted 13 lines
drivers/mfd/intel-lpss.c +5 -0
index 63d6694f71457..51550c1835c69 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;
+	}
+

[Severity: High]
This isn't a bug introduced by this patch, but does skipping intel_lpss_cache_ltr() here cause incorrect PM QoS hardware writes to be skipped?

If debugfs is disabled in the kernel, intel_lpss_debugfs_add() returns early here, skipping the subsequent call to intel_lpss_cache_ltr(). Because lpss is zero-allocated, lpss->active_ltr and lpss->idle_ltr remain 0.

Later, when PM QoS calls intel_lpss_ltr_set(), it checks if the new LTR value matches lpss->active_ltr:

drivers/mfd/intel-lpss.c:intel_lpss_ltr_set() {
    ...
    if (ltr == lpss->active_ltr)
        return;
    ...
}

If the new calculated LTR value evaluates to 0, this check evaluates to true and the function returns early without writing to the hardware register, leaving the LTR incorrectly active.

[ ... ]

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

Quoted 12 lines
drivers/mfd/intel-lpss.c +1 -4
@@ -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,

[Severity: High]
This is a pre-existing issue, but is the error path missing a call to mfd_remove_devices() if the main cell registration fails?

In intel_lpss_probe(), the driver registers the IDMA child device via mfd_add_devices(). If the subsequent mfd_add_devices() call for the main cell fails, the probe function jumps to err_remove_ltr:

drivers/mfd/intel-lpss.c:intel_lpss_probe() {
    ...
    ret = mfd_add_devices(dev, lpss->devid, lpss->cell,
                          1, info->mem, info->irq, NULL);
    if (ret)
        goto err_remove_ltr;
    ...
err_remove_ltr:
    intel_lpss_debugfs_remove(lpss);
    intel_lpss_ltr_hide(lpss);
    intel_lpss_unregister_clock(lpss);
}

The err_remove_ltr path unwinds resources but misses a call to mfd_remove_devices(dev). The previously added IDMA device is left registered while the parent device's devres frees the memory associated with the parent (including the intel_lpss struct).

Could this leave dangling IDMA child devices that maintain references to freed memory, leading to a use-after-free?

[ ... ]

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