netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: ipv4: fix clang -Wformat warning
@ 2022-07-07 17:30 Justin Stitt
  2022-07-07 17:40 ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Justin Stitt @ 2022-07-07 17:30 UTC (permalink / raw)
  To: Steffen Klassert, Herbert Xu, David S . Miller, Hideaki YOSHIFUJI,
	David Ahern, 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/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.

Link: https://github.com/ClangBuiltLinux/linux/issues/378
Signed-off-by: Justin Stitt <justinstitt@google.com>
---
 net/ipv4/ah4.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
index 6eea1e9e998d..3bf3d01fb7e3 100644
--- 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);
-- 
2.37.0.rc0.161.g10f37bed90-goog


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

* Re: [PATCH] net: ipv4: fix clang -Wformat warning
  2022-07-07 17:30 [PATCH] net: ipv4: fix clang -Wformat warning Justin Stitt
@ 2022-07-07 17:40 ` Joe Perches
  2022-07-07 17:47   ` Justin Stitt
  0 siblings, 1 reply; 4+ messages in thread
From: Joe Perches @ 2022-07-07 17:40 UTC (permalink / raw)
  To: Justin Stitt, Steffen Klassert, Herbert Xu, David S . Miller,
	Hideaki YOSHIFUJI, David Ahern, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni
  Cc: Nathan Chancellor, Nick Desaulniers, Tom Rix, netdev,
	linux-kernel, llvm

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.

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


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

* Re: [PATCH] net: ipv4: fix clang -Wformat warning
  2022-07-07 17:40 ` Joe Perches
@ 2022-07-07 17:47   ` Justin Stitt
  2022-07-07 18:01     ` Joe Perches
  0 siblings, 1 reply; 4+ messages in thread
From: Justin Stitt @ 2022-07-07 17:47 UTC (permalink / raw)
  To: Joe Perches
  Cc: Steffen Klassert, Herbert Xu, David S . Miller, Hideaki YOSHIFUJI,
	David Ahern, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, netdev,
	linux-kernel, llvm

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?
>
> > 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);
>

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

* Re: [PATCH] net: ipv4: fix clang -Wformat warning
  2022-07-07 17:47   ` Justin Stitt
@ 2022-07-07 18:01     ` Joe Perches
  0 siblings, 0 replies; 4+ messages in thread
From: Joe Perches @ 2022-07-07 18:01 UTC (permalink / raw)
  To: Justin Stitt
  Cc: Steffen Klassert, Herbert Xu, David S . Miller, Hideaki YOSHIFUJI,
	David Ahern, Eric Dumazet, Jakub Kicinski, Paolo Abeni,
	Nathan Chancellor, Nick Desaulniers, Tom Rix, netdev,
	linux-kernel, llvm

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


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

end of thread, other threads:[~2022-07-07 18:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-07 17:30 [PATCH] net: ipv4: fix clang -Wformat warning Justin Stitt
2022-07-07 17:40 ` Joe Perches
2022-07-07 17:47   ` Justin Stitt
2022-07-07 18:01     ` Joe Perches

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