Re: [PATCH v3] RDMA/usnic: Suppress a compiler warning

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Jul 24, 2018 at 09:03:49AM +0300, Leon Romanovsky wrote:
> On Mon, Jul 23, 2018 at 03:37:01PM -0700, Bart Van Assche wrote:
> > This patch avoids that the following compiler warning is reported when
> > building with gcc 8 and W=1:
> >
> > drivers/infiniband/hw/usnic/usnic_fwd.c:95:2: warning: 'strncpy' output may be truncated copying 16 bytes from a string of length 20 [-Wstringop-truncation]
> >   strncpy(ufdev->name, netdev_name(ufdev->netdev),
> >   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >     sizeof(ufdev->name) - 1);
> >     ~~~~~~~~~~~~~~~~~~~~~~~~
> >
> > Signed-off-by: Bart Van Assche <bart.vanassche@xxxxxxx>
> > Cc: Christian Benvenuti <benve@xxxxxxxxx>
> > ---
> >  drivers/infiniband/hw/usnic/usnic_fwd.c | 4 ++--
> >  drivers/infiniband/hw/usnic/usnic_fwd.h | 2 +-
> >  2 files changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/infiniband/hw/usnic/usnic_fwd.c b/drivers/infiniband/hw/usnic/usnic_fwd.c
> > index 995a26b65156..7875883621f4 100644
> > --- a/drivers/infiniband/hw/usnic/usnic_fwd.c
> > +++ b/drivers/infiniband/hw/usnic/usnic_fwd.c
> > @@ -92,8 +92,8 @@ struct usnic_fwd_dev *usnic_fwd_dev_alloc(struct pci_dev *pdev)
> >  	ufdev->pdev = pdev;
> >  	ufdev->netdev = pci_get_drvdata(pdev);
> >  	spin_lock_init(&ufdev->lock);
> > -	strncpy(ufdev->name, netdev_name(ufdev->netdev),
> > -			sizeof(ufdev->name) - 1);
> > +	BUILD_BUG_ON(sizeof(ufdev->name) != sizeof(ufdev->netdev->name));
>
> Technically speaking, there is nothing wrong with sizeof(ufdev->name) >
> sizeof(ufdev->netdev->name), but my question is different, are you sure
> that ufdev->netdev->name is null-terminated string?
>
> I think that it is not.

OK, double checked, it is actually yes - null terminated string.

dev_alloc_name -> dev_alloc_name_ns -> strlcpy

Thanks

>
> Thanks
>
> > +	strcpy(ufdev->name, ufdev->netdev->name);
> >
> >  	return ufdev;
> >  }
> > diff --git a/drivers/infiniband/hw/usnic/usnic_fwd.h b/drivers/infiniband/hw/usnic/usnic_fwd.h
> > index 0b2cc4e79707..f0b71d593da5 100644
> > --- a/drivers/infiniband/hw/usnic/usnic_fwd.h
> > +++ b/drivers/infiniband/hw/usnic/usnic_fwd.h
> > @@ -57,7 +57,7 @@ struct usnic_fwd_dev {
> >  	char				mac[ETH_ALEN];
> >  	unsigned int			mtu;
> >  	__be32				inaddr;
> > -	char				name[IFNAMSIZ+1];
> > +	char				name[IFNAMSIZ];
> >  };
> >
> >  struct usnic_fwd_flow {
> > --
> > 2.18.0
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
> > the body of a message to majordomo@xxxxxxxxxxxxxxx
> > More majordomo info at  http://vger.kernel.org/majordomo-info.html


Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux