Skip to contentSkip to conversation

net: rxrpc: fix clang -Wformat warning

PATCH In review Justin Stitt 5 participants 9 messages Jul 6, 2022 – Jul 9, 2022

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: rxrpc: fix clang -Wformat warning

When building with Clang we encounter this warning:

| net/rxrpc/rxkad.c:434:33: error: format specifies type 'unsigned short'
| but the argument has type 'u32' (aka 'unsigned int') [-Werror,-Wformat]
| _leave(" = %d [set %hx]", ret, y);

y is a u32 but the format specifier is %hx. Going from unsigned int to short int results in a loss of data. This is surely not intended behavior. If it is intended, the warning should be suppressed through other means.

This patch should get us closer to the goal of enabling the -Wformat flag for Clang builds.

---
 net/rxrpc/rxkad.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/rxkad.c +1 -1
index 08aab5c01437..aa180464ec37 100644
@@ -431,7 +431,7 @@ static int rxkad_secure_packet(struct rxrpc_call *call,
 		break;
 	}
 
-	_leave(" = %d [set %hx]", ret, y);
+	_leave(" = %d [set %u]", ret, y);
 	return ret;
 }
 
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
#1 lore raw

Hi Justin,

Quoted 24 lines · Justin Stitt

When building with Clang we encounter this warning:

| net/rxrpc/rxkad.c:434:33: error: format specifies type 'unsigned short'
| but the argument has type 'u32' (aka 'unsigned int') [-Werror,-Wformat]
| _leave(" = %d [set %hx]", ret, y);

y is a u32 but the format specifier is %hx. Going from unsigned int to short int results in a loss of data. This is surely not intended behavior. If it is intended, the warning should be suppressed through other means.

This patch should get us closer to the goal of enabling the -Wformat flag for Clang builds.

---
 net/rxrpc/rxkad.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/rxkad.c +0 -0
index 08aab5c01437..aa180464ec37 100644

net/rxrpc/rxkad.c static int rxkad_secure_packet(struct rxrpc_call *call, · line 434

Quoted 5 lines
net/rxrpc/rxkad.c +1 -1
@@ -431,7 +431,7 @@ static int rxkad_secure_packet(struct rxrpc_call *call,
 		break;
 	}
 
-	_leave(" = %d [set %hx]", ret, y);
+	_leave(" = %d [set %u]", ret, y);

Should this just become %x to keep printing it as a hexidecimal number?

Cheers,
Nathan

Quoted 6 lines
net/rxrpc/rxkad.c +0 -0
 	return ret;
 }
 
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
#2 lore raw

PATCH v2 1/1 net: rxrpc: fix clang -Wformat warning

In reply to Justin Stitt

When building with Clang we encounter this warning:

| net/rxrpc/rxkad.c:434:33: error: format specifies type 'unsigned short'
| but the argument has type 'u32' (aka 'unsigned int') [-Werror,-Wformat]
| _leave(" = %d [set %hx]", ret, y);

y is a u32 but the format specifier is %hx. Going from unsigned int to short int results in a loss of data. This is surely not intended behavior. If it is intended, the warning should be suppressed through other means.

This patch should get us closer to the goal of enabling the -Wformat flag for Clang builds.

---
diff from v1 -> v2:
* Change format specifier from %u to %x to properly represent hexadecimal.

 net/rxrpc/rxkad.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/rxkad.c +1 -1
index 08aab5c01437..258917a714c8 100644
@@ -431,7 +431,7 @@ static int rxkad_secure_packet(struct rxrpc_call *call,
 		break;
 	}
 
-	_leave(" = %d [set %hx]", ret, y);
+	_leave(" = %d [set %x]", ret, y);
 	return ret;
 }
 
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
Reviewed-by on v2 1/1
#3 lore raw
Quoted 10 lines · Justin Stitt

When building with Clang we encounter this warning:

| net/rxrpc/rxkad.c:434:33: error: format specifies type 'unsigned short'
| but the argument has type 'u32' (aka 'unsigned int') [-Werror,-Wformat]
| _leave(" = %d [set %hx]", ret, y);

y is a u32 but the format specifier is %hx. Going from unsigned int to short int results in a loss of data. This is surely not intended behavior. If it is intended, the warning should be suppressed through other means.

Quoted 5 lines

This patch should get us closer to the goal of enabling the -Wformat flag for Clang builds.

Quoted 23 lines

---
diff from v1 -> v2:
* Change format specifier from %u to %x to properly represent hexadecimal.

 net/rxrpc/rxkad.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/rxrpc/rxkad.c +1 -1
index 08aab5c01437..258917a714c8 100644
@@ -431,7 +431,7 @@ static int rxkad_secure_packet(struct rxrpc_call *call,
 		break;
 	}
 
-	_leave(" = %d [set %hx]", ret, y);
+	_leave(" = %d [set %x]", ret, y);
 	return ret;
 }
 
Signature · 1 line
2.37.0.rc0.161.g10f37bed90-goog
maintainer Acked-by on v2 1/1
#4 lore raw
In reply to Justin Stitt
Quoted 4 lines · Justin Stitt

y is a u32 but the format specifier is %hx. Going from unsigned int to short int results in a loss of data. This is surely not intended behavior. If it is intended, the warning should be suppressed through other means.

Yeah, y is reduced to a 16-bit number so that it can be used in the protocol, but the type is still 32-bit because that's needed for the calculation. An alternative would be to print sp->hdr.cksum since that's the value that will appear on the wire, but I've no objection to this change either.

Quoted 5 lines

This patch should get us closer to the goal of enabling the -Wformat flag for Clang builds.

#5 lore raw
In reply to Justin Stitt
This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Hello:

This patch was applied to netdev/net-next.git (master) by Jakub Kicinski <[email protected]>:

Quoted 11 lines · On Thu, 7 Jul 2022 11:20:52 -0700 you wrote:

When building with Clang we encounter this warning:

| net/rxrpc/rxkad.c:434:33: error: format specifies type 'unsigned short'
| but the argument has type 'u32' (aka 'unsigned int') [-Werror,-Wformat]
| _leave(" = %d [set %hx]", ret, y);

y is a u32 but the format specifier is %hx. Going from unsigned int to short int results in a loss of data. This is surely not intended behavior. If it is intended, the warning should be suppressed through other means.

[...]

Here is the summary with links:
- [v2] net: rxrpc: fix clang -Wformat warning

    https://git.kernel.org/netdev/net-next/c/5b47d2364652

You are awesome, thank you!

Signature · 2 lines
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
#6 lore raw
In reply to Justin Stitt
Quoted 4 lines · Justin Stitt

When building with Clang we encounter this warning:

Quoted 3 lines

net/rxrpc/rxkad.c:434:33: error: format specifies type 'unsigned short' but the argument has type 'u32' (aka 'unsigned int') [-Werror,-Wformat] _leave(" = %d [set %hx]", ret, y);

Does anyone still use these debugging macros in rxrpc or is it historic cruft?

net/rxrpc/ar-internal.h-#define kenter(FMT,...) dbgprintk("==> %s("FMT")",__func__ ,##__VA_ARGS__) net/rxrpc/ar-internal.h-#define kleave(FMT,...) dbgprintk("<== %s()"FMT"",__func__ ,##__VA_ARGS__)
net/rxrpc/ar-internal.h-#define kdebug(FMT,...) dbgprintk(" "FMT ,##__VA_ARGS__)
net/rxrpc/ar-internal.h-#define kproto(FMT,...) dbgprintk("### "FMT ,##__VA_ARGS__)
net/rxrpc/ar-internal.h-#define knet(FMT,...) dbgprintk("@@@ "FMT ,##__VA_ARGS__)

etc...

[]

net/rxrpc/Kconfig:config AF_RXRPC_DEBUG
net/rxrpc/Kconfig- bool "RxRPC dynamic debugging"
net/rxrpc/Kconfig- help
net/rxrpc/Kconfig- Say Y here to make runtime controllable debugging messages appear.
net/rxrpc/Kconfig-
net/rxrpc/Kconfig- See Documentation/networking/rxrpc.rst

This seems to show there is debugging documentation, but it doesn't seem to exist in this file.

net/rxrpc/rxkad.c

Quoted 1 line
net/rxrpc/rxkad.c +0 -0

[]

Quoted 9 lines
net/rxrpc/rxkad.c +1 -1
@@ -431,7 +431,7 @@ static int rxkad_secure_packet(struct rxrpc_call *call,
 		break;
 	}
 
-	_leave(" = %d [set %hx]", ret, y);
+	_leave(" = %d [set %u]", ret, y);
 	return ret;
 }
 
maintainer
#7 lore raw
Quoted 1 line · Joe Perches

Does anyone still use these debugging macros in rxrpc

Yes.

David

maintainer
#8 lore raw
In reply to Joe Perches
Quoted 9 lines · Joe Perches

net/rxrpc/Kconfig:config AF_RXRPC_DEBUG
net/rxrpc/Kconfig- bool "RxRPC dynamic debugging"
net/rxrpc/Kconfig- help
net/rxrpc/Kconfig- Say Y here to make runtime controllable debugging messages appear.
net/rxrpc/Kconfig-
net/rxrpc/Kconfig- See Documentation/networking/rxrpc.rst

This seems to show there is debugging documentation, but it doesn't seem to exist in this file.

Try looking in net/rxrpc/ar-internal.h:

#elif defined(CONFIG_AF_RXRPC_DEBUG)

David