diff mbox series

net: rxrpc: fix clang -Wformat warning

Message ID 20220706235648.594609-1-justinstitt@google.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net: rxrpc: fix clang -Wformat warning | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 2 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 8 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Justin Stitt July 6, 2022, 11:56 p.m. UTC
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 <justinstitt@google.com>
---
 net/rxrpc/rxkad.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Nathan Chancellor July 7, 2022, 5:58 p.m. UTC | #1
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 <justinstitt@google.com>
> ---
>  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
>
Joe Perches July 7, 2022, 11:10 p.m. UTC | #2
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;
>  }
>
David Howells July 8, 2022, 9:39 a.m. UTC | #3
Joe Perches <joe@perches.com> wrote:

> Does anyone still use these debugging macros in rxrpc

Yes.

David
David Howells July 8, 2022, 9:40 a.m. UTC | #4
Joe Perches <joe@perches.com> 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
diff mbox series

Patch

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;
 }