net: dsa: use ethtool string helpers
Subsystems (10)
Networking Network drivers Networking DSA Marvell 88E6XXX Ethernet switch fabric driver +6 more subsystems
PATCH v4 1/1 net: dsa: use ethtool string helpers
These are the preferred way to copy ethtool strings.
Avoids incrementing pointers all over the place.
Signed-off-by Rosen Penev <[email protected]>
(for hellcreek driver)
Reviewed-by Kurt Kanzenbach <[email protected]>
---
v4: use double pointer parameters for mv88e6xxx
v3: remove curly braces from ksz_common.c
v2: remove curly braces from rzn1_a5psw.c
drivers/net/dsa/b53/b53_common.c | 3 +- drivers/net/dsa/bcm_sf2.c | 4 +- drivers/net/dsa/bcm_sf2.h | 4 +- drivers/net/dsa/bcm_sf2_cfp.c | 22 +++------ drivers/net/dsa/dsa_loop.c | 3 +- drivers/net/dsa/hirschmann/hellcreek.c | 8 +--- drivers/net/dsa/microchip/ksz_common.c | 6 +-- drivers/net/dsa/mv88e6xxx/chip.c | 57 +++++++++-------------- drivers/net/dsa/mv88e6xxx/chip.h | 6 +-- drivers/net/dsa/mv88e6xxx/serdes.c | 14 +++--- drivers/net/dsa/mv88e6xxx/serdes.h | 8 ++-- drivers/net/dsa/rzn1_a5psw.c | 6 +-- drivers/net/dsa/sja1105/sja1105_ethtool.c | 7 +-- drivers/net/dsa/xrs700x/xrs700x.c | 6 +-- net/dsa/user.c | 13 ++---- 15 files changed, 64 insertions(+), 103 deletions(-)
drivers/net/dsa/b53/b53_common.c +1 -2
@@ -989,8 +989,7 @@ void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,if (stringset ==ETH_SS_STATS ) {for (i =0 ; i < mib_size; i++) -strscpy (data + i *ETH_GSTRING_LEN , - mibs[i].name,ETH_GSTRING_LEN ); +ethtool_puts (&data, mibs[i].name); }else if (stringset ==ETH_SS_PHY_STATS ) { phydev =b53_get_phy_device (ds, port);if (!phydev)
drivers/net/dsa/bcm_sf2.c +2 -2
@@ -1183,8 +1183,8 @@ static void bcm_sf2_sw_get_strings(struct dsa_switch *ds, int port,int cnt =b53_get_sset_count (ds, port, stringset);b53_get_strings (ds, port, stringset, data); -bcm_sf2_cfp_get_strings (ds, port, stringset, - data + cnt *ETH_GSTRING_LEN ); + data += cnt *ETH_GSTRING_LEN ; +bcm_sf2_cfp_get_strings (ds, port, stringset, &data); } static void bcm_sf2_sw_get_ethtool_stats(struct dsa_switch *ds, int port,
drivers/net/dsa/bcm_sf2.h +2 -2
@@ -228,8 +228,8 @@ int bcm_sf2_set_rxnfc(struct dsa_switch *ds, int port,int bcm_sf2_cfp_rst (struct bcm_sf2_priv *priv);void bcm_sf2_cfp_exit (struct dsa_switch *ds);int bcm_sf2_cfp_resume (struct dsa_switch *ds); -void bcm_sf2_cfp_get_strings (struct dsa_switch *ds,int port, -u32 stringset,uint8_t *data); +void bcm_sf2_cfp_get_strings (struct dsa_switch *ds,int port,u32 stringset, +uint8_t **data);void bcm_sf2_cfp_get_ethtool_stats (struct dsa_switch *ds,int port,uint64_t *data);int bcm_sf2_cfp_get_sset_count (struct dsa_switch *ds,int port,int sset);
drivers/net/dsa/bcm_sf2_cfp.c +7 -15
@@ -1279,27 +1279,19 @@ static const struct bcm_sf2_cfp_stat { }, }; -void bcm_sf2_cfp_get_strings (struct dsa_switch *ds,int port, -u32 stringset,uint8_t *data) +void bcm_sf2_cfp_get_strings (struct dsa_switch *ds,int port,u32 stringset, +uint8_t **data) {struct bcm_sf2_priv *priv =bcm_sf2_to_priv (ds); -unsigned int s =ARRAY_SIZE (bcm_sf2_cfp_stats); -char buf[ETH_GSTRING_LEN ]; -unsigned int i, j, iter; +unsigned int i, j;if (stringset !=ETH_SS_STATS )return ; -for (i =1 ; i < priv->num_cfp_rules; i++) { -for (j =0 ; j < s; j++) { -snprintf (buf,sizeof (buf), -"CFP%03d_%sCntr" , - i, bcm_sf2_cfp_stats[j].name); - iter = (i -1 ) * s + j; -strscpy (data + iter *ETH_GSTRING_LEN , - buf,ETH_GSTRING_LEN ); - } - } +for (i =1 ; i < priv->num_cfp_rules; i++) +for (j =0 ; j <ARRAY_SIZE (bcm_sf2_cfp_stats); j++) +ethtool_sprintf (data,"CFP%03d_%sCntr" , i, + bcm_sf2_cfp_stats[j].name); } void bcm_sf2_cfp_get_ethtool_stats(struct dsa_switch *ds, int port,
drivers/net/dsa/dsa_loop.c +1 -2
@@ -121,8 +121,7 @@ static void dsa_loop_get_strings(struct dsa_switch *ds, int port,return ;for (i =0 ; i < __DSA_LOOP_CNT_MAX; i++) -memcpy (data + i *ETH_GSTRING_LEN , - ps->ports[port].mib[i].name,ETH_GSTRING_LEN ); +ethtool_puts (&data, ps->ports[port].mib[i].name); } static void dsa_loop_get_ethtool_stats(struct dsa_switch *ds, int port,
drivers/net/dsa/hirschmann/hellcreek.c +2 -6
@@ -294,12 +294,8 @@ static void hellcreek_get_strings(struct dsa_switch *ds, int port, {int i; -for (i =0 ; i <ARRAY_SIZE (hellcreek_counter); ++i) { -const struct hellcreek_counter *counter = &hellcreek_counter[i]; - -strscpy (data + i *ETH_GSTRING_LEN , - counter->name,ETH_GSTRING_LEN ); - } +for (i =0 ; i <ARRAY_SIZE (hellcreek_counter); ++i) +ethtool_puts (&data, hellcreek_counter[i].name); }static int hellcreek_get_sset_count (struct dsa_switch *ds,int port,int sset)
drivers/net/dsa/microchip/ksz_common.c +2 -4
@@ -2112,10 +2112,8 @@ static void ksz_get_strings(struct dsa_switch *ds, int port,if (stringset !=ETH_SS_STATS )return ; -for (i =0 ; i < dev->info->mib_cnt; i++) { -memcpy (buf + i *ETH_GSTRING_LEN , - dev->info->mib_names[i].string,ETH_GSTRING_LEN ); - } +for (i =0 ; i < dev->info->mib_cnt; i++) +ethtool_puts (&buf, dev->info->mib_names[i].string); }/**
drivers/net/dsa/mv88e6xxx/chip.c +23 -34
101 lines not on this page · raw message
drivers/net/dsa/mv88e6xxx/chip.h +3 -3
@@ -606,7 +606,7 @@ struct mv88e6xxx_ops {/* Return the number of strings describing statistics */ int (*stats_get_sset_count)(struct mv88e6xxx_chip *chip); -int (*stats_get_strings)(struct mv88e6xxx_chip *chip,uint8_t *data); +void (*stats_get_strings)(struct mv88e6xxx_chip *chip,uint8_t **data);size_t (*stats_get_stat)(struct mv88e6xxx_chip *chip,int port,const struct mv88e6xxx_hw_stat *stat,uint64_t *data);
@@ -633,8 +633,8 @@ struct mv88e6xxx_ops {/* Statistics from the SERDES interface */ int (*serdes_get_sset_count)(struct mv88e6xxx_chip *chip,int port); -int (*serdes_get_strings)(struct mv88e6xxx_chip *chip,int port, -uint8_t *data); +int (*serdes_get_strings)(struct mv88e6xxx_chip *chip,int port, +uint8_t **data);size_t (*serdes_get_stats)(struct mv88e6xxx_chip *chip,int port,uint64_t *data);
drivers/net/dsa/mv88e6xxx/serdes.c +6 -8
@@ -132,8 +132,8 @@ int mv88e6352_serdes_get_sset_count(struct mv88e6xxx_chip *chip, int port)return ARRAY_SIZE (mv88e6352_serdes_hw_stats); } -int mv88e6352_serdes_get_strings (struct mv88e6xxx_chip *chip, -int port,uint8_t *data) +int mv88e6352_serdes_get_strings (struct mv88e6xxx_chip *chip,int port, +uint8_t **data) {struct mv88e6352_serdes_hw_stat *stat;int err, i;
@@ -144,8 +144,7 @@ int mv88e6352_serdes_get_strings(struct mv88e6xxx_chip *chip,for (i =0 ; i <ARRAY_SIZE (mv88e6352_serdes_hw_stats); i++) { stat = &mv88e6352_serdes_hw_stats[i]; -memcpy (data + i *ETH_GSTRING_LEN , stat->string, -ETH_GSTRING_LEN ); +ethtool_puts (data, stat->string); }return ARRAY_SIZE (mv88e6352_serdes_hw_stats); }
@@ -394,8 +393,8 @@ int mv88e6390_serdes_get_sset_count(struct mv88e6xxx_chip *chip, int port)return ARRAY_SIZE (mv88e6390_serdes_hw_stats); } -int mv88e6390_serdes_get_strings (struct mv88e6xxx_chip *chip, -int port,uint8_t *data) +int mv88e6390_serdes_get_strings (struct mv88e6xxx_chip *chip,int port, +uint8_t **data) {struct mv88e6390_serdes_hw_stat *stat;int i;
@@ -405,8 +404,7 @@ int mv88e6390_serdes_get_strings(struct mv88e6xxx_chip *chip,for (i =0 ; i <ARRAY_SIZE (mv88e6390_serdes_hw_stats); i++) { stat = &mv88e6390_serdes_hw_stats[i]; -memcpy (data + i *ETH_GSTRING_LEN , stat->string, -ETH_GSTRING_LEN ); +ethtool_puts (data, stat->string); }return ARRAY_SIZE (mv88e6390_serdes_hw_stats); }
drivers/net/dsa/mv88e6xxx/serdes.h +4 -4
@@ -125,13 +125,13 @@ unsigned int mv88e6352_serdes_irq_mapping(struct mv88e6xxx_chip *chip,unsigned int mv88e6390_serdes_irq_mapping (struct mv88e6xxx_chip *chip,int port);int mv88e6352_serdes_get_sset_count (struct mv88e6xxx_chip *chip,int port); -int mv88e6352_serdes_get_strings (struct mv88e6xxx_chip *chip, -int port,uint8_t *data); +int mv88e6352_serdes_get_strings (struct mv88e6xxx_chip *chip,int port, +uint8_t **data);size_t mv88e6352_serdes_get_stats (struct mv88e6xxx_chip *chip,int port,uint64_t *data);int mv88e6390_serdes_get_sset_count (struct mv88e6xxx_chip *chip,int port); -int mv88e6390_serdes_get_strings (struct mv88e6xxx_chip *chip, -int port,uint8_t *data); +int mv88e6390_serdes_get_strings (struct mv88e6xxx_chip *chip,int port, +uint8_t **data);size_t mv88e6390_serdes_get_stats (struct mv88e6xxx_chip *chip,int port,uint64_t *data);
drivers/net/dsa/rzn1_a5psw.c +2 -4
@@ -802,10 +802,8 @@ static void a5psw_get_strings(struct dsa_switch *ds, int port, u32 stringset,if (stringset !=ETH_SS_STATS )return ; -for (u =0 ; u <ARRAY_SIZE (a5psw_stats); u++) { -memcpy (data + u *ETH_GSTRING_LEN , a5psw_stats[u].name, -ETH_GSTRING_LEN ); - } +for (u =0 ; u <ARRAY_SIZE (a5psw_stats); u++) +ethtool_puts (&data, a5psw_stats[u].name); } static void a5psw_get_ethtool_stats(struct dsa_switch *ds, int port,
drivers/net/dsa/sja1105/sja1105_ethtool.c +2 -5
@@ -586,7 +586,6 @@ void sja1105_get_strings(struct dsa_switch *ds, int port, {struct sja1105_private *priv = ds->priv;enum sja1105_counter_index max_ctr, i; -char *p = data;if (stringset !=ETH_SS_STATS )return ;
@@ -597,10 +596,8 @@ void sja1105_get_strings(struct dsa_switch *ds, int port,else max_ctr = __MAX_SJA1105PQRS_PORT_COUNTER; -for (i =0 ; i < max_ctr; i++) { -strscpy (p, sja1105_port_counters[i].name,ETH_GSTRING_LEN ); - p +=ETH_GSTRING_LEN ; - } +for (i =0 ; i < max_ctr; i++) +ethtool_puts (&data, sja1105_port_counters[i].name); }int sja1105_get_sset_count (struct dsa_switch *ds,int port,int sset)
drivers/net/dsa/xrs700x/xrs700x.c +2 -4
@@ -91,10 +91,8 @@ static void xrs700x_get_strings(struct dsa_switch *ds, int port,if (stringset !=ETH_SS_STATS )return ; -for (i =0 ; i <ARRAY_SIZE (xrs700x_mibs); i++) { -strscpy (data, xrs700x_mibs[i].name,ETH_GSTRING_LEN ); - data +=ETH_GSTRING_LEN ; - } +for (i =0 ; i <ARRAY_SIZE (xrs700x_mibs); i++) +ethtool_puts (&data, xrs700x_mibs[i].name); }static int xrs700x_get_sset_count (struct dsa_switch *ds,int port,int sset)
net/dsa/user.c +5 -8
@@ -1042,15 +1042,12 @@ static void dsa_user_get_strings(struct net_device *dev,struct dsa_switch *ds = dp->ds;if (stringset ==ETH_SS_STATS ) { -int len =ETH_GSTRING_LEN ; - -strscpy_pad (data,"tx_packets" , len); -strscpy_pad (data + len,"tx_bytes" , len); -strscpy_pad (data +2 * len,"rx_packets" , len); -strscpy_pad (data +3 * len,"rx_bytes" , len); +ethtool_puts (&data,"tx_packets" ); +ethtool_puts (&data,"tx_bytes" ); +ethtool_puts (&data,"rx_packets" ); +ethtool_puts (&data,"rx_bytes" );if (ds->ops->get_strings) - ds->ops->get_strings (ds, dp->index, stringset, - data +4 * len); + ds->ops->get_strings (ds, dp->index, stringset, data); }else if (stringset ==ETH_SS_TEST ) {net_selftest_get_strings (data); }
Signature · 1 line
2.47.0
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net-next.git (main) by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Sun, 27 Oct 2024 21:48:28 -0700 you wrote:
These are the preferred way to copy ethtool strings.
Avoids incrementing pointers all over the place.
Signed-off-by Rosen Penev <[email protected]>(for hellcreek driver)
Reviewed-by Kurt Kanzenbach <[email protected]>[...]
Here is the summary with links:
- [PATCHv4,net-next] net: dsa: use ethtool string helpers
https://git.kernel.org/netdev/net-next/c/f12b363887c7
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html