drivers/net/ethernet/aquantia/atlantic/aq_ethtool.c:278:59: warning: '%u' directive output may be truncated writing between 1 and 10 bytes into a region of size 6

kernel test robot
2024-12-20T22:31:24Z

Hi Simon,

FYI, the error/warning still remains.

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: e9b8ffafd20ad21357a789cc58ffaa162b3ad074
commit: 5874e0c9f25661c2faefe4809907166defae3d7f net: atlantic: Avoid warning about potential string truncation
date: 4 months ago
config: x86_64-randconfig-074-20241221 (https://download.01.org/0day-ci/archive/20241221/202412210625.Wl5iFYw5-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-12) 11.3.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241221/202412210625.Wl5iFYw5-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202412210625.Wl5iFYw5-lkp@intel.com/

All warnings (new ones prefixed by >>):

drivers/net/ethernet/aquantia/atlantic/aq_ethtool.c: In function 'aq_ethtool_get_strings':
>> drivers/net/ethernet/aquantia/atlantic/aq_ethtool.c:278:59: warning: '%u' directive output may be truncated writing between 1 and 10 bytes into a region of size 6 [-Wformat-truncation=]
278 | snprintf(tc_string, 8, "TC%u ", tc);
| ^~
drivers/net/ethernet/aquantia/atlantic/aq_ethtool.c:278:56: note: directive argument in the range [0, 4294967294]
278 | snprintf(tc_string, 8, "TC%u ", tc);
| ^~~~~~~
drivers/net/ethernet/aquantia/atlantic/aq_ethtool.c:278:33: note: 'snprintf' output between 5 and 14 bytes into a destination of size 8
278 | snprintf(tc_string, 8, "TC%u ", tc);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

vim +278 drivers/net/ethernet/aquantia/atlantic/aq_ethtool.c

261
262 cfg = aq_nic_get_cfg(nic);
263
264 switch (stringset) {
265 case ETH_SS_STATS: {
266 const int rx_stat_cnt = ARRAY_SIZE(aq_ethtool_queue_rx_stat_names);
267 const int tx_stat_cnt = ARRAY_SIZE(aq_ethtool_queue_tx_stat_names);
268 char tc_string[8];
269 unsigned int tc;
270
271 memset(tc_string, 0, sizeof(tc_string));
272 memcpy(p, aq_ethtool_stat_names,
273 sizeof(aq_ethtool_stat_names));
274 p = p + sizeof(aq_ethtool_stat_names);
275
276 for (tc = 0; tc < cfg->tcs; tc++) {
277 if (cfg->is_qos)
> 278 snprintf(tc_string, 8, "TC%u ", tc);
279
280 for (i = 0; i < cfg->vecs; i++) {
281 for (si = 0; si < rx_stat_cnt; si++) {
282 ethtool_sprintf(&p,
283 aq_ethtool_queue_rx_stat_names[si],
284 tc_string,
285 AQ_NIC_CFG_TCVEC2RING(cfg, tc, i));
286 }
287 for (si = 0; si < tx_stat_cnt; si++) {
288 ethtool_sprintf(&p,
289 aq_ethtool_queue_tx_stat_names[si],
290 tc_string,
291 AQ_NIC_CFG_TCVEC2RING(cfg, tc, i));
292 }
293 }
294 }
295 #if IS_REACHABLE(CONFIG_PTP_1588_CLOCK)
296 if (nic->aq_ptp) {
297 const int rx_ring_cnt = aq_ptp_get_ring_cnt(nic, ATL_RING_RX);
298 const int tx_ring_cnt = aq_ptp_get_ring_cnt(nic, ATL_RING_TX);
299 unsigned int ptp_ring_idx =
300 aq_ptp_ring_idx(nic->aq_nic_cfg.tc_mode);
301
302 snprintf(tc_string, 8, "PTP ");
303
304 for (i = 0; i < max(rx_ring_cnt, tx_ring_cnt); i++) {
305 for (si = 0; si < rx_stat_cnt; si++) {
306 ethtool_sprintf(&p,
307 aq_ethtool_queue_rx_stat_names[si],
308 tc_string,
309 i ? PTP_HWST_RING_IDX : ptp_ring_idx);
310 }
311 if (i >= tx_ring_cnt)
312 continue;
313 for (si = 0; si < tx_stat_cnt; si++) {
314 ethtool_sprintf(&p,
315 aq_ethtool_queue_tx_stat_names[si],
316 tc_string,
317 i ? PTP_HWST_RING_IDX : ptp_ring_idx);
318 }
319 }
320 }
321 #endif
322 #if IS_ENABLED(CONFIG_MACSEC)
323 if (!nic->macsec_cfg)
324 break;
325
326 memcpy(p, aq_macsec_stat_names, sizeof(aq_macsec_stat_names));
327 p = p + sizeof(aq_macsec_stat_names);
328 for (i = 0; i < AQ_MACSEC_MAX_SC; i++) {
329 struct aq_macsec_txsc *aq_txsc;
330
331 if (!(test_bit(i, &nic->macsec_cfg->txsc_idx_busy)))
332 continue;
333
334 for (si = 0;
335 si < ARRAY_SIZE(aq_macsec_txsc_stat_names);
336 si++) {
337 ethtool_sprintf(&p,
338 aq_macsec_txsc_stat_names[si], i);
339 }
340 aq_txsc = &nic->macsec_cfg->aq_txsc[i];
341 for (sa = 0; sa < MACSEC_NUM_AN; sa++) {
342 if (!(test_bit(sa, &aq_txsc->tx_sa_idx_busy)))
343 continue;
344 for (si = 0;
345 si < ARRAY_SIZE(aq_macsec_txsa_stat_names);
346 si++) {
347 ethtool_sprintf(&p,
348 aq_macsec_txsa_stat_names[si],
349 i, sa);
350 }
351 }
352 }
353 for (i = 0; i < AQ_MACSEC_MAX_SC; i++) {
354 struct aq_macsec_rxsc *aq_rxsc;
355
356 if (!(test_bit(i, &nic->macsec_cfg->rxsc_idx_busy)))
357 continue;
358
359 aq_rxsc = &nic->macsec_cfg->aq_rxsc[i];
360 for (sa = 0; sa < MACSEC_NUM_AN; sa++) {
361 if (!(test_bit(sa, &aq_rxsc->rx_sa_idx_busy)))
362 continue;
363 for (si = 0;
364 si < ARRAY_SIZE(aq_macsec_rxsa_stat_names);
365 si++) {
366 ethtool_sprintf(&p,
367 aq_macsec_rxsa_stat_names[si],
368 i, sa);
369 }
370 }
371 }
372 #endif
373 break;
374 }
375 case ETH_SS_PRIV_FLAGS:
376 memcpy(p, aq_ethtool_priv_flag_names,
377 sizeof(aq_ethtool_priv_flag_names));
378 break;
379 }
380 }
381

--
0-DAY CI Kernel Test Service