Skip to contentSkip to conversation

mfd: intel-lpss: Clean up and modernize DebugFS usage

PATCH Superseded Maria Lisina 4 participants 8 messages Sep 15 – Sep 16

Subsystems (2)

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 mfd: intel-lpss: Clean up and modernize DebugFS usage

The DebugFS API is designed to handle errors gracefully. Any explicit checking on return values is considered an anti-pattern.

This patch removes unnecessary error checking and converts intel_lpss_debugfs_add() into a void function.

While at it, this patch also clean ups legacy and deprecated usage of S_IRUGO macro and debugfs_remove_recursive() function.

---
Changes in v5:
- Changed the goal of the patch to DebugFS modernization.
- Refactored intel_lpss_debugfs_add() into a void function.
- Removed deprecated macros and functions.
- Removed dmesg message completely.
- Link to v4: https://lore.kernel.org/r/[email protected]

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 | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)
drivers/mfd/intel-lpss.c +11 -17
index 63d6694f71457b2e09d238af0a9bfb897a169a64..1a61ef1a62b3e8a2777f357d5c4605d5d57d9532 100644
@@ -142,28 +142,25 @@ static void intel_lpss_cache_ltr(struct intel_lpss *lpss)
 	lpss->idle_ltr = readl(lpss->priv + LPSS_PRIV_IDLELTR);
 }
 
-static int intel_lpss_debugfs_add(struct intel_lpss *lpss)
+static void intel_lpss_debugfs_add(struct intel_lpss *lpss)
 {
-	struct dentry *dir;
-
-	dir = debugfs_create_dir(dev_name(lpss->dev), intel_lpss_debugfs);
-	if (IS_ERR(dir))
-		return PTR_ERR(dir);
+	lpss->debugfs =
+		debugfs_create_dir(dev_name(lpss->dev), intel_lpss_debugfs);
 
 	/* Cache the values into lpss structure */
 	intel_lpss_cache_ltr(lpss);
 
-	debugfs_create_x32("capabilities", S_IRUGO, dir, &lpss->caps);
-	debugfs_create_x32("active_ltr", S_IRUGO, dir, &lpss->active_ltr);
-	debugfs_create_x32("idle_ltr", S_IRUGO, dir, &lpss->idle_ltr);
-
-	lpss->debugfs = dir;
-	return 0;
+	debugfs_create_x32("capabilities", 0444, lpss->debugfs,
+					   &lpss->caps);
+	debugfs_create_x32("active_ltr", 0444, lpss->debugfs,
+					   &lpss->active_ltr);
+	debugfs_create_x32("idle_ltr", 0444, lpss->debugfs,
+					   &lpss->idle_ltr);
 }
 
 static void intel_lpss_debugfs_remove(struct intel_lpss *lpss)
 {
-	debugfs_remove_recursive(lpss->debugfs);
+	debugfs_remove(lpss->debugfs);
 }
 
 static void intel_lpss_ltr_set(struct device *dev, s32 val)
@@ -432,10 +429,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,

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

Best regards,

Signature · 1 line
Maria Lisina <[email protected]>
#1 lore raw
Sashiko has reviewed this patch and found no issues. It looks great!
Quoted 10 lines

The DebugFS API is designed to handle errors gracefully. Any explicit checking on return values is considered an anti-pattern.

This patch removes unnecessary error checking and converts intel_lpss_debugfs_add() into a void function.

While at it, this patch also clean ups legacy and deprecated usage of S_IRUGO macro and debugfs_remove_recursive() function.

Sashiko has reviewed this patch and found no issues. It looks great!

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

On Wed, Sep 16, 2026 at 03:13:35AM +0500, Maria Lisina wrote:

Thank you for the update, my comments below.

Quoted 5 lines

The DebugFS API is designed to handle errors gracefully. Any explicit checking on return values is considered an anti-pattern.

This patch removes unnecessary error checking and converts intel_lpss_debugfs_add() into a void function.

Yep, these two paragraphs are good!

Quoted 2 lines

While at it, this patch also clean ups legacy and deprecated usage of S_IRUGO macro and debugfs_remove_recursive() function.

No, this should be a separate patch.

...

drivers/mfd/intel-lpss.c static void intel_lpss_cache_ltr(struct intel_lpss *lpss)

Quoted 12 lines
drivers/mfd/intel-lpss.c +3 -5
-static int intel_lpss_debugfs_add(struct intel_lpss *lpss)
+static void intel_lpss_debugfs_add(struct intel_lpss *lpss)
 {
 
-	struct dentry *dir;
-
-	dir = debugfs_create_dir(dev_name(lpss->dev), intel_lpss_debugfs);
 
+	lpss->debugfs =
+		debugfs_create_dir(dev_name(lpss->dev), intel_lpss_debugfs);
 
-	lpss->debugfs = dir;

This is unneeded churn. Yes, I understand that dir won't be used, but if you really want to refactor do it in a separate change.

Quoted 1 line

}

