Skip to contentSkip to conversation

ref_tracker: use %ld format specifier for PTR_ERR() during directory creation failure

PATCH In review Qasim Ijaz 2 participants 4 messages Apr 12, 2025 – Apr 14, 2025 Library code

lore
Share & tools
lore

Qasim Ijaz

author
#0 lore raw

PATCH 1/1 ref_tracker: use %ld format specifier for PTR_ERR() during directory creation failure

PTR_ERR yields type long, so use %ld format specifier in pr_warn.

Fixes ada5a12aae58 ("ref_tracker: add a top level debugfs directory for ref_tracker")
---
 lib/ref_tracker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ref_tracker.c +1 -1
index 4064154252a6..02e9f0c3dd82 100644
@@ -283,7 +283,7 @@ static int __init ref_tracker_debug_init(void)
 {
 	ref_tracker_debug_dir = debugfs_create_dir("ref_tracker", NULL);
 	if (IS_ERR(ref_tracker_debug_dir)) {
-		pr_warn("ref_tracker: unable to create ref_tracker debugfs directory: %d\n",
+		pr_warn("ref_tracker: unable to create ref_tracker debugfs directory: %ld\n",
 			PTR_ERR(ref_tracker_debug_dir));
 		ref_tracker_debug_dir = NULL;
 	}
Signature · 1 line
2.39.5
#1 lore raw

Hi Qasim,

Quoted 15 lines · Qasim Ijaz

PTR_ERR yields type long, so use %ld format specifier in pr_warn.

Fixes ada5a12aae58 ("ref_tracker: add a top level debugfs directory for ref_tracker")
---
 lib/ref_tracker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
lib/ref_tracker.c +0 -0
index 4064154252a6..02e9f0c3dd82 100644

lib/ref_tracker.c static int __init ref_tracker_debug_init(void) · line 286

Quoted 5 lines
lib/ref_tracker.c +1 -1
@@ -283,7 +283,7 @@ static int __init ref_tracker_debug_init(void)
 {
 	ref_tracker_debug_dir = debugfs_create_dir("ref_tracker", NULL);
 	if (IS_ERR(ref_tracker_debug_dir)) {
-		pr_warn("ref_tracker: unable to create ref_tracker debugfs directory: %d\n",
+		pr_warn("ref_tracker: unable to create ref_tracker debugfs directory: %ld\n",

While there is nothing wrong with doing this to resolve the warning, I think this would be a good opportunity to use the '%pe' format specifier
[1] instead of '%ld', as that will print the symbolic error name (such as -EINVAL instead of just -22) and make it easier for people to decipher what has gone wrong.

pr_warn("ref_tracker: unable to create ref_tracker debugfs directory: %pe\n",

          ref_tracker_debug_dir);

[1]: From the "error pointers" section in Documentation/core-api/printk-formats.rst

Cheers,
Nathan

Quoted 7 lines
lib/ref_tracker.c +0 -0
 			PTR_ERR(ref_tracker_debug_dir));
 		ref_tracker_debug_dir = NULL;
 	}
Signature · 1 line
2.39.5
author
#2 lore raw
Quoted 13 lines · Nathan Chancellor

Hi Qasim,

Quoted 10 lines · Qasim Ijaz

PTR_ERR yields type long, so use %ld format specifier in pr_warn.

Fixes ada5a12aae58 ("ref_tracker: add a top level debugfs directory for ref_tracker")
---
 lib/ref_tracker.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 17 lines

lib/ref_tracker.c static int __init ref_tracker_debug_init(void) · line 286

Quoted 10 lines
lib/ref_tracker.c +1 -1
index 4064154252a6..02e9f0c3dd82 100644
@@ -283,7 +283,7 @@ static int __init ref_tracker_debug_init(void)
 {
 	ref_tracker_debug_dir = debugfs_create_dir("ref_tracker", NULL);
 	if (IS_ERR(ref_tracker_debug_dir)) {
-		pr_warn("ref_tracker: unable to create ref_tracker debugfs directory: %d\n",
+		pr_warn("ref_tracker: unable to create ref_tracker debugfs directory: %ld\n",

While there is nothing wrong with doing this to resolve the warning, I think this would be a good opportunity to use the '%pe' format specifier
[1] instead of '%ld', as that will print the symbolic error name (such as -EINVAL instead of just -22) and make it easier for people to decipher what has gone wrong.

Hi Nathan,

Thanks for the suggestion, I think this would be an improvement over using %ld.

Would you like me to include you in a suggested-by tag in patch v2?

Regards,
Qasim

Quoted 15 lines

pr_warn("ref_tracker: unable to create ref_tracker debugfs directory: %pe\n",

          ref_tracker_debug_dir);

[1]: From the "error pointers" section in Documentation/core-api/printk-formats.rst

Cheers,
Nathan

Quoted 7 lines
lib/ref_tracker.c +0 -0
 			PTR_ERR(ref_tracker_debug_dir));
 		ref_tracker_debug_dir = NULL;
 	}
Signature · 1 line
2.39.5
#3 lore raw
Quoted 6 lines · Qasim Ijaz

Hi Nathan,

Thanks for the suggestion, I think this would be an improvement over using %ld.

Would you like me to include you in a suggested-by tag in patch v2?

No, I do not need a Suggested-by tag, feel free to send v2 without it.

Cheers,
Nathan