netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guillaume Nault <gnault@redhat.com>
To: Justin Stitt <justinstitt@google.com>
Cc: James Chapman <jchapman@katalix.com>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Nathan Chancellor <nathan@kernel.org>,
	Nick Desaulniers <ndesaulniers@google.com>,
	Tom Rix <trix@redhat.com>,
	netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
	llvm@lists.linux.dev
Subject: Re: [PATCH] net: l2tp: fix clang -Wformat warning
Date: Thu, 7 Jul 2022 09:50:52 +0200	[thread overview]
Message-ID: <20220707075052.GA3912@debian.home> (raw)
In-Reply-To: <20220706230833.535238-1-justinstitt@google.com>

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
> 


  reply	other threads:[~2022-07-07  7:51 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-06 23:08 [PATCH] net: l2tp: fix clang -Wformat warning Justin Stitt
2022-07-07  7:50 ` Guillaume Nault [this message]
2022-07-08  1:30 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220707075052.GA3912@debian.home \
    --to=gnault@redhat.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=jchapman@katalix.com \
    --cc=justinstitt@google.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=llvm@lists.linux.dev \
    --cc=nathan@kernel.org \
    --cc=ndesaulniers@google.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=trix@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).