diff mbox series

mpi3mr: Fix W=1 compilation warnings

Message ID 20210623072153.25758-2-sreekanth.reddy@broadcom.com
State New
Headers show
Series mpi3mr: Fix W=1 compilation warnings | expand

Commit Message

Sreekanth Reddy June 23, 2021, 7:21 a.m. UTC
Fix for below W=1 compilation warning,
'strncpy' output may be truncated copying 16 bytes
 from a string of length 64

Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Sreekanth Reddy <sreekanth.reddy@broadcom.com>
---
 drivers/scsi/mpi3mr/mpi3mr_fw.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

Comments

Martin K. Petersen June 29, 2021, 3:44 a.m. UTC | #1
Sreekanth,

> -	strncpy(drv_info->os_name, utsname()->sysname, sizeof(drv_info->os_name));

> -	drv_info->os_name[sizeof(drv_info->os_name) - 1] = 0;

> -	strncpy(drv_info->os_version, utsname()->release, sizeof(drv_info->os_version));

> -	drv_info->os_version[sizeof(drv_info->os_version) - 1] = 0;

> +	memcpy(drv_info->os_name, utsname()->sysname, sizeof(drv_info->os_name) - 1);

> +	memcpy(drv_info->os_version, utsname()->release, sizeof(drv_info->os_version) - 1);


strscpy()?

-- 
Martin K. Petersen	Oracle Linux Engineering
Sreekanth Reddy June 29, 2021, 2:08 p.m. UTC | #2
On Tue, Jun 29, 2021 at 9:14 AM Martin K. Petersen
<martin.petersen@oracle.com> wrote:
>

>

> Sreekanth,

>

> > -     strncpy(drv_info->os_name, utsname()->sysname, sizeof(drv_info->os_name));

> > -     drv_info->os_name[sizeof(drv_info->os_name) - 1] = 0;

> > -     strncpy(drv_info->os_version, utsname()->release, sizeof(drv_info->os_version));

> > -     drv_info->os_version[sizeof(drv_info->os_version) - 1] = 0;

> > +     memcpy(drv_info->os_name, utsname()->sysname, sizeof(drv_info->os_name) - 1);

> > +     memcpy(drv_info->os_version, utsname()->release, sizeof(drv_info->os_version) - 1);

>

> strscpy()?


Agreed. Posted a new patch using strscpy().

Thanks,
Sreekanth
>

> --

> Martin K. Petersen      Oracle Linux Engineering
diff mbox series

Patch

diff --git a/drivers/scsi/mpi3mr/mpi3mr_fw.c b/drivers/scsi/mpi3mr/mpi3mr_fw.c
index 9eceafca59bc..fd437a19b948 100644
--- a/drivers/scsi/mpi3mr/mpi3mr_fw.c
+++ b/drivers/scsi/mpi3mr/mpi3mr_fw.c
@@ -2608,10 +2608,8 @@  static int mpi3mr_issue_iocinit(struct mpi3mr_ioc *mrioc)
 	}
 	drv_info->information_length = cpu_to_le32(data_len);
 	strncpy(drv_info->driver_signature, "Broadcom", sizeof(drv_info->driver_signature));
-	strncpy(drv_info->os_name, utsname()->sysname, sizeof(drv_info->os_name));
-	drv_info->os_name[sizeof(drv_info->os_name) - 1] = 0;
-	strncpy(drv_info->os_version, utsname()->release, sizeof(drv_info->os_version));
-	drv_info->os_version[sizeof(drv_info->os_version) - 1] = 0;
+	memcpy(drv_info->os_name, utsname()->sysname, sizeof(drv_info->os_name) - 1);
+	memcpy(drv_info->os_version, utsname()->release, sizeof(drv_info->os_version) - 1);
 	strncpy(drv_info->driver_name, MPI3MR_DRIVER_NAME, sizeof(drv_info->driver_name));
 	strncpy(drv_info->driver_version, MPI3MR_DRIVER_VERSION, sizeof(drv_info->driver_version));
 	strncpy(drv_info->driver_release_date, MPI3MR_DRIVER_RELDATE, sizeof(drv_info->driver_release_date));