Skip to contentSkip to conversation

mfd: intel-lpss: Fix DebugFS initialization

PATCH Superseded Maria Lisina 4 participants 5 messages Sep 13 – Sep 15

Subsystems (2)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 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_init() and intel_lpss_debugfs_add() functions and removes warning message.

---
Changes in v3:
- Fixed commit name and description.
- Link to v2: https://lore.kernel.org/r/[email protected]

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 1 potential issue(s) to consider:

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

Pre-existing issues:
- [High] Missing unwinding of successfully registered MFD child devices on probe failure. --

commit c27fe2681171dc4bc688bb38beb6968be3f1b34d
Author: Maria Lisina <[email protected]>

mfd: intel-lpss: Fix DebugFS initialization

This commit updates intel_lpss_init() and intel_lpss_debugfs_add() to gracefully handle the case where DebugFS is disabled. This prevents the driver from spamming the kernel log with unnecessary warning messages during probe.

Quoted 4 lines
drivers/mfd/intel-lpss.c +0 -0
index 63d6694f71457..c2cb58c0f98a9 100644

[ ... ]

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 looking at the rest of intel_lpss_probe(), is it possible that we are missing a call to unregister the iDMA child device if the main cell registration fails?

If the first mfd_add_devices() call for the iDMA cell succeeds, but the second mfd_add_devices() call for the main cell fails, the code jumps to the err_remove_ltr error path:

	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);

Since err_remove_ltr does not call mfd_remove_devices(dev), does this leave the successfully registered iDMA device active while its parent structures are freed, potentially leading to a use-after-free?

Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
#2 lore raw
In reply to Maria Lisina

On Sun, Sep 13, 2026 at 05:53:53PM +0500, Maria Lisina via B4 Relay wrote:

This is a fair report and patch, but three versions over a night?! Please, slow down! Even with this kind of patch you have to wait at least 24h between versions.

Quoted 9 lines

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

One message is enough as an example.

Quoted 2 lines

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

...

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

Quoted 4 lines
drivers/mfd/intel-lpss.c +1 -3
-	ret = intel_lpss_debugfs_add(lpss);
-	if (ret)
-		dev_warn(dev, "Failed to create debugfs entries\n");
+	intel_lpss_debugfs_add(lpss);

Obviously this message is added here deliberately. If you are annoyed by it, we may consider dropping the level.

...

drivers/mfd/intel-lpss.c EXPORT_NS_GPL_DEV_PM_OPS(intel_lpss_pm_ops, INTEL_LPSS) = { · line 545

Quoted 3 lines
drivers/mfd/intel-lpss.c +3 -0
+	/* Ensure intel_lpss_debugfs stays NULL on error,
+	 * so intel_lpss_debugfs_add() exits properly.
+	 */

/*
* Wrong comment style for multi-line
* comments.
*/

...

TL;DR: moving from warn to info or debug level would be a good compromise.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#3 lore raw
In reply to Maria Lisina
Quoted 60 lines · On Sun, 13 Sep 2026, Maria Lisina via B4 Relay wrote:

From: Maria Lisina <[email protected]>

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_init() and intel_lpss_debugfs_add() functions and removes warning message.

---
Changes in v3:
- Fixed commit name and description.
- Link to v2: https://lore.kernel.org/r/[email protected]

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 +6 -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,

drivers/mfd/intel-lpss.c EXPORT_NS_GPL_DEV_PM_OPS(intel_lpss_pm_ops, INTEL_LPSS) = { · line 541

Quoted 3 lines
drivers/mfd/intel-lpss.c +0 -0
@@ -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);

Why not move this and everything else debugfs related to intel_lpss_debugfs_add()? Then we can get rid of the awful global variable, have everything nicely compartmentalised and ensure that we handle each fault gracefully?

Quoted 20 lines
drivers/mfd/intel-lpss.c +7 -1
+
+	/* 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]>
Signature · 1 line
Lee Jones
#4 lore raw
Quoted 1 line · Lee Jones

On Sun, 13 Sep 2026, Maria Lisina via B4 Relay wrote:

...

Quoted 8 lines
Quoted 3 lines

static int __init intel_lpss_init(void)
{
intel_lpss_debugfs = debugfs_create_dir("intel_lpss", NULL);

Why not move this and everything else debugfs related to intel_lpss_debugfs_add()? Then we can get rid of the awful global variable, have everything nicely compartmentalised and ensure that we handle each fault gracefully?

This creates a directory under the root of the debugfs, so if you want to have that not at the driver level, but at the device, it must be a singleton op. We may achieve this by doing DO_ONCE_SLEEPABLE() from once.h.

Also note, this won't give us the possibility to kill the global variable, as that one is per-driver, not per-device.

Quoted 9 lines

drivers/mfd/intel-lpss.c EXPORT_NS_GPL_DEV_PM_OPS(intel_lpss_pm_ops, INTEL_LPSS) = { · line 551

Quoted 9 lines
drivers/mfd/intel-lpss.c +6 -0
+	/* 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);

In any case it's orthogonal to the purpose of this patch AFAICS. If you still think we definitely need to use probe (which I think doesn't buy us anything but troubles with singleton), I can do it later on.

Signature · 2 lines
With Best Regards,
Andy Shevchenko