netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net-next] net: ethernet: ti: Fix format specifier in netcp_create_interface()
@ 2023-03-29 15:08 Nathan Chancellor
  2023-03-29 17:10 ` Nick Desaulniers
  2023-03-31  6:30 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 4+ messages in thread
From: Nathan Chancellor @ 2023-03-29 15:08 UTC (permalink / raw)
  To: davem, edumazet, kuba, pabeni
  Cc: nathan, ndesaulniers, trix, razor, kerneljasonxing, netdev,
	linux-kernel, llvm, patches

After commit 3948b05950fd ("net: introduce a config option to tweak
MAX_SKB_FRAGS"), clang warns:

  drivers/net/ethernet/ti/netcp_core.c:2085:4: warning: format specifies type 'long' but the argument has type 'int' [-Wformat]
                          MAX_SKB_FRAGS);
                          ^~~~~~~~~~~~~
  include/linux/dev_printk.h:144:65: note: expanded from macro 'dev_err'
          dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
                                                                 ~~~     ^~~~~~~~~~~
  include/linux/dev_printk.h:110:23: note: expanded from macro 'dev_printk_index_wrap'
                  _p_func(dev, fmt, ##__VA_ARGS__);                       \
                               ~~~    ^~~~~~~~~~~
  include/linux/skbuff.h:352:23: note: expanded from macro 'MAX_SKB_FRAGS'
  #define MAX_SKB_FRAGS CONFIG_MAX_SKB_FRAGS
                        ^~~~~~~~~~~~~~~~~~~~
  ./include/generated/autoconf.h:11789:30: note: expanded from macro 'CONFIG_MAX_SKB_FRAGS'
  #define CONFIG_MAX_SKB_FRAGS 17
                               ^~
  1 warning generated.

Follow the pattern of the rest of the tree by changing the specifier to
'%u' and casting MAX_SKB_FRAGS explicitly to 'unsigned int', which
eliminates the warning.

Fixes: 3948b05950fd ("net: introduce a config option to tweak MAX_SKB_FRAGS")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
---
I am a little confused as to why the solution for this warning is
casting to 'unsigned int' rather than just updating all the specifiers
to be '%d', as I do not see how MAX_SKB_FRAGS can be any type other than
just 'int' but I figured I would be consistent with the other fixes I
have seen around this issue.
---
 drivers/net/ethernet/ti/netcp_core.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c
index 1bb596a9d8a2..d829113c16ee 100644
--- a/drivers/net/ethernet/ti/netcp_core.c
+++ b/drivers/net/ethernet/ti/netcp_core.c
@@ -2081,8 +2081,8 @@ static int netcp_create_interface(struct netcp_device *netcp_device,
 	netcp->tx_pool_region_id = temp[1];
 
 	if (netcp->tx_pool_size < MAX_SKB_FRAGS) {
-		dev_err(dev, "tx-pool size too small, must be at least %ld\n",
-			MAX_SKB_FRAGS);
+		dev_err(dev, "tx-pool size too small, must be at least %u\n",
+			(unsigned int)MAX_SKB_FRAGS);
 		ret = -ENODEV;
 		goto quit;
 	}

---
base-commit: 3b064f541be822dc095991c6dda20a75eb51db5e
change-id: 20230329-net-ethernet-ti-wformat-acaa86350657

Best regards,
-- 
Nathan Chancellor <nathan@kernel.org>


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

* Re: [PATCH net-next] net: ethernet: ti: Fix format specifier in netcp_create_interface()
  2023-03-29 15:08 [PATCH net-next] net: ethernet: ti: Fix format specifier in netcp_create_interface() Nathan Chancellor
@ 2023-03-29 17:10 ` Nick Desaulniers
  2023-03-29 17:41   ` Nick Desaulniers
  2023-03-31  6:30 ` patchwork-bot+netdevbpf
  1 sibling, 1 reply; 4+ messages in thread
From: Nick Desaulniers @ 2023-03-29 17:10 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: davem, edumazet, kuba, pabeni, trix, razor, kerneljasonxing,
	netdev, linux-kernel, llvm, patches

