diff mbox series

net: mana: use ethtool string helpers

Message ID 20241022204908.511021-1-rosenp@gmail.com (mailing list archive)
State Accepted
Commit ae2930b0b3116537e4335c4d9c1f99fa01259ac7
Delegated to: Netdev Maintainers
Headers show
Series net: mana: use ethtool string helpers | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 5 this patch: 5
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 17 of 17 maintainers
netdev/build_clang success Errors and warnings before: 3 this patch: 3
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 4 this patch: 4
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 71 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-23--12-00 (tests: 777)

Commit Message

Rosen Penev Oct. 22, 2024, 8:49 p.m. UTC
The latter is the preferred way to copy ethtool strings.

Avoids manually incrementing the data pointer.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
---
 .../ethernet/microsoft/mana/mana_ethtool.c    | 55 ++++++-------------
 1 file changed, 18 insertions(+), 37 deletions(-)

Comments

Rosen Penev Oct. 22, 2024, 8:56 p.m. UTC | #1
On Tue, Oct 22, 2024 at 1:49 PM Rosen Penev <rosenp@gmail.com> wrote:
>
> The latter is the preferred way to copy ethtool strings.
>
> Avoids manually incrementing the data pointer.
>
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
forgot to put net-next.
> ---
>  .../ethernet/microsoft/mana/mana_ethtool.c    | 55 ++++++-------------
>  1 file changed, 18 insertions(+), 37 deletions(-)
>
> diff --git a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
> index 349f11bf8e64..c419626073f5 100644
> --- a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
> @@ -91,53 +91,34 @@ static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
>  {
>         struct mana_port_context *apc = netdev_priv(ndev);
>         unsigned int num_queues = apc->num_queues;
> -       u8 *p = data;
>         int i;
>
>         if (stringset != ETH_SS_STATS)
>                 return;
>
> -       for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++) {
> -               memcpy(p, mana_eth_stats[i].name, ETH_GSTRING_LEN);
> -               p += ETH_GSTRING_LEN;
> -       }
> +       for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++)
> +               ethtool_puts(&data, mana_eth_stats[i].name);
>
>         for (i = 0; i < num_queues; i++) {
> -               sprintf(p, "rx_%d_packets", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "rx_%d_bytes", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "rx_%d_xdp_drop", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "rx_%d_xdp_tx", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "rx_%d_xdp_redirect", i);
> -               p += ETH_GSTRING_LEN;
> +               ethtool_sprintf(&data, "rx_%d_packets", i);
> +               ethtool_sprintf(&data, "rx_%d_bytes", i);
> +               ethtool_sprintf(&data, "rx_%d_xdp_drop", i);
> +               ethtool_sprintf(&data, "rx_%d_xdp_tx", i);
> +               ethtool_sprintf(&data, "rx_%d_xdp_redirect", i);
>         }
>
>         for (i = 0; i < num_queues; i++) {
> -               sprintf(p, "tx_%d_packets", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "tx_%d_bytes", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "tx_%d_xdp_xmit", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "tx_%d_tso_packets", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "tx_%d_tso_bytes", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "tx_%d_tso_inner_packets", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "tx_%d_tso_inner_bytes", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "tx_%d_long_pkt_fmt", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "tx_%d_short_pkt_fmt", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "tx_%d_csum_partial", i);
> -               p += ETH_GSTRING_LEN;
> -               sprintf(p, "tx_%d_mana_map_err", i);
> -               p += ETH_GSTRING_LEN;
> +               ethtool_sprintf(&data, "tx_%d_packets", i);
> +               ethtool_sprintf(&data, "tx_%d_bytes", i);
> +               ethtool_sprintf(&data, "tx_%d_xdp_xmit", i);
> +               ethtool_sprintf(&data, "tx_%d_tso_packets", i);
> +               ethtool_sprintf(&data, "tx_%d_tso_bytes", i);
> +               ethtool_sprintf(&data, "tx_%d_tso_inner_packets", i);
> +               ethtool_sprintf(&data, "tx_%d_tso_inner_bytes", i);
> +               ethtool_sprintf(&data, "tx_%d_long_pkt_fmt", i);
> +               ethtool_sprintf(&data, "tx_%d_short_pkt_fmt", i);
> +               ethtool_sprintf(&data, "tx_%d_csum_partial", i);
> +               ethtool_sprintf(&data, "tx_%d_mana_map_err", i);
>         }
>  }
>
> --
> 2.47.0
>
Simon Horman Oct. 24, 2024, 11:04 a.m. UTC | #2
On Tue, Oct 22, 2024 at 01:49:08PM -0700, Rosen Penev wrote:
> The latter is the preferred way to copy ethtool strings.
> 
> Avoids manually incrementing the data pointer.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>

