diff mbox series

[net-next] veth: use ethtool_sprintf instead of snprintf

Message ID 20211125015438.5355-1-xiangxia.m.yue@gmail.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [net-next] veth: use ethtool_sprintf instead of snprintf | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 3 of 3 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 34 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Tonghao Zhang Nov. 25, 2021, 1:54 a.m. UTC
From: Tonghao Zhang <xiangxia.m.yue@gmail.com>

use ethtools api ethtool_sprintf to instead of snprintf.

Cc: Jakub Kicinski <kuba@kernel.org>
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Tonghao Zhang <xiangxia.m.yue@gmail.com>
---
 drivers/net/veth.c | 20 +++++++-------------
 1 file changed, 7 insertions(+), 13 deletions(-)

Comments

Jakub Kicinski Nov. 25, 2021, 2:13 a.m. UTC | #1
On Thu, 25 Nov 2021 09:54:38 +0800 xiangxia.m.yue@gmail.com wrote:
>  		for (i = 0; i < dev->real_num_rx_queues; i++) {
> -			for (j = 0; j < VETH_RQ_STATS_LEN; j++) {
> -				snprintf(p, ETH_GSTRING_LEN,
> -					 "rx_queue_%u_%.18s",
> -					 i, veth_rq_stats_desc[j].desc);
> -				p += ETH_GSTRING_LEN;
> -			}
> +			for (j = 0; j < VETH_RQ_STATS_LEN; j++)
> +				ethtool_sprintf(&p, "rx_queue_%u_%.18s",
> +						i, veth_rq_stats_desc[j].desc);
>  		}
>  		for (i = 0; i < dev->real_num_tx_queues; i++) {
> -			for (j = 0; j < VETH_TQ_STATS_LEN; j++) {
> -				snprintf(p, ETH_GSTRING_LEN,
> -					 "tx_queue_%u_%.18s",
> -					 i, veth_tq_stats_desc[j].desc);
> -				p += ETH_GSTRING_LEN;
> -			}
> +			for (j = 0; j < VETH_TQ_STATS_LEN; j++)
> +				ethtool_sprintf(&p, "tx_queue_%u_%.18s",
> +						i, veth_tq_stats_desc[j].desc);
>  		}

You can drop the brackets from the outside for as well.
diff mbox series

Patch

diff --git a/drivers/net/veth.c b/drivers/net/veth.c
index 5ca0a899101d..d1c3a3ff4928 100644
--- a/drivers/net/veth.c
+++ b/drivers/net/veth.c
@@ -134,7 +134,7 @@  static void veth_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *inf
 
 static void veth_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
 {
-	char *p = (char *)buf;
+	u8 *p = buf;
 	int i, j;
 
 	switch(stringset) {
@@ -142,20 +142,14 @@  static void veth_get_strings(struct net_device *dev, u32 stringset, u8 *buf)
 		memcpy(p, &ethtool_stats_keys, sizeof(ethtool_stats_keys));
 		p += sizeof(ethtool_stats_keys);
 		for (i = 0; i < dev->real_num_rx_queues; i++) {
-			for (j = 0; j < VETH_RQ_STATS_LEN; j++) {
-				snprintf(p, ETH_GSTRING_LEN,
-					 "rx_queue_%u_%.18s",
-					 i, veth_rq_stats_desc[j].desc);
-				p += ETH_GSTRING_LEN;
-			}
+			for (j = 0; j < VETH_RQ_STATS_LEN; j++)
+				ethtool_sprintf(&p, "rx_queue_%u_%.18s",
+						i, veth_rq_stats_desc[j].desc);
 		}
 		for (i = 0; i < dev->real_num_tx_queues; i++) {
-			for (j = 0; j < VETH_TQ_STATS_LEN; j++) {
-				snprintf(p, ETH_GSTRING_LEN,
-					 "tx_queue_%u_%.18s",
-					 i, veth_tq_stats_desc[j].desc);
-				p += ETH_GSTRING_LEN;
-			}
+			for (j = 0; j < VETH_TQ_STATS_LEN; j++)
+				ethtool_sprintf(&p, "tx_queue_%u_%.18s",
+						i, veth_tq_stats_desc[j].desc);
 		}
 		break;
 	}