Skip to contentSkip to conversation

net: use %ld format specifier for PTR_ERR in pr_warn

PATCH In review Qasim Ijaz 4 participants 5 messages Apr 12, 2025 – Apr 13, 2025

Subsystems (2)
lore
Share & tools
lore

Qasim Ijaz

author
#0 lore raw

PATCH 1/1 net: use %ld format specifier for PTR_ERR in pr_warn

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

Fixes 193510c95215 ("net: add debugfs files for showing netns refcount tracking info")
---
 net/core/net_namespace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/net_namespace.c +1 -1
index f47b9f10af24..a419a3aa57a6 100644
@@ -1652,7 +1652,7 @@ static int __init ns_debug_init(void)
 	if (ref_tracker_debug_dir) {
 		ns_ref_tracker_dir = debugfs_create_dir("net_ns", ref_tracker_debug_dir);
 		if (IS_ERR(ns_ref_tracker_dir)) {
-			pr_warn("net: unable to create ref_tracker/net_ns directory: %d\n",
+			pr_warn("net: unable to create ref_tracker/net_ns directory: %ld\n",
 				PTR_ERR(ns_ref_tracker_dir));
 			goto out;
 		}
Signature · 1 line
2.39.5
#1 lore raw

From: Qasim Ijaz <[email protected]>
Date: Sat, 12 Apr 2025 23:55:28 +0100

Quoted 1 line

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

errno fits in the range of int, so no need to use %ld.

Quoted 2 lines
Fixes 193510c95215 ("net: add debugfs files for showing netns refcount tracking info")

The series is not yet applied. It's not necessary this time, but in such a case, please reply to the original patch thread.

Also, please make sure your patch can be applied cleanly on the latest remote net-next.git and the Fixes tag points to an existing commit.

Quoted 20 lines
---
 net/core/net_namespace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/net_namespace.c +1 -1
index f47b9f10af24..a419a3aa57a6 100644
@@ -1652,7 +1652,7 @@ static int __init ns_debug_init(void)
 	if (ref_tracker_debug_dir) {
 		ns_ref_tracker_dir = debugfs_create_dir("net_ns", ref_tracker_debug_dir);
 		if (IS_ERR(ns_ref_tracker_dir)) {
-			pr_warn("net: unable to create ref_tracker/net_ns directory: %d\n",
+			pr_warn("net: unable to create ref_tracker/net_ns directory: %ld\n",
 				PTR_ERR(ns_ref_tracker_dir));
 			goto out;
 		}
Signature · 1 line
2.39.5
#2 lore raw
Quoted 5 lines · Kuniyuki Iwashima

From: Qasim Ijaz <[email protected]>
Date: Sat, 12 Apr 2025 23:55:28 +0100

Quoted 1 line

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

errno fits in the range of int, so no need to use %ld.

Sure but the compiler does not know that and will warn about the format specifier and type mismatch:

https://lore.kernel.org/[email protected]/

I think my comment about switching to '%pe' on basically the same patch in lib/ref_tracker.c is relevant here too:

https://lore.kernel.org/20250413013245.GA2989337@ax162/

Cheers,
Nathan

author
#3 lore raw
In reply to Kuniyuki Iwashima
Quoted 8 lines · Kuniyuki Iwashima

From: Qasim Ijaz <[email protected]>
Date: Sat, 12 Apr 2025 23:55:28 +0100

Quoted 1 line

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

errno fits in the range of int, so no need to use %ld.

Quoted 1 line
Quoted 8 lines
Quoted 1 line
Fixes 193510c95215 ("net: add debugfs files for showing netns refcount tracking info")

The series is not yet applied. It's not necessary this time, but in such a case, please reply to the original patch thread.

Also, please make sure your patch can be applied cleanly on the latest remote net-next.git and the Fixes tag points to an existing commit.

Hi Kuniyuki

Thank you for your comments, as Nathan said the current code emits a compiler warning as per the kernel test robot.

Given this would you like me to resend patch v2 with the changes you and Nathan specified?

Regards,
Qasim

Quoted 21 lines
Quoted 21 lines
---
 net/core/net_namespace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/net_namespace.c +1 -1
index f47b9f10af24..a419a3aa57a6 100644
@@ -1652,7 +1652,7 @@ static int __init ns_debug_init(void)
 	if (ref_tracker_debug_dir) {
 		ns_ref_tracker_dir = debugfs_create_dir("net_ns", ref_tracker_debug_dir);
 		if (IS_ERR(ns_ref_tracker_dir)) {
-			pr_warn("net: unable to create ref_tracker/net_ns directory: %d\n",
+			pr_warn("net: unable to create ref_tracker/net_ns directory: %ld\n",
 				PTR_ERR(ns_ref_tracker_dir));
 			goto out;
 		}
Signature · 1 line
2.39.5
#4 lore raw
In reply to Qasim Ijaz
Quoted 13 lines · Qasim Ijaz

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

Fixes 193510c95215 ("net: add debugfs files for showing netns refcount tracking info")
---
 net/core/net_namespace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/net_namespace.c +0 -0
index f47b9f10af24..a419a3aa57a6 100644

net/core/net_namespace.c static int __init ns_debug_init(void) · line 1658

Quoted 8 lines
net/core/net_namespace.c +1 -1
@@ -1652,7 +1652,7 @@ static int __init ns_debug_init(void)
 	if (ref_tracker_debug_dir) {
 		ns_ref_tracker_dir = debugfs_create_dir("net_ns", ref_tracker_debug_dir);
 		if (IS_ERR(ns_ref_tracker_dir)) {
-			pr_warn("net: unable to create ref_tracker/net_ns directory: %d\n",
+			pr_warn("net: unable to create ref_tracker/net_ns directory: %ld\n",
 				PTR_ERR(ns_ref_tracker_dir));
 			goto out;
 		}

Thanks, that will silence a potential compiler warning. This is not merged yet, but I'll make sure to incorporate this change in the next version.

FWIW, I'm planning to put together a v3 that will require less involvement with net/ code, so most of these bits will probably get deleted anyway.

Cheers!

Signature · 1 line
Jeff Layton <[email protected]>