...

drivers/mfd/intel-lpss.c static void intel_lpss_cache_ltr(struct intel_lpss *lpss) · line 163

Quoted 4 lines

static void intel_lpss_debugfs_remove(struct intel_lpss *lpss) {

drivers/mfd/intel-lpss.c +1 -1
-	debugfs_remove_recursive(lpss->debugfs);
+	debugfs_remove(lpss->debugfs);

Hmm... Why?

Quoted 1 line

}

...

So, if you really want a refactoring, split this to up to three patches:
1) drop debugfs checks along with the warn message (as your initial goal);
2) replace macros by plain octal values for the permissions (optional);
3) assign debugfs directory directly (optional).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 16 lines · Andy Shevchenko

On Wed, Sep 16, 2026 at 03:13:35AM +0500, Maria Lisina wrote:

Thank you for the update, my comments below.

Quoted 5 lines

The DebugFS API is designed to handle errors gracefully. Any explicit checking on return values is considered an anti-pattern.

This patch removes unnecessary error checking and converts intel_lpss_debugfs_add() into a void function.

Yep, these two paragraphs are good!

Quoted 2 lines

While at it, this patch also clean ups legacy and deprecated usage of S_IRUGO macro and debugfs_remove_recursive() function.

No, this should be a separate patch.

...

Quoted 17 lines

drivers/mfd/intel-lpss.c static void intel_lpss_cache_ltr(struct intel_lpss *lpss)

Quoted 12 lines
drivers/mfd/intel-lpss.c +3 -5
-static int intel_lpss_debugfs_add(struct intel_lpss *lpss)
+static void intel_lpss_debugfs_add(struct intel_lpss *lpss)
 {
 
-	struct dentry *dir;
-
-	dir = debugfs_create_dir(dev_name(lpss->dev), intel_lpss_debugfs);
 
+	lpss->debugfs =
+		debugfs_create_dir(dev_name(lpss->dev), intel_lpss_debugfs);
 
-	lpss->debugfs = dir;

This is unneeded churn. Yes, I understand that dir won't be used, but if you really want to refactor do it in a separate change.

Quoted 1 line

}

...

Quoted 6 lines

drivers/mfd/intel-lpss.c static void intel_lpss_cache_ltr(struct intel_lpss *lpss) · line 163

Quoted 4 lines

static void intel_lpss_debugfs_remove(struct intel_lpss *lpss) {

drivers/mfd/intel-lpss.c +1 -1
-	debugfs_remove_recursive(lpss->debugfs);
+	debugfs_remove(lpss->debugfs);

Hmm... Why?

Answering this will give you...

Quoted 1 line
Quoted 1 line

}

...

Quoted 4 lines

So, if you really want a refactoring, split this to up to three patches:
1) drop debugfs checks along with the warn message (as your initial goal);
2) replace macros by plain octal values for the permissions (optional);
3) assign debugfs directory directly (optional).

4) replace debugfs_remove_recursive() with debugfs_remove() (optional).

Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#4 lore raw
In reply to Maria Lisina
Quoted 41 lines · Maria Lisina

The DebugFS API is designed to handle errors gracefully. Any explicit checking on return values is considered an anti-pattern.

This patch removes unnecessary error checking and converts intel_lpss_debugfs_add() into a void function.

While at it, this patch also clean ups legacy and deprecated usage of S_IRUGO macro and debugfs_remove_recursive() function.

---
Changes in v5:
- Changed the goal of the patch to DebugFS modernization.
- Refactored intel_lpss_debugfs_add() into a void function.
- Removed deprecated macros and functions.
- Removed dmesg message completely.
- Link to v4: https://lore.kernel.org/r/[email protected]

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 | 28 +++++++++++-----------------
 1 file changed, 11 insertions(+), 17 deletions(-)
drivers/mfd/intel-lpss.c +0 -0
index 63d6694f71457b2e09d238af0a9bfb897a169a64..1a61ef1a62b3e8a2777f357d5c4605d5d57d9532 100644
@@ -142,28 +142,25 @@ static void intel_lpss_cache_ltr(struct intel_lpss *lpss)
 	lpss->idle_ltr = readl(lpss->priv + LPSS_PRIV_IDLELTR);
 }
 

drivers/mfd/intel-lpss.c static void intel_lpss_cache_ltr(struct intel_lpss *lpss) · line 148