Reviewed-by: Simon Horman <horms@kernel.org>
Simon Horman Oct. 24, 2024, 11:05 a.m. UTC | #3
On Tue, Oct 22, 2024 at 01:56:56PM -0700, Rosen Penev wrote:
> On Tue, Oct 22, 2024 at 1:49 PM Rosen Penev <rosenp@gmail.com> wrote:
> >
> > The latter is the preferred way to copy ethtool strings.
> >
> > Avoids manually incrementing the data pointer.
> >
> > Signed-off-by: Rosen Penev <rosenp@gmail.com>
> forgot to put net-next.

Hi Rosen,

The CI guessed correctly, so I don't think you need to repost just for that.

...
Shradha Gupta Oct. 25, 2024, 6:08 a.m. UTC | #4
On Tue, Oct 22, 2024 at 01:49:08PM -0700, Rosen Penev wrote:
> The latter is the preferred way to copy ethtool strings.
> 
> Avoids manually incrementing the data pointer.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  .../ethernet/microsoft/mana/mana_ethtool.c    | 55 ++++++-------------
>  1 file changed, 18 insertions(+), 37 deletions(-)
> 
> diff --git a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
> index 349f11bf8e64..c419626073f5 100644
> --- a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
> +++ b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
> @@ -91,53 +91,34 @@ static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
>  {
>  	struct mana_port_context *apc = netdev_priv(ndev);
>  	unsigned int num_queues = apc->num_queues;
> -	u8 *p = data;
>  	int i;
>  
>  	if (stringset != ETH_SS_STATS)
>  		return;
>  
> -	for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++) {
> -		memcpy(p, mana_eth_stats[i].name, ETH_GSTRING_LEN);
> -		p += ETH_GSTRING_LEN;
> -	}
> +	for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++)
> +		ethtool_puts(&data, mana_eth_stats[i].name);
>  
>  	for (i = 0; i < num_queues; i++) {
> -		sprintf(p, "rx_%d_packets", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "rx_%d_bytes", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "rx_%d_xdp_drop", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "rx_%d_xdp_tx", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "rx_%d_xdp_redirect", i);
> -		p += ETH_GSTRING_LEN;
> +		ethtool_sprintf(&data, "rx_%d_packets", i);
> +		ethtool_sprintf(&data, "rx_%d_bytes", i);
> +		ethtool_sprintf(&data, "rx_%d_xdp_drop", i);
> +		ethtool_sprintf(&data, "rx_%d_xdp_tx", i);
> +		ethtool_sprintf(&data, "rx_%d_xdp_redirect", i);
>  	}
>  
>  	for (i = 0; i < num_queues; i++) {
> -		sprintf(p, "tx_%d_packets", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "tx_%d_bytes", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "tx_%d_xdp_xmit", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "tx_%d_tso_packets", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "tx_%d_tso_bytes", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "tx_%d_tso_inner_packets", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "tx_%d_tso_inner_bytes", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "tx_%d_long_pkt_fmt", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "tx_%d_short_pkt_fmt", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "tx_%d_csum_partial", i);
> -		p += ETH_GSTRING_LEN;
> -		sprintf(p, "tx_%d_mana_map_err", i);
> -		p += ETH_GSTRING_LEN;
> +		ethtool_sprintf(&data, "tx_%d_packets", i);
> +		ethtool_sprintf(&data, "tx_%d_bytes", i);
> +		ethtool_sprintf(&data, "tx_%d_xdp_xmit", i);
> +		ethtool_sprintf(&data, "tx_%d_tso_packets", i);
> +		ethtool_sprintf(&data, "tx_%d_tso_bytes", i);
> +		ethtool_sprintf(&data, "tx_%d_tso_inner_packets", i);
> +		ethtool_sprintf(&data, "tx_%d_tso_inner_bytes", i);
> +		ethtool_sprintf(&data, "tx_%d_long_pkt_fmt", i);
> +		ethtool_sprintf(&data, "tx_%d_short_pkt_fmt", i);
> +		ethtool_sprintf(&data, "tx_%d_csum_partial", i);
> +		ethtool_sprintf(&data, "tx_%d_mana_map_err", i);
>  	}
>  }
Reviewed-by: Shradha Gupta <shradhagupta@linux.microsoft.com>
>  
> -- 
> 2.47.0
patchwork-bot+netdevbpf@kernel.org Oct. 29, 2024, 11 p.m. UTC | #5
Hello:

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

