net: broadcom: use ethtool string helpers
Subsystems (7)
PATCH 1/1 net: broadcom: use ethtool string helpers
The latter is the preferred way to copy ethtool strings.
Avoids manually incrementing the pointer. Cleans up the code quite well.
--- .../ethernet/broadcom/asp2/bcmasp_ethtool.c | 6 +- drivers/net/ethernet/broadcom/bcm63xx_enet.c | 12 ++-- drivers/net/ethernet/broadcom/bcmsysport.c | 20 ++---- drivers/net/ethernet/broadcom/bgmac.c | 3 +- .../ethernet/broadcom/bnx2x/bnx2x_ethtool.c | 66 ++++++++----------- .../net/ethernet/broadcom/genet/bcmgenet.c | 6 +- 6 files changed, 47 insertions(+), 66 deletions(-)
drivers/net/ethernet/broadcom/asp2/bcmasp_ethtool.c +3 -3
@@ -101,14 +101,14 @@ static int bcmasp_get_sset_count(struct net_device *dev, int string_set)static void bcmasp_get_strings (struct net_device *dev,u32 stringset,u8 *data) { +const char *str;unsigned int i;switch (stringset) {case ETH_SS_STATS :for (i =0 ; i <BCMASP_STATS_LEN ; i++) { -memcpy (data + i *ETH_GSTRING_LEN , - bcmasp_gstrings_stats[i].stat_string, -ETH_GSTRING_LEN ); + str = bcmasp_gstrings_stats[i].stat_string; +ethtool_puts (&data, str); }break ;default :
drivers/net/ethernet/broadcom/bcm63xx_enet.c +6 -6
@@ -1339,14 +1339,14 @@ static int bcm_enet_get_sset_count(struct net_device *netdev,static void bcm_enet_get_strings (struct net_device *netdev,u32 stringset,u8 *data) { +const char *str;int i;switch (stringset) {case ETH_SS_STATS :for (i =0 ; i <BCM_ENET_STATS_LEN ; i++) { -memcpy (data + i *ETH_GSTRING_LEN , - bcm_enet_gstrings_stats[i].stat_string, -ETH_GSTRING_LEN ); + str = bcm_enet_gstrings_stats[i].stat_string; +ethtool_puts (&data, str); }break ; }
@@ -2503,14 +2503,14 @@ static const struct bcm_enet_stats bcm_enetsw_gstrings_stats[] = {static void bcm_enetsw_get_strings (struct net_device *netdev,u32 stringset,u8 *data) { +const char *str;int i;switch (stringset) {case ETH_SS_STATS :for (i =0 ; i <BCM_ENETSW_STATS_LEN ; i++) { -memcpy (data + i *ETH_GSTRING_LEN , - bcm_enetsw_gstrings_stats[i].stat_string, -ETH_GSTRING_LEN ); + str = bcm_enetsw_gstrings_stats[i].stat_string; +ethtool_puts (&data, str); }break ; }
drivers/net/ethernet/broadcom/bcmsysport.c +5 -15
@@ -370,32 +370,22 @@ static void bcm_sysport_get_strings(struct net_device *dev, {struct bcm_sysport_priv *priv =netdev_priv (dev);const struct bcm_sysport_stats *s; -char buf[128 ]; -int i, j; +int i;switch (stringset) {case ETH_SS_STATS : -for (i =0 , j =0 ; i <BCM_SYSPORT_STATS_LEN ; i++) { +for (i =0 ; i <BCM_SYSPORT_STATS_LEN ; i++) { s = &bcm_sysport_gstrings_stats[i];if (priv->is_lite && !bcm_sysport_lite_stat_valid (s->type))continue ; -memcpy (data + j *ETH_GSTRING_LEN , s->stat_string, -ETH_GSTRING_LEN ); - j++; +ethtool_puts (&data, s->stat_string); }for (i =0 ; i < dev->num_tx_queues; i++) { -snprintf (buf,sizeof (buf),"txq%d_packets" , i); -memcpy (data + j *ETH_GSTRING_LEN , buf, -ETH_GSTRING_LEN ); - j++; - -snprintf (buf,sizeof (buf),"txq%d_bytes" , i); -memcpy (data + j *ETH_GSTRING_LEN , buf, -ETH_GSTRING_LEN ); - j++; +ethtool_sprintf (&data,"txq%d_packets" , i); +ethtool_sprintf (&data,"txq%d_bytes" , i); }break ;default :
drivers/net/ethernet/broadcom/bgmac.c +1 -2
@@ -1367,8 +1367,7 @@ static void bgmac_get_strings(struct net_device *dev, u32 stringset,return ;for (i =0 ; i <BGMAC_STATS_LEN ; i++) -strscpy (data + i *ETH_GSTRING_LEN , - bgmac_get_strings_stats[i].name,ETH_GSTRING_LEN ); +ethtool_puts (&data, bgmac_get_strings_stats[i].name); } static void bgmac_get_ethtool_stats(struct net_device *dev,
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c +29 -37
108 lines not on this page · raw message
drivers/net/ethernet/broadcom/genet/bcmgenet.c +3 -3
@@ -1144,14 +1144,14 @@ static int bcmgenet_get_sset_count(struct net_device *dev, int string_set)static void bcmgenet_get_strings (struct net_device *dev,u32 stringset,u8 *data) { +const char *str;int i;switch (stringset) {case ETH_SS_STATS :for (i =0 ; i <BCMGENET_STATS_LEN ; i++) { -memcpy (data + i *ETH_GSTRING_LEN , - bcmgenet_gstrings_stats[i].stat_string, -ETH_GSTRING_LEN ); + str = bcmgenet_gstrings_stats[i].stat_string; +ethtool_puts (&data, str); }break ; }
Signature · 1 line
2.47.0
Quoted 5 lines · Rosen Penev
The latter is the preferred way to copy ethtool strings.
Avoids manually incrementing the pointer. Cleans up the code quite well.
Signed-off-by Rosen Penev <[email protected]>
Jakub Kicinski
maintainerdrivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) · line 3216
Quoted 8 lines · On Tue, 22 Oct 2024 18:27:34 -0700 Rosen Penev wrote:
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c +2
-2@@ -3220,13 +3212,13 @@ static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) start =0 ; else start =4 ; -memcpy (buf, bnx2x_tests_str_arr + start, -ETH_GSTRING_LEN *BNX2X_NUM_TESTS (bp)); +for (i = start; i <BNX2X_NUM_TESTS (bp); i++) +ethtool_puts (&buf, bnx2x_tests_str_arr[i]);
I don't think this is equivalent.
Also, please split bnx2x to a separate patch, the other drivers in this patch IIUC are small embedded ones, the bnx2x is an "enterprise product".
Signature · 1 line
pw-bot: cr
Quoted 12 lines · Jakub Kicinski
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) · line 3216
Quoted 8 lines · On Tue, 22 Oct 2024 18:27:34 -0700 Rosen Penev wrote:
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c +2
-2@@ -3220,13 +3212,13 @@ static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) start =0 ; else start =4 ; -memcpy (buf, bnx2x_tests_str_arr + start, -ETH_GSTRING_LEN *BNX2X_NUM_TESTS (bp)); +for (i = start; i <BNX2X_NUM_TESTS (bp); i++) +ethtool_puts (&buf, bnx2x_tests_str_arr[i]);I don't think this is equivalent.
What's wrong here?
Quoted 6 lines
Also, please split bnx2x to a separate patch, the other drivers in this patch IIUC are small embedded ones, the bnx2x is an "enterprise product".
--
pw-bot: cr
Quoted 13 lines · Rosen Penev
Quoted 12 lines · Jakub Kicinski
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) · line 3216
Quoted 8 lines · On Tue, 22 Oct 2024 18:27:34 -0700 Rosen Penev wrote:
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c +2
-2@@ -3220,13 +3212,13 @@ static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) start =0 ; else start =4 ; -memcpy (buf, bnx2x_tests_str_arr + start, -ETH_GSTRING_LEN *BNX2X_NUM_TESTS (bp)); +for (i = start; i <BNX2X_NUM_TESTS (bp); i++) +ethtool_puts (&buf, bnx2x_tests_str_arr[i]);I don't think this is equivalent.
Quoted 1 line
What's wrong here?
I was trying to figure that out too...
I guess the memcpy does everything all at once and this does it via iteration...?
memcpy would actually result in copying the padding between strings in the bnx2x_tests_str_arr, while the ethtool_puts turns into strscpy which doesn't pad the tail of the buffer with zeros?
Quoted 6 lines
Quoted 6 lines
Also, please split bnx2x to a separate patch, the other drivers in this patch IIUC are small embedded ones, the bnx2x is an "enterprise product".
--
pw-bot: cr
Quoted 19 lines · Jacob Keller
Quoted 13 lines · Rosen Penev
Quoted 12 lines · Jakub Kicinski
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) · line 3216
Quoted 8 lines · On Tue, 22 Oct 2024 18:27:34 -0700 Rosen Penev wrote:
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c +2
-2@@ -3220,13 +3212,13 @@ static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) start =0 ; else start =4 ; -memcpy (buf, bnx2x_tests_str_arr + start, -ETH_GSTRING_LEN *BNX2X_NUM_TESTS (bp)); +for (i = start; i <BNX2X_NUM_TESTS (bp); i++) +ethtool_puts (&buf, bnx2x_tests_str_arr[i]);I don't think this is equivalent.
Quoted 1 line
What's wrong here?
Quoted 8 lines
I was trying to figure that out too...
I guess the memcpy does everything all at once and this does it via iteration...?
memcpy would actually result in copying the padding between strings in the
bnx2x_tests_str_arr, while theethtool_putsturns into strscpy which doesn't pad the tail of the buffer with zeros?
I'll remove the change in the next version.
Still doesn't make much sense.
Quoted 8 lines
Quoted 7 lines
Quoted 7 lines
Also, please split bnx2x to a separate patch, the other drivers in this patch IIUC are small embedded ones, the bnx2x is an "enterprise product".
--
pw-bot: cr
Jakub Kicinski
maintainerQuoted 7 lines · On Tue, 29 Oct 2024 16:43:15 -0700 Rosen Penev wrote:
Quoted 6 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) · line 3216
Quoted 4 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c +2
-2-memcpy (buf, bnx2x_tests_str_arr + start, -ETH_GSTRING_LEN *BNX2X_NUM_TESTS (bp)); +for (i = start; i <BNX2X_NUM_TESTS (bp); i++) +ethtool_puts (&buf, bnx2x_tests_str_arr[i]);I don't think this is equivalent.
What's wrong here?
We used to copy ETH_GSTRING_LEN * BNX2X_NUM_TESTS(bp)
but i will no only go from start to BNX2X_NUM_TESTS(bp)
IOW the copied length is ETH_GSTRING_LEN * (BNX2X_NUM_TESTS(bp) - start) No?
Quoted 6 lines · Jakub Kicinski
Quoted 5 lines · On Tue, 29 Oct 2024 16:43:15 -0700 Rosen Penev wrote:
Quoted 5 lines
Quoted 4 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c +2
-2-memcpy (buf, bnx2x_tests_str_arr + start, -ETH_GSTRING_LEN *BNX2X_NUM_TESTS (bp)); +for (i = start; i <BNX2X_NUM_TESTS (bp); i++) +ethtool_puts (&buf, bnx2x_tests_str_arr[i]);
Quoted 7 lines
Quoted 2 lines
Quoted 1 line
I don't think this is equivalent.
What's wrong here?
We used to copy
ETH_GSTRING_LEN*BNX2X_NUM_TESTS(bp)
but i will no only go from start toBNX2X_NUM_TESTS(bp)
IOW the copied length isETH_GSTRING_LEN* (BNX2X_NUM_TESTS(bp)- start) No?
Hmm. Yea that's right. I'm guessing BNX2X_NUM_TESTS(bp) changes the number of tests based on what start would be...
Probably we could use a static size of the string array instead of BNX2X_NUM_TESTS(bp), and that would fix things, but this specific change needs more careful review of the surrounding code.
Quoted 13 lines · Jacob Keller
Quoted 9 lines · Jakub Kicinski
Quoted 7 lines · On Tue, 29 Oct 2024 16:43:15 -0700 Rosen Penev wrote:
Quoted 6 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c static void bnx2x_get_strings(struct net_device *dev, u32 stringset, u8 *buf) · line 3216
Quoted 4 lines
drivers/net/ethernet/broadcom/bnx2x/bnx2x_ethtool.c +2
-2-memcpy (buf, bnx2x_tests_str_arr + start, -ETH_GSTRING_LEN *BNX2X_NUM_TESTS (bp)); +for (i = start; i <BNX2X_NUM_TESTS (bp); i++) +ethtool_puts (&buf, bnx2x_tests_str_arr[i]);I don't think this is equivalent.
What's wrong here?
Quoted 7 lines
Quoted 4 lines
We used to copy
ETH_GSTRING_LEN*BNX2X_NUM_TESTS(bp)
but i will no only go from start toBNX2X_NUM_TESTS(bp)
IOW the copied length isETH_GSTRING_LEN* (BNX2X_NUM_TESTS(bp)- start) No?Hmm. Yea that's right. I'm guessing
BNX2X_NUM_TESTS(bp)changes the number of tests based on what start would be...
makes sense now.
Loop iteration variable should be ARRAY_SIZE(bnx2x_tests_str_arr), which is BNX2X_NUM_TESTS_SF.
Quoted 4 lines
Probably we could use a static size of the string array instead of
BNX2X_NUM_TESTS(bp), and that would fix things, but this specific change needs more careful review of the surrounding code.