Quoted 10 lines
drivers/mfd/intel-lpss.c +3 -6
-static int intel_lpss_debugfs_add(struct intel_lpss *lpss)
+static void intel_lpss_debugfs_add(struct intel_lpss *lpss)
 {
-	struct dentry *dir;
-
-	dir = debugfs_create_dir(dev_name(lpss->dev), intel_lpss_debugfs);
-	if (IS_ERR(dir))
-		return PTR_ERR(dir);
+	lpss->debugfs =
+		debugfs_create_dir(dev_name(lpss->dev), intel_lpss_debugfs);

No need to line-wrap for this. Use up to 100-chars to prevent this craziness.

Why continue if this returns an error?

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

Quoted 11 lines
drivers/mfd/intel-lpss.c +1 -6
 	/* Cache the values into lpss structure */
 	intel_lpss_cache_ltr(lpss);
 
-	debugfs_create_x32("capabilities", S_IRUGO, dir, &lpss->caps);
-	debugfs_create_x32("active_ltr", S_IRUGO, dir, &lpss->active_ltr);
-	debugfs_create_x32("idle_ltr", S_IRUGO, dir, &lpss->idle_ltr);
-
-	lpss->debugfs = dir;
-	return 0;
+	debugfs_create_x32("capabilities", 0444, lpss->debugfs,

Does this accept a NULL pointer or an error in parameter 3?

drivers/mfd/intel-lpss.c static void intel_lpss_cache_ltr(struct intel_lpss *lpss) · line 154

Quoted 1 line
drivers/mfd/intel-lpss.c +1 -0
+					   &lpss->caps);

You should always align to the '(' but in this case, don't wrap at all.

drivers/mfd/intel-lpss.c static void intel_lpss_cache_ltr(struct intel_lpss *lpss) · line 163

Quoted 10 lines
drivers/mfd/intel-lpss.c +5 -1
+	debugfs_create_x32("active_ltr", 0444, lpss->debugfs,
+					   &lpss->active_ltr);
+	debugfs_create_x32("idle_ltr", 0444, lpss->debugfs,
+					   &lpss->idle_ltr);
 }
 
 static void intel_lpss_debugfs_remove(struct intel_lpss *lpss)
 {
-	debugfs_remove_recursive(lpss->debugfs);
+	debugfs_remove(lpss->debugfs);

Please explain why this is required?

Quoted 24 lines
drivers/mfd/intel-lpss.c +1 -5
 }
 
 static void intel_lpss_ltr_set(struct device *dev, s32 val)
@@ -432,10 +429,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,
 
---

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

Best regards,

Signature · 1 line
Maria Lisina <[email protected]>
Signature · 1 line
Lee Jones
#5 lore raw
Quoted 10 lines · Lee Jones
Quoted 8 lines · Maria Lisina

The DebugFS API is designed to handle errors gracefully. Any explicit checking on return values is considered an anti-pattern.

This patch removes unnecessary error checking and converts intel_lpss_debugfs_add() into a void function.

While at it, this patch also clean ups legacy and deprecated usage of S_IRUGO macro and debugfs_remove_recursive() function.

...

Quoted 1 line

Why continue if this returns an error?

Because we don't care.

Quoted 3 lines

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

Quoted 1 line
drivers/mfd/intel-lpss.c +1 -0
+	debugfs_create_x32("capabilities", 0444, lpss->debugfs,

Does this accept a NULL pointer or an error in parameter 3?

Yes, debugfs is designed to be used without checks.

Quoted 1 line
Quoted 1 line
drivers/mfd/intel-lpss.c +1 -0
+					   &lpss->caps);
Signature · 2 lines
With Best Regards,
Andy Shevchenko
maintainer
#6 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 8 lines · Lee Jones
Quoted 6 lines · Maria Lisina

The DebugFS API is designed to handle errors gracefully. Any explicit checking on return values is considered an anti-pattern.

This patch removes unnecessary error checking and converts intel_lpss_debugfs_add() into a void function.

Quoted 8 lines
Quoted 2 lines
Quoted 2 lines

While at it, this patch also clean ups legacy and deprecated usage of S_IRUGO macro and debugfs_remove_recursive() function.

...

Quoted 1 line

Why continue if this returns an error?

Because we don't care.

If you engage your Embedded mind, you will reel at the wasted cycles!

Signature · 1 line
Lee Jones
#7 lore raw
Quoted 3 lines · Lee Jones
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Lee Jones

On Wed, 16 Sep 2026, Maria Lisina wrote:

...

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

Why continue if this returns an error?

Because we don't care.

If you engage your Embedded mind, you will reel at the wasted cycles!

True, but it not the hot path. Anyway, Greg KH is keen to see debugfs properly used, id est without checking. I am fine with that.

Signature · 2 lines
With Best Regards,
Andy Shevchenko