drivers/net/ethernet/ti/cpsw_ethtool.c:244:21: warning: ': ' directive output may be truncated writing 2 bytes into a region of size between 1 and 19

From: kernel test robot
Date: Mon Nov 06 2023 - 11:37:28 EST


tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: d2f51b3516dade79269ff45eae2a7668ae711b25
commit: c24eef283a23b85cbd755265539dc4dbe3fee949 net: ethernet: ti: cpsw: move ethtool func in separate file
date: 4 years, 6 months ago
config: x86_64-buildonly-randconfig-006-20230915 (https://download.01.org/0day-ci/archive/20231107/202311070051.jj6o85Vg-lkp@xxxxxxxxx/config)
compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231107/202311070051.jj6o85Vg-lkp@xxxxxxxxx/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@xxxxxxxxx>
| Closes: https://lore.kernel.org/oe-kbuild-all/202311070051.jj6o85Vg-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

drivers/net/ethernet/ti/cpsw_ethtool.c: In function 'cpsw_add_ch_strings':
>> drivers/net/ethernet/ti/cpsw_ethtool.c:244:21: warning: ': ' directive output may be truncated writing 2 bytes into a region of size between 1 and 19 [-Wformat-truncation=]
"%s DMA chan %ld: %s", rx_dir ? "Rx" : "Tx",
^~
drivers/net/ethernet/ti/cpsw_ethtool.c:243:3: note: 'snprintf' output 16 or more bytes (assuming 34) into a destination of size 32
snprintf(*p, ETH_GSTRING_LEN,
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
"%s DMA chan %ld: %s", rx_dir ? "Rx" : "Tx",
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(long)(i / CPSW_STATS_CH_LEN),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cpsw_gstrings_ch_stats[line].stat_string);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +244 drivers/net/ethernet/ti/cpsw_ethtool.c

233
234 static void cpsw_add_ch_strings(u8 **p, int ch_num, int rx_dir)
235 {
236 int ch_stats_len;
237 int line;
238 int i;
239
240 ch_stats_len = CPSW_STATS_CH_LEN * ch_num;
241 for (i = 0; i < ch_stats_len; i++) {
242 line = i % CPSW_STATS_CH_LEN;
243 snprintf(*p, ETH_GSTRING_LEN,
> 244 "%s DMA chan %ld: %s", rx_dir ? "Rx" : "Tx",
245 (long)(i / CPSW_STATS_CH_LEN),
246 cpsw_gstrings_ch_stats[line].stat_string);
247 *p += ETH_GSTRING_LEN;
248 }
249 }
250

--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki