drivers/infiniband/hw/mlx4/sysfs.c:360:2: warning: 'strncpy' output may be truncated copying 8 bytes from a string of length 31 [-Wstringop-truncation] Signed-off-by: Qian Cai <cai@xxxxxx> --- Changes since v2: * Used strscpy() instead of snprintf() * Removed an unnecessary statement. drivers/infiniband/hw/mlx4/sysfs.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/infiniband/hw/mlx4/sysfs.c b/drivers/infiniband/hw/mlx4/sysfs.c index 752bdd536130..8cf0d2e4c823 100644 --- a/drivers/infiniband/hw/mlx4/sysfs.c +++ b/drivers/infiniband/hw/mlx4/sysfs.c @@ -357,8 +357,7 @@ static void get_name(struct mlx4_ib_dev *dev, char *name, int i, int max) /* pci_name format is: bus:dev:func -> xxxx:yy:zz.n */ strlcpy(name, pci_name(dev->dev->persist->pdev), max); - strncpy(base_name, name, 8); /*till xxxx:yy:*/ - base_name[8] = '\0'; + strscpy(base_name, name, sizeof(base_name)); /*till xxxx:yy:*/ /* with no ARI only 3 last bits are used so when the fn is higher than 8 * need to add it to the dev num, so count in the last number will be * modulo 8 */ -- 2.17.2 (Apple Git-113)