drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c:90:25: warning: 'strncpy' specified bound depends on the length of the source argument

From: kernel test robot
Date: Thu Jun 22 2023 - 01:02:37 EST


Hi Huazhong,

FYI, the error/warning still remains.

tree: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
head: dad9774deaf1cf8e8f7483310dfb2690310193d2
commit: 1556ea9120ffcf4faf7ac6b62a6e28216f260a23 net: hns3: refactor dump mac list of debugfs
date: 2 years, 1 month ago
config: arm64-defconfig (https://download.01.org/0day-ci/archive/20230622/202306221218.d8gEgeI8-lkp@xxxxxxxxx/config)
compiler: aarch64-linux-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230622/202306221218.d8gEgeI8-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/202306221218.d8gEgeI8-lkp@xxxxxxxxx/

All warnings (new ones prefixed by >>):

drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c: In function 'hclge_dbg_fill_content.constprop':
>> drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c:90:25: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation]
90 | strncpy(pos, items[i].name, strlen(items[i].name));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c:88:25: warning: 'strncpy' specified bound depends on the length of the source argument [-Wstringop-truncation]
88 | strncpy(pos, result[i], strlen(result[i]));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


vim +/strncpy +90 drivers/net/ethernet/hisilicon/hns3/hns3pf/hclge_debugfs.c

77
78 static void hclge_dbg_fill_content(char *content, u16 len,
79 const struct hclge_dbg_item *items,
80 const char **result, u16 size)
81 {
82 char *pos = content;
83 u16 i;
84
85 memset(content, ' ', len);
86 for (i = 0; i < size; i++) {
87 if (result)
88 strncpy(pos, result[i], strlen(result[i]));
89 else
> 90 strncpy(pos, items[i].name, strlen(items[i].name));
91 pos += strlen(items[i].name) + items[i].interval;
92 }
93 *pos++ = '\n';
94 *pos++ = '\0';
95 }
96

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