2022-07-07 00:07:39

by Justin Stitt

[permalink] [raw]
Subject: [PATCH] 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.

Link: https://github.com/ClangBuiltLinux/linux/issues/378
Signed-off-by: Justin Stitt <[email protected]>
---
net/rxrpc/rxkad.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index 08aab5c01437..aa180464ec37 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -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;
}

--
2.37.0.rc0.161.g10f37bed90-goog


2022-07-07 18:21:31

by Nathan Chancellor

[permalink] [raw]
Subject: Re: [PATCH] net: rxrpc: fix clang -Wformat warning

Hi Justin,

On Wed, Jul 06, 2022 at 04:56:48PM -0700, Justin Stitt 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.
>
> This patch should get us closer to the goal of enabling the -Wformat
> flag for Clang builds.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/378
> Signed-off-by: Justin Stitt <[email protected]>
> ---
> net/rxrpc/rxkad.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
> index 08aab5c01437..aa180464ec37 100644
> --- a/net/rxrpc/rxkad.c
> +++ b/net/rxrpc/rxkad.c
> @@ -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

> return ret;
> }
>
> --
> 2.37.0.rc0.161.g10f37bed90-goog
>

2022-07-07 19:03:45

by Justin Stitt

[permalink] [raw]
Subject: [PATCH v2] 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.

Link: https://github.com/ClangBuiltLinux/linux/issues/378
Signed-off-by: Justin Stitt <[email protected]>
---
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(-)

diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index 08aab5c01437..258917a714c8 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -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;
}

--
2.37.0.rc0.161.g10f37bed90-goog

2022-07-07 23:16:37

by Joe Perches

[permalink] [raw]
Subject: Re: [PATCH] net: rxrpc: fix clang -Wformat warning

On Wed, 2022-07-06 at 16:56 -0700, Justin Stitt 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);

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.

> diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
[]
> @@ -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;
> }
>

2022-07-08 10:04:10

by David Howells

[permalink] [raw]
Subject: Re: [PATCH v2] net: rxrpc: fix clang -Wformat warning

Justin Stitt <[email protected]> wrote:

> 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.

> This patch should get us closer to the goal of enabling the -Wformat
> flag for Clang builds.
>
> Link: https://github.com/ClangBuiltLinux/linux/issues/378
> Signed-off-by: Justin Stitt <[email protected]>

Acked-by: David Howells <[email protected]>

2022-07-08 10:04:28

by David Howells

[permalink] [raw]
Subject: Re: [PATCH] net: rxrpc: fix clang -Wformat warning

Joe Perches <[email protected]> wrote:

> 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

2022-07-08 10:05:10

by David Howells

[permalink] [raw]
Subject: Re: [PATCH] net: rxrpc: fix clang -Wformat warning

Joe Perches <[email protected]> wrote:

> Does anyone still use these debugging macros in rxrpc

Yes.

David

2022-07-09 04:22:20

by patchwork-bot+netdevbpf

[permalink] [raw]
Subject: Re: [PATCH v2] net: rxrpc: fix clang -Wformat warning

Hello:

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

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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html