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 <rosenp@gmail.com>
(for hellcreek driver)
Reviewed-by: Kurt Kanzenbach <kurt@linutronix.de>
Link: https://patch.msgid.link/20241028044828.1639668-1-rosenp@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Rosen Penev 2024-10-27 21:48:28 -07:00 committed by Jakub Kicinski
parent 574583c30c
commit f12b363887
15 changed files with 64 additions and 103 deletions

View File

@ -989,8 +989,7 @@ void b53_get_strings(struct dsa_switch *ds, int port, u32 stringset,
if (stringset == ETH_SS_STATS) { if (stringset == ETH_SS_STATS) {
for (i = 0; i < mib_size; i++) for (i = 0; i < mib_size; i++)
strscpy(data + i * ETH_GSTRING_LEN, ethtool_puts(&data, mibs[i].name);
mibs[i].name, ETH_GSTRING_LEN);
} else if (stringset == ETH_SS_PHY_STATS) { } else if (stringset == ETH_SS_PHY_STATS) {
phydev = b53_get_phy_device(ds, port); phydev = b53_get_phy_device(ds, port);
if (!phydev) if (!phydev)

View File

@ -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); int cnt = b53_get_sset_count(ds, port, stringset);
b53_get_strings(ds, port, stringset, data); 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, static void bcm_sf2_sw_get_ethtool_stats(struct dsa_switch *ds, int port,

View File

@ -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); int bcm_sf2_cfp_rst(struct bcm_sf2_priv *priv);
void bcm_sf2_cfp_exit(struct dsa_switch *ds); void bcm_sf2_cfp_exit(struct dsa_switch *ds);
int bcm_sf2_cfp_resume(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, void bcm_sf2_cfp_get_strings(struct dsa_switch *ds, int port, u32 stringset,
u32 stringset, uint8_t *data); uint8_t **data);
void bcm_sf2_cfp_get_ethtool_stats(struct dsa_switch *ds, int port, void bcm_sf2_cfp_get_ethtool_stats(struct dsa_switch *ds, int port,
uint64_t *data); uint64_t *data);
int bcm_sf2_cfp_get_sset_count(struct dsa_switch *ds, int port, int sset); int bcm_sf2_cfp_get_sset_count(struct dsa_switch *ds, int port, int sset);

View File

@ -1279,27 +1279,19 @@ static const struct bcm_sf2_cfp_stat {
}, },
}; };
void bcm_sf2_cfp_get_strings(struct dsa_switch *ds, int port, void bcm_sf2_cfp_get_strings(struct dsa_switch *ds, int port, u32 stringset,
u32 stringset, uint8_t *data) uint8_t **data)
{ {
struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds);
unsigned int s = ARRAY_SIZE(bcm_sf2_cfp_stats); unsigned int i, j;
char buf[ETH_GSTRING_LEN];
unsigned int i, j, iter;
if (stringset != ETH_SS_STATS) if (stringset != ETH_SS_STATS)
return; return;
for (i = 1; i < priv->num_cfp_rules; i++) { for (i = 1; i < priv->num_cfp_rules; i++)
for (j = 0; j < s; j++) { for (j = 0; j < ARRAY_SIZE(bcm_sf2_cfp_stats); j++)
snprintf(buf, sizeof(buf), ethtool_sprintf(data, "CFP%03d_%sCntr", i,
"CFP%03d_%sCntr", bcm_sf2_cfp_stats[j].name);
i, bcm_sf2_cfp_stats[j].name);
iter = (i - 1) * s + j;
strscpy(data + iter * ETH_GSTRING_LEN,
buf, ETH_GSTRING_LEN);
}
}
} }
void bcm_sf2_cfp_get_ethtool_stats(struct dsa_switch *ds, int port, void bcm_sf2_cfp_get_ethtool_stats(struct dsa_switch *ds, int port,

View File

@ -121,8 +121,7 @@ static void dsa_loop_get_strings(struct dsa_switch *ds, int port,
return; return;
for (i = 0; i < __DSA_LOOP_CNT_MAX; i++) for (i = 0; i < __DSA_LOOP_CNT_MAX; i++)
memcpy(data + i * ETH_GSTRING_LEN, ethtool_puts(&data, ps->ports[port].mib[i].name);
ps->ports[port].mib[i].name, ETH_GSTRING_LEN);
} }
static void dsa_loop_get_ethtool_stats(struct dsa_switch *ds, int port, static void dsa_loop_get_ethtool_stats(struct dsa_switch *ds, int port,

View File

@ -294,12 +294,8 @@ static void hellcreek_get_strings(struct dsa_switch *ds, int port,
{ {
int i; int i;
for (i = 0; i < ARRAY_SIZE(hellcreek_counter); ++i) { for (i = 0; i < ARRAY_SIZE(hellcreek_counter); ++i)
const struct hellcreek_counter *counter = &hellcreek_counter[i]; ethtool_puts(&data, hellcreek_counter[i].name);
strscpy(data + i * ETH_GSTRING_LEN,
counter->name, ETH_GSTRING_LEN);
}
} }
static int hellcreek_get_sset_count(struct dsa_switch *ds, int port, int sset) static int hellcreek_get_sset_count(struct dsa_switch *ds, int port, int sset)

View File

@ -2112,10 +2112,8 @@ static void ksz_get_strings(struct dsa_switch *ds, int port,
if (stringset != ETH_SS_STATS) if (stringset != ETH_SS_STATS)
return; return;
for (i = 0; i < dev->info->mib_cnt; i++) { for (i = 0; i < dev->info->mib_cnt; i++)
memcpy(buf + i * ETH_GSTRING_LEN, ethtool_puts(&buf, dev->info->mib_names[i].string);
dev->info->mib_names[i].string, ETH_GSTRING_LEN);
}
} }
/** /**

View File

@ -1153,42 +1153,37 @@ static uint64_t _mv88e6xxx_get_ethtool_stat(struct mv88e6xxx_chip *chip,
return value; return value;
} }
static int mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip, static void mv88e6xxx_stats_get_strings(struct mv88e6xxx_chip *chip,
uint8_t *data, int types) uint8_t **data, int types)
{ {
const struct mv88e6xxx_hw_stat *stat; const struct mv88e6xxx_hw_stat *stat;
int i, j; int i;
for (i = 0, j = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) { for (i = 0; i < ARRAY_SIZE(mv88e6xxx_hw_stats); i++) {
stat = &mv88e6xxx_hw_stats[i]; stat = &mv88e6xxx_hw_stats[i];
if (stat->type & types) { if (stat->type & types)
memcpy(data + j * ETH_GSTRING_LEN, stat->string, ethtool_puts(data, stat->string);
ETH_GSTRING_LEN);
j++;
}
} }
return j;
} }
static int mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip, static void mv88e6095_stats_get_strings(struct mv88e6xxx_chip *chip,
uint8_t *data) uint8_t **data)
{ {
return mv88e6xxx_stats_get_strings(chip, data, mv88e6xxx_stats_get_strings(chip, data,
STATS_TYPE_BANK0 | STATS_TYPE_PORT); STATS_TYPE_BANK0 | STATS_TYPE_PORT);
} }
static int mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip, static void mv88e6250_stats_get_strings(struct mv88e6xxx_chip *chip,
uint8_t *data) uint8_t **data)
{ {
return mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0); mv88e6xxx_stats_get_strings(chip, data, STATS_TYPE_BANK0);
} }
static int mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip, static void mv88e6320_stats_get_strings(struct mv88e6xxx_chip *chip,
uint8_t *data) uint8_t **data)
{ {
return mv88e6xxx_stats_get_strings(chip, data, mv88e6xxx_stats_get_strings(chip, data,
STATS_TYPE_BANK0 | STATS_TYPE_BANK1); STATS_TYPE_BANK0 | STATS_TYPE_BANK1);
} }
static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = { static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
@ -1199,21 +1194,18 @@ static const uint8_t *mv88e6xxx_atu_vtu_stats_strings[] = {
"vtu_miss_violation", "vtu_miss_violation",
}; };
static void mv88e6xxx_atu_vtu_get_strings(uint8_t *data) static void mv88e6xxx_atu_vtu_get_strings(uint8_t **data)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++) for (i = 0; i < ARRAY_SIZE(mv88e6xxx_atu_vtu_stats_strings); i++)
strscpy(data + i * ETH_GSTRING_LEN, ethtool_puts(data, mv88e6xxx_atu_vtu_stats_strings[i]);
mv88e6xxx_atu_vtu_stats_strings[i],
ETH_GSTRING_LEN);
} }
static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port, static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
u32 stringset, uint8_t *data) u32 stringset, uint8_t *data)
{ {
struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_chip *chip = ds->priv;
int count = 0;
if (stringset != ETH_SS_STATS) if (stringset != ETH_SS_STATS)
return; return;
@ -1221,15 +1213,12 @@ static void mv88e6xxx_get_strings(struct dsa_switch *ds, int port,
mv88e6xxx_reg_lock(chip); mv88e6xxx_reg_lock(chip);
if (chip->info->ops->stats_get_strings) if (chip->info->ops->stats_get_strings)
count = chip->info->ops->stats_get_strings(chip, data); chip->info->ops->stats_get_strings(chip, &data);
if (chip->info->ops->serdes_get_strings) { if (chip->info->ops->serdes_get_strings)
data += count * ETH_GSTRING_LEN; chip->info->ops->serdes_get_strings(chip, port, &data);
count = chip->info->ops->serdes_get_strings(chip, port, data);
}
data += count * ETH_GSTRING_LEN; mv88e6xxx_atu_vtu_get_strings(&data);
mv88e6xxx_atu_vtu_get_strings(data);
mv88e6xxx_reg_unlock(chip); mv88e6xxx_reg_unlock(chip);
} }

View File

@ -606,7 +606,7 @@ struct mv88e6xxx_ops {
/* Return the number of strings describing statistics */ /* Return the number of strings describing statistics */
int (*stats_get_sset_count)(struct mv88e6xxx_chip *chip); 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, size_t (*stats_get_stat)(struct mv88e6xxx_chip *chip, int port,
const struct mv88e6xxx_hw_stat *stat, const struct mv88e6xxx_hw_stat *stat,
uint64_t *data); uint64_t *data);
@ -633,8 +633,8 @@ struct mv88e6xxx_ops {
/* Statistics from the SERDES interface */ /* Statistics from the SERDES interface */
int (*serdes_get_sset_count)(struct mv88e6xxx_chip *chip, int port); int (*serdes_get_sset_count)(struct mv88e6xxx_chip *chip, int port);
int (*serdes_get_strings)(struct mv88e6xxx_chip *chip, int port, int (*serdes_get_strings)(struct mv88e6xxx_chip *chip, int port,
uint8_t *data); uint8_t **data);
size_t (*serdes_get_stats)(struct mv88e6xxx_chip *chip, int port, size_t (*serdes_get_stats)(struct mv88e6xxx_chip *chip, int port,
uint64_t *data); uint64_t *data);

View File

@ -132,8 +132,8 @@ int mv88e6352_serdes_get_sset_count(struct mv88e6xxx_chip *chip, int port)
return ARRAY_SIZE(mv88e6352_serdes_hw_stats); return ARRAY_SIZE(mv88e6352_serdes_hw_stats);
} }
int mv88e6352_serdes_get_strings(struct mv88e6xxx_chip *chip, int mv88e6352_serdes_get_strings(struct mv88e6xxx_chip *chip, int port,
int port, uint8_t *data) uint8_t **data)
{ {
struct mv88e6352_serdes_hw_stat *stat; struct mv88e6352_serdes_hw_stat *stat;
int err, i; 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++) { for (i = 0; i < ARRAY_SIZE(mv88e6352_serdes_hw_stats); i++) {
stat = &mv88e6352_serdes_hw_stats[i]; stat = &mv88e6352_serdes_hw_stats[i];
memcpy(data + i * ETH_GSTRING_LEN, stat->string, ethtool_puts(data, stat->string);
ETH_GSTRING_LEN);
} }
return ARRAY_SIZE(mv88e6352_serdes_hw_stats); 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); return ARRAY_SIZE(mv88e6390_serdes_hw_stats);
} }
int mv88e6390_serdes_get_strings(struct mv88e6xxx_chip *chip, int mv88e6390_serdes_get_strings(struct mv88e6xxx_chip *chip, int port,
int port, uint8_t *data) uint8_t **data)
{ {
struct mv88e6390_serdes_hw_stat *stat; struct mv88e6390_serdes_hw_stat *stat;
int i; 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++) { for (i = 0; i < ARRAY_SIZE(mv88e6390_serdes_hw_stats); i++) {
stat = &mv88e6390_serdes_hw_stats[i]; stat = &mv88e6390_serdes_hw_stats[i];
memcpy(data + i * ETH_GSTRING_LEN, stat->string, ethtool_puts(data, stat->string);
ETH_GSTRING_LEN);
} }
return ARRAY_SIZE(mv88e6390_serdes_hw_stats); return ARRAY_SIZE(mv88e6390_serdes_hw_stats);
} }

