diff mbox

IB/hfi1: Suppress a compiler warning

Message ID 20180710183216.25450-1-bart.vanassche@wdc.com (mailing list archive)
State Accepted
Delegated to: Jason Gunthorpe
Headers show

Commit Message

Bart Van Assche July 10, 2018, 6:32 p.m. UTC
Avoid that the following compiler warning is reported when building
with gcc 8:

drivers/infiniband/hw/hfi1/verbs.c:1896:2: warning: 'strncpy' output may be truncated copying 64 bytes from a string of length 64 [-Wstringop-truncation]

Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
---
 drivers/infiniband/hw/hfi1/verbs.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Dennis Dalessandro July 11, 2018, 4:59 p.m. UTC | #1
On 7/10/2018 2:32 PM, Bart Van Assche wrote:
> Avoid that the following compiler warning is reported when building
> with gcc 8:
> 
> drivers/infiniband/hw/hfi1/verbs.c:1896:2: warning: 'strncpy' output may be truncated copying 64 bytes from a string of length 64 [-Wstringop-truncation]
> 
> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> ---
>   drivers/infiniband/hw/hfi1/verbs.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/infiniband/hw/hfi1/verbs.c b/drivers/infiniband/hw/hfi1/verbs.c
> index 5cef1224fa9c..47aade71acbb 100644
> --- a/drivers/infiniband/hw/hfi1/verbs.c
> +++ b/drivers/infiniband/hw/hfi1/verbs.c
> @@ -1893,7 +1893,7 @@ int hfi1_register_ib_device(struct hfi1_devdata *dd)
>   	ibdev->process_mad = hfi1_process_mad;
>   	ibdev->get_dev_fw_str = hfi1_get_dev_fw_str;
>   
> -	strncpy(ibdev->node_desc, init_utsname()->nodename,
> +	strlcpy(ibdev->node_desc, init_utsname()->nodename,
>   		sizeof(ibdev->node_desc));
>   
>   	/*
> 

Technically the code is OK as is because the string will be short enough 
but in general this is probably the right thing to do so...

Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
--
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
Jason Gunthorpe July 11, 2018, 8:21 p.m. UTC | #2
On Tue, Jul 10, 2018 at 11:32:16AM -0700, Bart Van Assche wrote:
> Avoid that the following compiler warning is reported when building
> with gcc 8:
> 
> drivers/infiniband/hw/hfi1/verbs.c:1896:2: warning: 'strncpy' output may be truncated copying 64 bytes from a string of length 64 [-Wstringop-truncation]
> 
> Signed-off-by: Bart Van Assche <bart.vanassche@wdc.com>
> Reviewed-by: Dennis Dalessandro <dennis.dalessandro@intel.com>
> ---
>  drivers/infiniband/hw/hfi1/verbs.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Applied to for-next

Thanks,
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

Patch

diff --git a/drivers/infiniband/hw/hfi1/verbs.c b/drivers/infiniband/hw/hfi1/verbs.c
index 5cef1224fa9c..47aade71acbb 100644
--- a/drivers/infiniband/hw/hfi1/verbs.c
+++ b/drivers/infiniband/hw/hfi1/verbs.c
@@ -1893,7 +1893,7 @@  int hfi1_register_ib_device(struct hfi1_devdata *dd)
 	ibdev->process_mad = hfi1_process_mad;
 	ibdev->get_dev_fw_str = hfi1_get_dev_fw_str;
 
-	strncpy(ibdev->node_desc, init_utsname()->nodename,
+	strlcpy(ibdev->node_desc, init_utsname()->nodename,
 		sizeof(ibdev->node_desc));
 
 	/*