On Tue, 22 Oct 2024 13:49:08 -0700 you wrote:
> The latter is the preferred way to copy ethtool strings.
> 
> Avoids manually incrementing the data pointer.
> 
> Signed-off-by: Rosen Penev <rosenp@gmail.com>
> ---
>  .../ethernet/microsoft/mana/mana_ethtool.c    | 55 ++++++-------------
>  1 file changed, 18 insertions(+), 37 deletions(-)

Here is the summary with links:
  - net: mana: use ethtool string helpers
    https://git.kernel.org/netdev/net-next/c/ae2930b0b311

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
index 349f11bf8e64..c419626073f5 100644
--- a/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
+++ b/drivers/net/ethernet/microsoft/mana/mana_ethtool.c
@@ -91,53 +91,34 @@  static void mana_get_strings(struct net_device *ndev, u32 stringset, u8 *data)
 {
 	struct mana_port_context *apc = netdev_priv(ndev);
 	unsigned int num_queues = apc->num_queues;
-	u8 *p = data;
 	int i;
 
 	if (stringset != ETH_SS_STATS)
 		return;
 
-	for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++) {
-		memcpy(p, mana_eth_stats[i].name, ETH_GSTRING_LEN);
-		p += ETH_GSTRING_LEN;
-	}
+	for (i = 0; i < ARRAY_SIZE(mana_eth_stats); i++)
+		ethtool_puts(&data, mana_eth_stats[i].name);
 
 	for (i = 0; i < num_queues; i++) {
-		sprintf(p, "rx_%d_packets", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "rx_%d_bytes", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "rx_%d_xdp_drop", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "rx_%d_xdp_tx", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "rx_%d_xdp_redirect", i);
-		p += ETH_GSTRING_LEN;
+		ethtool_sprintf(&data, "rx_%d_packets", i);
+		ethtool_sprintf(&data, "rx_%d_bytes", i);
+		ethtool_sprintf(&data, "rx_%d_xdp_drop", i);
+		ethtool_sprintf(&data, "rx_%d_xdp_tx", i);
+		ethtool_sprintf(&data, "rx_%d_xdp_redirect", i);
 	}
 
 	for (i = 0; i < num_queues; i++) {
-		sprintf(p, "tx_%d_packets", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "tx_%d_bytes", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "tx_%d_xdp_xmit", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "tx_%d_tso_packets", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "tx_%d_tso_bytes", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "tx_%d_tso_inner_packets", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "tx_%d_tso_inner_bytes", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "tx_%d_long_pkt_fmt", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "tx_%d_short_pkt_fmt", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "tx_%d_csum_partial", i);
-		p += ETH_GSTRING_LEN;
-		sprintf(p, "tx_%d_mana_map_err", i);
-		p += ETH_GSTRING_LEN;
+		ethtool_sprintf(&data, "tx_%d_packets", i);
+		ethtool_sprintf(&data, "tx_%d_bytes", i);
+		ethtool_sprintf(&data, "tx_%d_xdp_xmit", i);
+		ethtool_sprintf(&data, "tx_%d_tso_packets", i);
+		ethtool_sprintf(&data, "tx_%d_tso_bytes", i);
+		ethtool_sprintf(&data, "tx_%d_tso_inner_packets", i);
+		ethtool_sprintf(&data, "tx_%d_tso_inner_bytes", i);
+		ethtool_sprintf(&data, "tx_%d_long_pkt_fmt", i);
+		ethtool_sprintf(&data, "tx_%d_short_pkt_fmt", i);
+		ethtool_sprintf(&data, "tx_%d_csum_partial", i);
+		ethtool_sprintf(&data, "tx_%d_mana_map_err", i);
 	}
 }