View File

@ -125,13 +125,13 @@ unsigned int mv88e6352_serdes_irq_mapping(struct mv88e6xxx_chip *chip,
unsigned int mv88e6390_serdes_irq_mapping(struct mv88e6xxx_chip *chip, unsigned int mv88e6390_serdes_irq_mapping(struct mv88e6xxx_chip *chip,
int port); int port);
int mv88e6352_serdes_get_sset_count(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 mv88e6352_serdes_get_strings(struct mv88e6xxx_chip *chip, int port,
int port, uint8_t *data); uint8_t **data);
size_t mv88e6352_serdes_get_stats(struct mv88e6xxx_chip *chip, int port, size_t mv88e6352_serdes_get_stats(struct mv88e6xxx_chip *chip, int port,
uint64_t *data); uint64_t *data);
int mv88e6390_serdes_get_sset_count(struct mv88e6xxx_chip *chip, int port); int mv88e6390_serdes_get_sset_count(struct mv88e6xxx_chip *chip, int port);
int mv88e6390_serdes_get_strings(struct mv88e6xxx_chip *chip, int mv88e6390_serdes_get_strings(struct mv88e6xxx_chip *chip, int port,
int port, uint8_t *data); uint8_t **data);
size_t mv88e6390_serdes_get_stats(struct mv88e6xxx_chip *chip, int port, size_t mv88e6390_serdes_get_stats(struct mv88e6xxx_chip *chip, int port,
uint64_t *data); uint64_t *data);

View File

@ -802,10 +802,8 @@ static void a5psw_get_strings(struct dsa_switch *ds, int port, u32 stringset,
if (stringset != ETH_SS_STATS) if (stringset != ETH_SS_STATS)
return; return;
for (u = 0; u < ARRAY_SIZE(a5psw_stats); u++) { for (u = 0; u < ARRAY_SIZE(a5psw_stats); u++)
memcpy(data + u * ETH_GSTRING_LEN, a5psw_stats[u].name, ethtool_puts(&data, a5psw_stats[u].name);
ETH_GSTRING_LEN);
}
} }
static void a5psw_get_ethtool_stats(struct dsa_switch *ds, int port, static void a5psw_get_ethtool_stats(struct dsa_switch *ds, int port,

View File

@ -586,7 +586,6 @@ void sja1105_get_strings(struct dsa_switch *ds, int port,
{ {
struct sja1105_private *priv = ds->priv; struct sja1105_private *priv = ds->priv;
enum sja1105_counter_index max_ctr, i; enum sja1105_counter_index max_ctr, i;
char *p = data;
if (stringset != ETH_SS_STATS) if (stringset != ETH_SS_STATS)
return; return;
@ -597,10 +596,8 @@ void sja1105_get_strings(struct dsa_switch *ds, int port,
else else
max_ctr = __MAX_SJA1105PQRS_PORT_COUNTER; max_ctr = __MAX_SJA1105PQRS_PORT_COUNTER;
for (i = 0; i < max_ctr; i++) { for (i = 0; i < max_ctr; i++)
strscpy(p, sja1105_port_counters[i].name, ETH_GSTRING_LEN); ethtool_puts(&data, sja1105_port_counters[i].name);
p += ETH_GSTRING_LEN;
}
} }
int sja1105_get_sset_count(struct dsa_switch *ds, int port, int sset) int sja1105_get_sset_count(struct dsa_switch *ds, int port, int sset)

View File

@ -91,10 +91,8 @@ static void xrs700x_get_strings(struct dsa_switch *ds, int port,
if (stringset != ETH_SS_STATS) if (stringset != ETH_SS_STATS)
return; return;
for (i = 0; i < ARRAY_SIZE(xrs700x_mibs); i++) { for (i = 0; i < ARRAY_SIZE(xrs700x_mibs); i++)
strscpy(data, xrs700x_mibs[i].name, ETH_GSTRING_LEN); ethtool_puts(&data, xrs700x_mibs[i].name);
data += ETH_GSTRING_LEN;
}
} }
static int xrs700x_get_sset_count(struct dsa_switch *ds, int port, int sset) static int xrs700x_get_sset_count(struct dsa_switch *ds, int port, int sset)

View File

@ -1042,15 +1042,12 @@ static void dsa_user_get_strings(struct net_device *dev,
struct dsa_switch *ds = dp->ds; struct dsa_switch *ds = dp->ds;
if (stringset == ETH_SS_STATS) { if (stringset == ETH_SS_STATS) {
int len = ETH_GSTRING_LEN; ethtool_puts(&data, "tx_packets");
ethtool_puts(&data, "tx_bytes");
strscpy_pad(data, "tx_packets", len); ethtool_puts(&data, "rx_packets");
strscpy_pad(data + len, "tx_bytes", len); ethtool_puts(&data, "rx_bytes");
strscpy_pad(data + 2 * len, "rx_packets", len);
strscpy_pad(data + 3 * len, "rx_bytes", len);
if (ds->ops->get_strings) if (ds->ops->get_strings)
ds->ops->get_strings(ds, dp->index, stringset, ds->ops->get_strings(ds, dp->index, stringset, data);
data + 4 * len);
} else if (stringset == ETH_SS_TEST) { } else if (stringset == ETH_SS_TEST) {
net_selftest_get_strings(data); net_selftest_get_strings(data);
} }