Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net: macb: use ethtool_sprintf to fill ethtool stats strings

The RISC-V toolchain triggers a stringop-truncation warning when using
snprintf() with a fixed ETH_GSTRING_LEN (32 bytes) buffer.

Convert the driver to use the modern ethtool_sprintf() API from
linux/ethtool.h. This removes the need for manual snprintf() and
memcpy() calls, handles the 32-byte padding automatically, and
simplifies the logic by removing manual pointer arithmetic.

Suggested-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Signed-off-by: Sean Chang <seanwascoding@gmail.com>
Link: https://patch.msgid.link/20260302142931.49108-1-seanwascoding@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

authored by

Sean Chang and committed by
Jakub Kicinski
acd338ba 39feb171

+2 -6
+2 -6
drivers/net/ethernet/cadence/macb_main.c
··· 3161 3161 3162 3162 static void gem_get_ethtool_strings(struct net_device *dev, u32 sset, u8 *p) 3163 3163 { 3164 - char stat_string[ETH_GSTRING_LEN]; 3165 3164 struct macb *bp = netdev_priv(dev); 3166 3165 struct macb_queue *queue; 3167 3166 unsigned int i; ··· 3173 3174 ETH_GSTRING_LEN); 3174 3175 3175 3176 for (q = 0, queue = bp->queues; q < bp->num_queues; ++q, ++queue) { 3176 - for (i = 0; i < QUEUE_STATS_LEN; i++, p += ETH_GSTRING_LEN) { 3177 - snprintf(stat_string, ETH_GSTRING_LEN, "q%d_%s", 3178 - q, queue_statistics[i].stat_string); 3179 - memcpy(p, stat_string, ETH_GSTRING_LEN); 3180 - } 3177 + for (i = 0; i < QUEUE_STATS_LEN; i++) 3178 + ethtool_sprintf(&p, "q%u_%s", q, queue_statistics[i].stat_string); 3181 3179 } 3182 3180 break; 3183 3181 }