linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: l2tp: fix clang -Wformat warning
@ 2022-07-06 23:08 Justin Stitt
  2022-07-07  7:50 ` Guillaume Nault
  2022-07-08  1:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Justin Stitt @ 2022-07-06 23:08 UTC (permalink / raw)
  To: James Chapman, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: Nathan Chancellor, Nick Desaulniers, Tom Rix, netdev,
	linux-kernel, llvm, Justin Stitt

When building with clang we encounter this warning:
| net/l2tp/l2tp_ppp.c:1557:6: error: format specifies type 'unsigned
| short' but the argument has type 'u32' (aka 'unsigned int')
| [-Werror,-Wformat] session->nr, session->ns,

Both session->nr and session->ns are of type u32. The format specifier
previously used is `%hu` which would truncate our unsigned integer from
32 to 16 bits. This doesn't seem like intended behavior, if it is then
perhaps we need to consider suppressing the warning with pragma clauses.

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/l2tp/l2tp_ppp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
index 8be1fdc68a0b..db2e584c625e 100644
--- a/net/l2tp/l2tp_ppp.c
+++ b/net/l2tp/l2tp_ppp.c
@@ -1553,7 +1553,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
 		   session->lns_mode ? "LNS" : "LAC",
 		   0,
 		   jiffies_to_msecs(session->reorder_timeout));
-	seq_printf(m, "   %hu/%hu %ld/%ld/%ld %ld/%ld/%ld\n",
+	seq_printf(m, "   %u/%u %ld/%ld/%ld %ld/%ld/%ld\n",
 		   session->nr, session->ns,
 		   atomic_long_read(&session->stats.tx_packets),
 		   atomic_long_read(&session->stats.tx_bytes),
-- 
2.37.0.rc0.161.g10f37bed90-goog


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: l2tp: fix clang -Wformat warning
  2022-07-06 23:08 [PATCH] net: l2tp: fix clang -Wformat warning Justin Stitt
@ 2022-07-07  7:50 ` Guillaume Nault
  2022-07-08  1:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Guillaume Nault @ 2022-07-07  7:50 UTC (permalink / raw)
  To: Justin Stitt
  Cc: James Chapman, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Nathan Chancellor, Nick Desaulniers, Tom Rix,
	netdev, linux-kernel, llvm

On Wed, Jul 06, 2022 at 04:08:33PM -0700, Justin Stitt wrote:
> When building with clang we encounter this warning:
> | net/l2tp/l2tp_ppp.c:1557:6: error: format specifies type 'unsigned
> | short' but the argument has type 'u32' (aka 'unsigned int')
> | [-Werror,-Wformat] session->nr, session->ns,
> 
> Both session->nr and session->ns are of type u32. The format specifier
> previously used is `%hu` which would truncate our unsigned integer from
> 32 to 16 bits. This doesn't seem like intended behavior, if it is then
> perhaps we need to consider suppressing the warning with pragma clauses.

pppol2tp_seq_session_show() is only called for L2TPv2 sessions, where
ns and nr are 2 bytes long (L2TPv3 uses 3 bytes, hence the u32 type in
the generic l2tp_session structure). So %hu shouldn't truncate anything
here.

However %u doesn't harm and is cleaner than silencing the warning with
pragma.

Acked-by: Guillaume Nault <gnault@redhat.com>


> 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/l2tp/l2tp_ppp.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
> index 8be1fdc68a0b..db2e584c625e 100644
> --- a/net/l2tp/l2tp_ppp.c
> +++ b/net/l2tp/l2tp_ppp.c
> @@ -1553,7 +1553,7 @@ static void pppol2tp_seq_session_show(struct seq_file *m, void *v)
>  		   session->lns_mode ? "LNS" : "LAC",
>  		   0,
>  		   jiffies_to_msecs(session->reorder_timeout));
> -	seq_printf(m, "   %hu/%hu %ld/%ld/%ld %ld/%ld/%ld\n",
> +	seq_printf(m, "   %u/%u %ld/%ld/%ld %ld/%ld/%ld\n",
>  		   session->nr, session->ns,
>  		   atomic_long_read(&session->stats.tx_packets),
>  		   atomic_long_read(&session->stats.tx_bytes),
> -- 
> 2.37.0.rc0.161.g10f37bed90-goog
> 


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: l2tp: fix clang -Wformat warning
  2022-07-06 23:08 [PATCH] net: l2tp: fix clang -Wformat warning Justin Stitt
  2022-07-07  7:50 ` Guillaume Nault
@ 2022-07-08  1:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-08  1:30 UTC (permalink / raw)
  To: Justin Stitt
  Cc: jchapman, davem, edumazet, kuba, pabeni, nathan, ndesaulniers,
	trix, netdev, linux-kernel, llvm

Hello:

This patch was applied to netdev/net-next.git (master)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  6 Jul 2022 16:08:33 -0700 you wrote:
> When building with clang we encounter this warning:
> | net/l2tp/l2tp_ppp.c:1557:6: error: format specifies type 'unsigned
> | short' but the argument has type 'u32' (aka 'unsigned int')
> | [-Werror,-Wformat] session->nr, session->ns,
> 
> Both session->nr and session->ns are of type u32. The format specifier
> previously used is `%hu` which would truncate our unsigned integer from
> 32 to 16 bits. This doesn't seem like intended behavior, if it is then
> perhaps we need to consider suppressing the warning with pragma clauses.
> 
> [...]

Here is the summary with links:
  - net: l2tp: fix clang -Wformat warning
    https://git.kernel.org/netdev/net-next/c/a2b6111b55f3

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-07-08  1:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-06 23:08 [PATCH] net: l2tp: fix clang -Wformat warning Justin Stitt
2022-07-07  7:50 ` Guillaume Nault
2022-07-08  1:30 ` patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).