diff mbox series

RDMA/usnic: Suppress a compiler warning

Message ID 20180723221039.11887-1-bart.vanassche@wdc.com (mailing list archive)
State Superseded
Headers show
Series RDMA/usnic: Suppress a compiler warning | expand

Commit Message

Bart Van Assche July 23, 2018, 10:10 p.m. UTC
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@wdc.com>
Cc: Christian Benvenuti <benve@cisco.com>
---
 drivers/infiniband/hw/usnic/usnic_fwd.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

Comments

Jason Gunthorpe July 23, 2018, 10:21 p.m. UTC | #1
On Mon, Jul 23, 2018 at 03:10:39PM -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@wdc.com>
> Cc: Christian Benvenuti <benve@cisco.com>
>  drivers/infiniband/hw/usnic/usnic_fwd.c | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/drivers/infiniband/hw/usnic/usnic_fwd.c b/drivers/infiniband/hw/usnic/usnic_fwd.c
> index 995a26b65156..bd17220e341b 100644
> +++ b/drivers/infiniband/hw/usnic/usnic_fwd.c
> @@ -92,8 +92,7 @@ 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);
> +	strncpy(ufdev->name, ufdev->netdev->name, sizeof(ufdev->name) - 1);

The -1 is sure strange netdev->name is always NULL terminated, no
reason for the ufdev->name size to be +1'd.. Right?

Maybe this:

 BUILD_BUG_ON(sizeof(ufdev->name) != sizeof(ufdev->netdev->name));
 strcpy(ufdev->name, ufdev->netdev->name);

Which seems to capture the intention

Jason
--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox series

Patch

diff --git a/drivers/infiniband/hw/usnic/usnic_fwd.c b/drivers/infiniband/hw/usnic/usnic_fwd.c
index 995a26b65156..bd17220e341b 100644
--- a/drivers/infiniband/hw/usnic/usnic_fwd.c
+++ b/drivers/infiniband/hw/usnic/usnic_fwd.c
@@ -92,8 +92,7 @@  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);
+	strncpy(ufdev->name, ufdev->netdev->name, sizeof(ufdev->name) - 1);
 
 	return ufdev;
 }