mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Justin Stitt <justinstitt@google.com>
Cc: Steffen Klassert <steffen.klassert@secunet.com>,
	Herbert Xu <herbert@gondor.apana.org.au>,
	"David S . Miller" <davem@davemloft.net>,
	Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
	David Ahern <dsahern@kernel.org>,
	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: ipv4: fix clang -Wformat warning
Date: Thu, 07 Jul 2022 11:01:26 -0700	[thread overview]
Message-ID: <da17617717c5f6a79f58cdf4a56cd39e28c53377.camel@perches.com> (raw)
In-Reply-To: <CAFhGd8oTybm0aQ_q60e+exf5eFO1kLiNKnmDZfVTyg=BbtgZsw@mail.gmail.com>

On Thu, 2022-07-07 at 10:47 -0700, Justin Stitt wrote:
> On Thu, Jul 7, 2022 at 10:40 AM Joe Perches <joe@perches.com> wrote:
> > 
> > On Thu, 2022-07-07 at 10:30 -0700, Justin Stitt wrote:
> > > When building with Clang we encounter this warning:
> > > > net/ipv4/ah4.c:513:4: error: format specifies type 'unsigned short' but
> > > > the argument has type 'int' [-Werror,-Wformat]
> > > > aalg_desc->uinfo.auth.icv_fullbits / 8);
> > > 
> > > `aalg_desc->uinfo.auth.icv_fullbits` is a u16 but due to default
> > > argument promotion becomes an int.
> > > 
> > > Variadic functions (printf-like) undergo default argument promotion.
> > > Documentation/core-api/printk-formats.rst specifically recommends using
> > > the promoted-to-type's format flag.
> > > 
> > > As per C11 6.3.1.1:
> > > (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n1548.pdf) `If an int
> > > can represent all values of the original type ..., the value is
> > > converted to an int; otherwise, it is converted to an unsigned int.
> > > These are called the integer promotions.` Thus it makes sense to change
> > > %hu to %d not only to follow this standard but to suppress the warning
> > > as well.
> > 
> > I think it also makes sense to use %u and not %d
> > as the original type is unsigned.
> Yeah, that would also work. An integer (even a signed one) fully
> encompasses a u16 so it's really a choice of style. Do you think the
> change to %u warrants a v2 of this patch?

As it's rather odd output to use '%u != %d', probably.

Your patch, up to you.

> > 
> > > diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
> > []
> > > @@ -507,7 +507,7 @@ static int ah_init_state(struct xfrm_state *x)
> > > 
> > >       if (aalg_desc->uinfo.auth.icv_fullbits/8 !=
> > >           crypto_ahash_digestsize(ahash)) {
> > > -             pr_info("%s: %s digestsize %u != %hu\n",
> > > +             pr_info("%s: %s digestsize %u != %d\n",
> > >                       __func__, x->aalg->alg_name,
> > >                       crypto_ahash_digestsize(ahash),
> > >                       aalg_desc->uinfo.auth.icv_fullbits / 8);
> > 


      reply	other threads:[~2022-07-07 18:01 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07 17:30 Justin Stitt
2022-07-07 17:40 ` Joe Perches
2022-07-07 17:47   ` Justin Stitt
2022-07-07 18:01     ` Joe Perches [this message]

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=da17617717c5f6a79f58cdf4a56cd39e28c53377.camel@perches.com \
    --to=joe@perches.com \
    --cc=davem@davemloft.net \
    --cc=dsahern@kernel.org \
    --cc=edumazet@google.com \
    --cc=herbert@gondor.apana.org.au \
    --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=steffen.klassert@secunet.com \
    --cc=trix@redhat.com \
    --cc=yoshfuji@linux-ipv6.org \
    /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

all inboxes | Powered by JetHome®