diff mbox series

[2/3] scsi: pm8001: pm8001_sas: Fix strncpy() warning when space is not left for NUL

Message ID 20201102102544.1018706-2-lee.jones@linaro.org
State New
Headers show
Series [1/3] scsi: arcmsr: arcmsr_hba: Stop __builtin_strncpy complaining about a lack of space for NUL | expand

Commit Message

Lee Jones Nov. 2, 2020, 10:25 a.m. UTC
This string is not NUL terminated.

Fixes the following W=1 kernel build warning(s):

 from drivers/scsi/pm8001/pm8001_sas.c:41:
 In function ‘strncpy’,
 inlined from ‘pm8001_issue_ssp_tmf’ at drivers/scsi/pm8001/pm8001_sas.c:919:2:
 include/linux/string.h:297:30: warning: ‘__builtin_strncpy’ specified bound 8 equals destination size [-Wstringop-truncation]
 297 | #define __underlying_strncpy __builtin_strncpy
 | ^
 include/linux/string.h:307:9: note: in expansion of macro ‘__underlying_strncpy’
 307 | return __underlying_strncpy(p, q, size);
 | ^~~~~~~~~~~~~~~~~~~~

Cc: Jack Wang <jinpu.wang@cloud.ionos.com>
Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
 drivers/scsi/pm8001/pm8001_sas.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Jinpu Wang Nov. 5, 2020, 11:03 a.m. UTC | #1
On Mon, Nov 2, 2020 at 11:25 AM Lee Jones <lee.jones@linaro.org> wrote:
>
> This string is not NUL terminated.
>
> Fixes the following W=1 kernel build warning(s):
>
>  from drivers/scsi/pm8001/pm8001_sas.c:41:
>  In function ‘strncpy’,
>  inlined from ‘pm8001_issue_ssp_tmf’ at drivers/scsi/pm8001/pm8001_sas.c:919:2:
>  include/linux/string.h:297:30: warning: ‘__builtin_strncpy’ specified bound 8 equals destination size [-Wstringop-truncation]
>  297 | #define __underlying_strncpy __builtin_strncpy
>  | ^
>  include/linux/string.h:307:9: note: in expansion of macro ‘__underlying_strncpy’
>  307 | return __underlying_strncpy(p, q, size);
>  | ^~~~~~~~~~~~~~~~~~~~
>
> Cc: Jack Wang <jinpu.wang@cloud.ionos.com>
> Signed-off-by: Lee Jones <lee.jones@linaro.org>
Thanks, Lee!
Acked-by: Jack Wang <jinpu.wang@cloud.ionos.com>
> ---
>  drivers/scsi/pm8001/pm8001_sas.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/scsi/pm8001/pm8001_sas.c b/drivers/scsi/pm8001/pm8001_sas.c
> index 9889bab7d31c1..5edfba3c622b4 100644
> --- a/drivers/scsi/pm8001/pm8001_sas.c
> +++ b/drivers/scsi/pm8001/pm8001_sas.c
> @@ -916,7 +916,7 @@ static int pm8001_issue_ssp_tmf(struct domain_device *dev,
>         if (!(dev->tproto & SAS_PROTOCOL_SSP))
>                 return TMF_RESP_FUNC_ESUPP;
>
> -       strncpy((u8 *)&ssp_task.LUN, lun, 8);
> +       memcpy((u8 *)&ssp_task.LUN, lun, 8);
>         return pm8001_exec_internal_tmf_task(dev, &ssp_task, sizeof(ssp_task),
>                 tmf);
>  }
> --
> 2.25.1
>
diff mbox series

Patch

diff --git a/drivers/scsi/pm8001/pm8001_sas.c b/drivers/scsi/pm8001/pm8001_sas.c
index 9889bab7d31c1..5edfba3c622b4 100644
--- a/drivers/scsi/pm8001/pm8001_sas.c
+++ b/drivers/scsi/pm8001/pm8001_sas.c
@@ -916,7 +916,7 @@  static int pm8001_issue_ssp_tmf(struct domain_device *dev,
 	if (!(dev->tproto & SAS_PROTOCOL_SSP))
 		return TMF_RESP_FUNC_ESUPP;
 
-	strncpy((u8 *)&ssp_task.LUN, lun, 8);
+	memcpy((u8 *)&ssp_task.LUN, lun, 8);
 	return pm8001_exec_internal_tmf_task(dev, &ssp_task, sizeof(ssp_task),
 		tmf);
 }