mfd: intel-lpss: Prevent DebugFS messages if it is not initialized
PATCH v4 1/1 mfd: intel-lpss: Prevent DebugFS messages if it is not initialized
The original code expects DebugFS to be always initialized which causes unwanted warnings 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 check to intel_lpss_init() and intel_lpss_debugfs_add() functions to prevent writing to uninitialized DebugFS.
---
Changes in v4:
- Keep the dmesg messages, instead check whether DebugFS is initialized
- Link to v3: https://lore.kernel.org/r/[email protected]
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 | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-)
drivers/mfd/intel-lpss.c +15 -1
@@ -146,6 +146,12 @@ static int intel_lpss_debugfs_add(struct intel_lpss *lpss) {struct dentry *dir; +/* Exit if DebugFS is not initialized */ +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);
@@ -538,7 +544,15 @@ 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 ); +/* +* Check whether DebugFS is initialized to +* prevent unwanted dmesg messages. +*/ +if (debugfs_initialized ()) + intel_lpss_debugfs =debugfs_create_dir ("intel_lpss" ,NULL ); +else + 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]>
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 3 potential issue(s) to consider:
New issues:
- [High] Returning early when DebugFS is disabled skips intel_lpss_cache_ltr(), leaving lpss->active_ltr uninitialized and breaking hardware latency tolerance updates.
- [Medium] The patch uses debugfs_initialized() and conditional NULL assignments to skip debugfs creation, failing to fix the root cause of the warning which is the driver improperly checking debugfs return values.
Pre-existing issues:
- [High] Missing mfd_remove_devices() in the error path of intel_lpss_probe() fails to unregister the successfully added 'idma64' child device, leading to a leaked zombie device and a potential Use-After-Free. --
commit 77999f12a7abfc9e74b87cc4f64a8d0ea8d2571f
Author: Maria Lisina <[email protected]>
mfd: intel-lpss: Prevent DebugFS messages if it is not initialized
The original code expects DebugFS to be always initialized which causes unwanted warnings when DebugFS is simply disabled. This patch adds checks to intel_lpss_init() and intel_lpss_debugfs_add() to prevent writing to uninitialized DebugFS.
Quoted 5 lines
drivers/mfd/intel-lpss.c +0
-0
drivers/mfd/intel-lpss.c static int intel_lpss_debugfs_add(struct intel_lpss *lpss) · line 154
Quoted 9 lines
drivers/mfd/intel-lpss.c +6
-0@@ -146,6 +146,12 @@ static int intel_lpss_debugfs_add(struct intel_lpss *lpss) {struct dentry *dir; +/* Exit if DebugFS is not initialized */ +if (!intel_lpss_debugfs) { + lpss->debugfs =NULL ; +return 0 ; + } +
[Severity: High]
Does this early return completely bypass intel_lpss_cache_ltr() leaving the cached hardware state uninitialized?
If intel_lpss_debugfs is NULL, this function returns early, leaving lpss->active_ltr and lpss->idle_ltr uninitialized (defaulted to 0 by devm_kzalloc).
Later, when intel_lpss_ltr_set() attempts to set the hardware state to 0:
drivers/mfd/intel-lpss.c:intel_lpss_ltr_set() {
...
if (ltr == lpss->active_ltr)
return;
...
}Will this optimization check incorrectly evaluate to true, comparing the target state to the uninitialized 0 value instead of the actual hardware state, and return early without updating the hardware?
Quoted 3 lines
drivers/mfd/intel-lpss.c +0
-0dir =debugfs_create_dir (dev_name (lpss->dev), intel_lpss_debugfs);if (IS_ERR (dir))return PTR_ERR (dir);
[ ... ]
Quoted 4 lines
drivers/mfd/intel-lpss.c +0
-0@@ -538,7 +544,15 @@ EXPORT_NS_GPL_DEV_PM_OPS(intel_lpss_pm_ops, INTEL_LPSS) = {static int __init intel_lpss_init (void ) {
drivers/mfd/intel-lpss.c EXPORT_NS_GPL_DEV_PM_OPS(intel_lpss_pm_ops, INTEL_LPSS) = { · line 555
Quoted 10 lines
drivers/mfd/intel-lpss.c +9
-1- intel_lpss_debugfs =debugfs_create_dir ("intel_lpss" ,NULL ); +/* +* Check whether DebugFS is initialized to +* prevent unwanted dmesg messages. +*/ +if (debugfs_initialized ()) + intel_lpss_debugfs =debugfs_create_dir ("intel_lpss" ,NULL ); +else + intel_lpss_debugfs =NULL ; +
[Severity: Medium]
Is using debugfs_initialized() an anti-pattern here?
If debugfs_create_dir() fails (e.g., with -ENOMEM) when CONFIG_DEBUG_FS is enabled, it returns ERR_PTR(-ENOMEM).
If this happens, intel_lpss_debugfs will contain an error pointer, so the !intel_lpss_debugfs check in intel_lpss_debugfs_add() will evaluate to false. The subsequent debugfs_create_dir() call will then be executed with an invalid parent. This call will fail, and IS_ERR(dir) will still be true, propagating the error and triggering the dev_warn() in the probe path anyway, which defeats the purpose of the patch.
Would it be better to unconditionally call debugfs functions and remove the return value checks entirely, as they gracefully handle the disabled state by returning ERR_PTR(-ENODEV)?
drivers/mfd/intel-lpss.c EXPORT_NS_GPL_DEV_PM_OPS(intel_lpss_pm_ops, INTEL_LPSS) = { · line 558
Quoted 3 lines
drivers/mfd/intel-lpss.c +0
-0return 0 ; }module_init (intel_lpss_init);
[Severity: High]
This is a pre-existing issue, but missing mfd_remove_devices() in the error path of intel_lpss_probe() fails to unregister the successfully added 'idma64' child device.
If mfd_add_devices() successfully registers the 'idma64' child device:
drivers/mfd/intel-lpss.c:intel_lpss_probe() {
...
if (intel_lpss_has_idma(lpss)) {
ret = mfd_add_devices(dev, lpss->devid, &intel_lpss_idma64_cell,
1, info->mem, info->irq, NULL);
...
}
ret = mfd_add_devices(dev, lpss->devid, lpss->cell,
1, info->mem, info->irq, NULL);
if (ret)
goto err_remove_ltr;
...
}And the subsequent mfd_add_devices() call for lpss->cell fails, it jumps to err_remove_ltr:
err_remove_ltr:
intel_lpss_debugfs_remove(lpss); intel_lpss_ltr_hide(lpss); intel_lpss_unregister_clock(lpss);
This error path omits mfd_remove_devices(), leaving the 'idma64' child registered. Since the driver core frees devres allocations (like lpss and its memory mapping) on probe failure, does this lead to a leaked zombie device and a potential Use-After-Free if the orphaned child is probed or accessed?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Andy Shevchenko
reviewerQuoted 9 lines · On Mon, Sep 14, 2026 at 04:21:31PM +0500, Maria Lisina via B4 Relay wrote:
The original code expects DebugFS to be always initialized which causes unwanted warnings 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
In previous review I pointed out that one of such a message is enough, no need to repeat it for each LPSS device in the system.
Quoted 3 lines
This patch adds proper check to
intel_lpss_init()andintel_lpss_debugfs_add()functions to prevent writing to uninitialized DebugFS.
...
Quoted 3 lines
Changes in v4:
- Keep the dmesg messages, instead check whether DebugFS is initialized
- Link to v3: https://lore.kernel.org/r/[email protected]
I mentioned that switching to the debug (or info) level is fine, I'm a bit puzzled what this version is trying to achieve. Strictly speaking the debugfs is designed in the way that no checks are required at all. In this case we want the user be informed about this as debugfs carries the LTR values.
So, I expect to see dev_warn() --> dev_dbg() or dev_info() in one-liner.
Signature · 2 lines
With Best Regards, Andy Shevchenko
I'm sorry, I didn't notice the part about commit description.
Also I don't really get it how is this dmesg message mandatory when DebugFS is completely disabled. It makes no sense to me. If user needs these LTR values for debugging purposes they should know about DebugFS. In other cases when DebugFS is disabled these messages shouldn't even appear as these LTR values stored in DebugFS don't do anything, at least if I remember correctly they aren't used for any purpose other than debugging while being exposed in DebugFS.
Andy Shevchenko
reviewerQuoted 9 lines · Maria Lisina
I'm sorry, I didn't notice the part about commit description.
Also I don't really get it how is this dmesg message mandatory when DebugFS is completely disabled. It makes no sense to me. If user needs these LTR values for debugging purposes they should know about DebugFS. In other cases when DebugFS is disabled these messages shouldn't even appear as these LTR values stored in DebugFS don't do anything, at least if I remember correctly they aren't used for any purpose other than debugging while being exposed in DebugFS.
This is fair point, but the patch does something else.
In lieu of the above you can propose a change that moves the intel_lpss_debugfs_add() function to return void and drop the message completely justifying it as you put it here.
Something like this (but in mangled form)
-static int intel_lpss_debugfs_add(struct intel_lpss *lpss) +static void intel_lpss_debugfs_add(struct intel_lpss *lpss)
- if (IS_ERR(dir))
- return PTR_ERR(dir);
- return 0;
- ret = intel_lpss_debugfs_add(lpss); + intel_lpss_debugfs_add(lpss); - if (ret)
- dev_warn(dev, "Failed to create debugfs entries\n");
Would it work for you?
Signature · 2 lines
With Best Regards, Andy Shevchenko