On 11/15/18 at 12:36 AM, Leon Romanovsky wrote: > On Wed, Nov 14, 2018 at 10:55:48PM -0500, Qian Cai wrote: > > 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] > > strncpy(base_name, name, 8); /*till xxxx:yy:*/ > > ^~~~~~~~~~~~~~~~~~~~~~~~~~~ > > > > Signed-off-by: Qian Cai <cai@xxxxxx> > > --- > > drivers/infiniband/hw/mlx4/sysfs.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/infiniband/hw/mlx4/sysfs.c b/drivers/infiniband/hw/mlx4/sysfs.c > > index 752bdd536130..1fa23c358d01 100644 > > --- a/drivers/infiniband/hw/mlx4/sysfs.c > > +++ b/drivers/infiniband/hw/mlx4/sysfs.c > > @@ -357,7 +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:*/ > > + snprintf(base_name, sizeof(base_name), name); /*till xxxx:yy:*/ > > base_name[8] = '\0'; > > What do you think if we change the two lines below > to be "strscpy(base_name, name, sizeof(base_name)); /*till xxxx:yy:*/" ? Make sense to use a newer API and simper interface. I’ll send a revised patch shortly.