On Wed, Mar 29, 2023 at 8:08 AM Nathan Chancellor <nathan@kernel.org> wrote:
>
> After commit 3948b05950fd ("net: introduce a config option to tweak
> MAX_SKB_FRAGS"), clang warns:
>
>   drivers/net/ethernet/ti/netcp_core.c:2085:4: warning: format specifies type 'long' but the argument has type 'int' [-Wformat]
>                           MAX_SKB_FRAGS);
>                           ^~~~~~~~~~~~~
>   include/linux/dev_printk.h:144:65: note: expanded from macro 'dev_err'
>           dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
>                                                                  ~~~     ^~~~~~~~~~~
>   include/linux/dev_printk.h:110:23: note: expanded from macro 'dev_printk_index_wrap'
>                   _p_func(dev, fmt, ##__VA_ARGS__);                       \
>                                ~~~    ^~~~~~~~~~~
>   include/linux/skbuff.h:352:23: note: expanded from macro 'MAX_SKB_FRAGS'
>   #define MAX_SKB_FRAGS CONFIG_MAX_SKB_FRAGS
>                         ^~~~~~~~~~~~~~~~~~~~
>   ./include/generated/autoconf.h:11789:30: note: expanded from macro 'CONFIG_MAX_SKB_FRAGS'
>   #define CONFIG_MAX_SKB_FRAGS 17
>                                ^~
>   1 warning generated.
>
> Follow the pattern of the rest of the tree by changing the specifier to
> '%u' and casting MAX_SKB_FRAGS explicitly to 'unsigned int', which
> eliminates the warning.
>
> Fixes: 3948b05950fd ("net: introduce a config option to tweak MAX_SKB_FRAGS")
> Signed-off-by: Nathan Chancellor <nathan@kernel.org>
> ---
> I am a little confused as to why the solution for this warning is
> casting to 'unsigned int' rather than just updating all the specifiers
> to be '%d', as I do not see how MAX_SKB_FRAGS can be any type other than
> just 'int' but I figured I would be consistent with the other fixes I
> have seen around this issue.

MAX_SKB_FRAGS might be defined by Kconfig, see:
 352 #define MAX_SKB_FRAGS CONFIG_MAX_SKB_FRAGS
in include/linux/skbuff.h. The Kconfig is declared in
net/Kconfig:254.

Because integer literals in C are signed, the cast is necessary to
avoid the format specifier from warning about the wrong signedness.
It would be preferable to have a `U` suffix on the literal value, then
the cast would be unnecessary.

Untested:
```
diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 494a23a976b0..67cb6bfc4056 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -349,7 +349,7 @@ struct sk_buff;
 # define CONFIG_MAX_SKB_FRAGS 17
 #endif

-#define MAX_SKB_FRAGS CONFIG_MAX_SKB_FRAGS
+#define MAX_SKB_FRAGS CONFIG_MAX_SKB_FRAGS ## U

 extern int sysctl_max_skb_frags;
```
Perhaps other code using MAX_SKB_FRAGS might have to worry about
signedness and conversions.

But I think what you have is fine for now.
Reviewed-by: Nick Desaulniers <ndesaulniers@google.com>
Though the above might be a longer-term solution since this might pop up again.

> ---
>  drivers/net/ethernet/ti/netcp_core.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/net/ethernet/ti/netcp_core.c b/drivers/net/ethernet/ti/netcp_core.c
> index 1bb596a9d8a2..d829113c16ee 100644
> --- a/drivers/net/ethernet/ti/netcp_core.c
> +++ b/drivers/net/ethernet/ti/netcp_core.c
> @@ -2081,8 +2081,8 @@ static int netcp_create_interface(struct netcp_device *netcp_device,
>         netcp->tx_pool_region_id = temp[1];
>
>         if (netcp->tx_pool_size < MAX_SKB_FRAGS) {
> -               dev_err(dev, "tx-pool size too small, must be at least %ld\n",
> -                       MAX_SKB_FRAGS);
> +               dev_err(dev, "tx-pool size too small, must be at least %u\n",
> +                       (unsigned int)MAX_SKB_FRAGS);
>                 ret = -ENODEV;
>                 goto quit;
>         }
>
> ---
> base-commit: 3b064f541be822dc095991c6dda20a75eb51db5e
> change-id: 20230329-net-ethernet-ti-wformat-acaa86350657
>
> Best regards,
> --
> Nathan Chancellor <nathan@kernel.org>
>


-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH net-next] net: ethernet: ti: Fix format specifier in netcp_create_interface()
  2023-03-29 17:10 ` Nick Desaulniers
@ 2023-03-29 17:41   ` Nick Desaulniers
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Desaulniers @ 2023-03-29 17:41 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: davem, edumazet, kuba, pabeni, trix, razor, kerneljasonxing,
	netdev, linux-kernel, llvm, patches

On Wed, Mar 29, 2023 at 10:10 AM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> Because integer literals in C are signed, the cast is necessary to
> avoid the format specifier from warning about the wrong signedness.
> It would be preferable to have a `U` suffix on the literal value, then
> the cast would be unnecessary.
>
> Untested:
> ```
> diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
> index 494a23a976b0..67cb6bfc4056 100644
> --- a/include/linux/skbuff.h
> +++ b/include/linux/skbuff.h
> @@ -349,7 +349,7 @@ struct sk_buff;
>  # define CONFIG_MAX_SKB_FRAGS 17
>  #endif
>
> -#define MAX_SKB_FRAGS CONFIG_MAX_SKB_FRAGS
> +#define MAX_SKB_FRAGS CONFIG_MAX_SKB_FRAGS ## U

Or rather this trick.
https://godbolt.org/z/81aPxf39b
I forget what that's called (it's not xmacros); we definitely have a
macro for that in the kernel.

-- 
Thanks,
~Nick Desaulniers

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

* Re: [PATCH net-next] net: ethernet: ti: Fix format specifier in netcp_create_interface()
  2023-03-29 15:08 [PATCH net-next] net: ethernet: ti: Fix format specifier in netcp_create_interface() Nathan Chancellor
  2023-03-29 17:10 ` Nick Desaulniers
@ 2023-03-31  6:30 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2023-03-31  6:30 UTC (permalink / raw)
  To: Nathan Chancellor
  Cc: davem, edumazet, kuba, pabeni, ndesaulniers, trix, razor,
	kerneljasonxing, netdev, linux-kernel, llvm, patches

Hello:

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

On Wed, 29 Mar 2023 08:08:01 -0700 you wrote:
> After commit 3948b05950fd ("net: introduce a config option to tweak
> MAX_SKB_FRAGS"), clang warns:
> 
>   drivers/net/ethernet/ti/netcp_core.c:2085:4: warning: format specifies type 'long' but the argument has type 'int' [-Wformat]
>                           MAX_SKB_FRAGS);
>                           ^~~~~~~~~~~~~
>   include/linux/dev_printk.h:144:65: note: expanded from macro 'dev_err'
>           dev_printk_index_wrap(_dev_err, KERN_ERR, dev, dev_fmt(fmt), ##__VA_ARGS__)
>                                                                  ~~~     ^~~~~~~~~~~
>   include/linux/dev_printk.h:110:23: note: expanded from macro 'dev_printk_index_wrap'
>                   _p_func(dev, fmt, ##__VA_ARGS__);                       \
>                                ~~~    ^~~~~~~~~~~
>   include/linux/skbuff.h:352:23: note: expanded from macro 'MAX_SKB_FRAGS'
>   #define MAX_SKB_FRAGS CONFIG_MAX_SKB_FRAGS
>                         ^~~~~~~~~~~~~~~~~~~~
>   ./include/generated/autoconf.h:11789:30: note: expanded from macro 'CONFIG_MAX_SKB_FRAGS'
>   #define CONFIG_MAX_SKB_FRAGS 17
>                                ^~
>   1 warning generated.
> 
> [...]

Here is the summary with links:
  - [net-next] net: ethernet: ti: Fix format specifier in netcp_create_interface()
    https://git.kernel.org/netdev/net-next/c/3292004c90c8

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] 4+ messages in thread

end of thread, other threads:[~2023-03-31  6:30 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-29 15:08 [PATCH net-next] net: ethernet: ti: Fix format specifier in netcp_create_interface() Nathan Chancellor
2023-03-29 17:10 ` Nick Desaulniers
2023-03-29 17:41   ` Nick Desaulniers
2023-03-31  6: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).