Skip to content

Commit ba8bcb0

Browse files
hormskuba-moo
authored andcommitted
gve: Use ethtool_sprintf/puts() to fill stats strings
Make use of standard helpers to simplify filling in stats strings. The first two ethtool_puts() changes address the following fortification warnings flagged by W=1 builds with clang-18. (The last ethtool_puts change does not because the warning relates to writing beyond the first element of an array, and gve_gstrings_priv_flags only has one element.) .../fortify-string.h:562:4: warning: call to '__read_overflow2_field' declared with 'warning' attribute: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Wattribute-warning] 562 | __read_overflow2_field(q_size_field, size); | ^ .../fortify-string.h:562:4: warning: call to '__read_overflow2_field' declared with 'warning' attribute: detected read beyond size of field (2nd parameter); maybe use struct_group()? [-Wattribute-warning] Likewise, the same changes resolve the same problems flagged by Smatch. .../gve_ethtool.c:100 gve_get_strings() error: __builtin_memcpy() '*gve_gstrings_main_stats' too small (32 vs 576) .../gve_ethtool.c:120 gve_get_strings() error: __builtin_memcpy() '*gve_gstrings_adminq_stats' too small (32 vs 512) Compile tested only. Reviewed-by: Shailend Chand <[email protected]> Reviewed-by: Larysa Zaremba <[email protected]> Signed-off-by: Simon Horman <[email protected]> Acked-by: Justin Stitt <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent ebb8308 commit ba8bcb0

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

drivers/net/ethernet/google/gve/gve_ethtool.c

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,42 +90,34 @@ static const char gve_gstrings_priv_flags[][ETH_GSTRING_LEN] = {
9090
static void gve_get_strings(struct net_device *netdev, u32 stringset, u8 *data)
9191
{
9292
struct gve_priv *priv = netdev_priv(netdev);
93-
char *s = (char *)data;
93+
u8 *s = (char *)data;
9494
int num_tx_queues;
9595
int i, j;
9696

9797
num_tx_queues = gve_num_tx_queues(priv);
9898
switch (stringset) {
9999
case ETH_SS_STATS:
100-
memcpy(s, *gve_gstrings_main_stats,
101-
sizeof(gve_gstrings_main_stats));
102-
s += sizeof(gve_gstrings_main_stats);
103-
104-
for (i = 0; i < priv->rx_cfg.num_queues; i++) {
105-
for (j = 0; j < NUM_GVE_RX_CNTS; j++) {
106-
snprintf(s, ETH_GSTRING_LEN,
107-
gve_gstrings_rx_stats[j], i);
108-
s += ETH_GSTRING_LEN;
109-
}
110-
}
100+
for (i = 0; i < ARRAY_SIZE(gve_gstrings_main_stats); i++)
101+
ethtool_puts(&s, gve_gstrings_main_stats[i]);
111102

112-
for (i = 0; i < num_tx_queues; i++) {
113-
for (j = 0; j < NUM_GVE_TX_CNTS; j++) {
114-
snprintf(s, ETH_GSTRING_LEN,
115-
gve_gstrings_tx_stats[j], i);
116-
s += ETH_GSTRING_LEN;
117-
}
118-
}
103+
for (i = 0; i < priv->rx_cfg.num_queues; i++)
104+
for (j = 0; j < NUM_GVE_RX_CNTS; j++)
105+
ethtool_sprintf(&s, gve_gstrings_rx_stats[j],
106+
i);
107+
108+
for (i = 0; i < num_tx_queues; i++)
109+
for (j = 0; j < NUM_GVE_TX_CNTS; j++)
110+
ethtool_sprintf(&s, gve_gstrings_tx_stats[j],
111+
i);
112+
113+
for (i = 0; i < ARRAY_SIZE(gve_gstrings_adminq_stats); i++)
114+
ethtool_puts(&s, gve_gstrings_adminq_stats[i]);
119115

120-
memcpy(s, *gve_gstrings_adminq_stats,
121-
sizeof(gve_gstrings_adminq_stats));
122-
s += sizeof(gve_gstrings_adminq_stats);
123116
break;
124117

125118
case ETH_SS_PRIV_FLAGS:
126-
memcpy(s, *gve_gstrings_priv_flags,
127-
sizeof(gve_gstrings_priv_flags));
128-
s += sizeof(gve_gstrings_priv_flags);
119+
for (i = 0; i < ARRAY_SIZE(gve_gstrings_priv_flags); i++)
120+
ethtool_puts(&s, gve_gstrings_priv_flags[i]);
129121
break;
130122

131123
default:

0 commit comments

Comments
 (0)