scsi: bfa: convert to strlcpy/strlcat
authorArnd Bergmann <arnd@arndb.de>
Mon, 4 Dec 2017 14:47:00 +0000 (15:47 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 8 Dec 2018 12:03:35 +0000 (13:03 +0100)
commit 8c5a50e8e7ad812a62f7ccf28d9a5e74fddf3000 upstream.

The bfa driver has a number of real issues with string termination
that gcc-8 now points out:

drivers/scsi/bfa/bfad_bsg.c: In function 'bfad_iocmd_port_get_attr':
drivers/scsi/bfa/bfad_bsg.c:320:9: error: argument to 'sizeof' in 'strncpy' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
drivers/scsi/bfa/bfa_fcs.c: In function 'bfa_fcs_fabric_psymb_init':
drivers/scsi/bfa/bfa_fcs.c:775:9: error: argument to 'sizeof' in 'strncat' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
drivers/scsi/bfa/bfa_fcs.c:781:9: error: argument to 'sizeof' in 'strncat' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
drivers/scsi/bfa/bfa_fcs.c:788:9: error: argument to 'sizeof' in 'strncat' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
drivers/scsi/bfa/bfa_fcs.c:801:10: error: argument to 'sizeof' in 'strncat' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
drivers/scsi/bfa/bfa_fcs.c:808:10: error: argument to 'sizeof' in 'strncat' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
drivers/scsi/bfa/bfa_fcs.c: In function 'bfa_fcs_fabric_nsymb_init':
drivers/scsi/bfa/bfa_fcs.c:837:10: error: argument to 'sizeof' in 'strncat' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
drivers/scsi/bfa/bfa_fcs.c:844:10: error: argument to 'sizeof' in 'strncat' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
drivers/scsi/bfa/bfa_fcs.c:852:10: error: argument to 'sizeof' in 'strncat' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
drivers/scsi/bfa/bfa_fcs.c: In function 'bfa_fcs_fabric_psymb_init':
drivers/scsi/bfa/bfa_fcs.c:778:2: error: 'strncat' output may be truncated copying 10 bytes from a string of length 63 [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcs.c:784:2: error: 'strncat' output may be truncated copying 30 bytes from a string of length 63 [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcs.c:803:3: error: 'strncat' output may be truncated copying 44 bytes from a string of length 63 [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcs.c:811:3: error: 'strncat' output may be truncated copying 16 bytes from a string of length 63 [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcs.c: In function 'bfa_fcs_fabric_nsymb_init':
drivers/scsi/bfa/bfa_fcs.c:840:2: error: 'strncat' output may be truncated copying 10 bytes from a string of length 63 [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcs.c:847:2: error: 'strncat' output may be truncated copying 30 bytes from a string of length 63 [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcs_lport.c: In function 'bfa_fcs_fdmi_get_hbaattr':
drivers/scsi/bfa/bfa_fcs_lport.c:2657:10: error: argument to 'sizeof' in 'strncat' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
drivers/scsi/bfa/bfa_fcs_lport.c:2659:11: error: argument to 'sizeof' in 'strncat' call is the same expression as the source; did you mean to use the size of the destination? [-Werror=sizeof-pointer-memaccess]
drivers/scsi/bfa/bfa_fcs_lport.c: In function 'bfa_fcs_lport_ms_gmal_response':
drivers/scsi/bfa/bfa_fcs_lport.c:3232:5: error: 'strncpy' output may be truncated copying 16 bytes from a string of length 247 [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcs_lport.c: In function 'bfa_fcs_lport_ns_send_rspn_id':
drivers/scsi/bfa/bfa_fcs_lport.c:4670:3: error: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcs_lport.c:4682:3: error: 'strncat' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcs_lport.c: In function 'bfa_fcs_lport_ns_util_send_rspn_id':
drivers/scsi/bfa/bfa_fcs_lport.c:5206:3: error: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcs_lport.c:5215:3: error: 'strncat' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcs_lport.c: In function 'bfa_fcs_fdmi_get_portattr':
drivers/scsi/bfa/bfa_fcs_lport.c:2751:2: error: 'strncpy' specified bound 128 equals destination size [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcbuild.c: In function 'fc_rspnid_build':
drivers/scsi/bfa/bfa_fcbuild.c:1254:2: error: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]
drivers/scsi/bfa/bfa_fcbuild.c:1253:25: note: length computed here
drivers/scsi/bfa/bfa_fcbuild.c: In function 'fc_rsnn_nn_build':
drivers/scsi/bfa/bfa_fcbuild.c:1275:2: error: 'strncpy' output truncated before terminating nul copying as many bytes from a string as its length [-Werror=stringop-truncation]

In most cases, this can be addressed by correctly calling strlcpy and
strlcat instead of strncpy/strncat, with the size of the destination
buffer as the last argument.

For consistency, I'm changing the other callers of strncpy() in this
driver the same way.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de>
Acked-by: Sudarsana Kalluru <Sudarsana.Kalluru@cavium.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/scsi/bfa/bfa_fcbuild.c
drivers/scsi/bfa/bfa_fcs.c
drivers/scsi/bfa/bfa_fcs_lport.c
drivers/scsi/bfa/bfa_ioc.c
drivers/scsi/bfa/bfa_svc.c
drivers/scsi/bfa/bfad.c
drivers/scsi/bfa/bfad_attr.c
drivers/scsi/bfa/bfad_bsg.c

index b8dadc9cc9935cb5c8b07c4c66627728b704b873..d3b00a475aebb766876143585b878184dfa1c882 100644 (file)
@@ -1250,8 +1250,8 @@ fc_rspnid_build(struct fchs_s *fchs, void *pyld, u32 s_id, u16 ox_id,
        memset(rspnid, 0, sizeof(struct fcgs_rspnid_req_s));
 
        rspnid->dap = s_id;
-       rspnid->spn_len = (u8) strlen((char *)name);
-       strncpy((char *)rspnid->spn, (char *)name, rspnid->spn_len);
+       strlcpy(rspnid->spn, name, sizeof(rspnid->spn));
+       rspnid->spn_len = (u8) strlen(rspnid->spn);
 
        return sizeof(struct fcgs_rspnid_req_s) + sizeof(struct ct_hdr_s);
 }
@@ -1271,8 +1271,8 @@ fc_rsnn_nn_build(struct fchs_s *fchs, void *pyld, u32 s_id,
        memset(rsnn_nn, 0, sizeof(struct fcgs_rsnn_nn_req_s));
 
        rsnn_nn->node_name = node_name;
-       rsnn_nn->snn_len = (u8) strlen((char *)name);
-       strncpy((char *)rsnn_nn->snn, (char *)name, rsnn_nn->snn_len);
+       strlcpy(rsnn_nn->snn, name, sizeof(rsnn_nn->snn));
+       rsnn_nn->snn_len = (u8) strlen(rsnn_nn->snn);
 
        return sizeof(struct fcgs_rsnn_nn_req_s) + sizeof(struct ct_hdr_s);
 }
index 4aa61e20e82d71b3072c8ce4a96ee2a7f0eb385c..932feb0ed4da1e0d0e5846b302342ef2ad2e008a 100644 (file)
@@ -769,23 +769,23 @@ bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
        bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
 
        /* Model name/number */
-       strncpy((char *)&port_cfg->sym_name, model,
-               BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
-       strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-               sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+       strlcpy(port_cfg->sym_name.symname, model,
+               BFA_SYMNAME_MAXLEN);
+       strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
+               BFA_SYMNAME_MAXLEN);
 
        /* Driver Version */
-       strncat((char *)&port_cfg->sym_name, (char *)driver_info->version,
-               BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
-       strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-               sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+       strlcat(port_cfg->sym_name.symname, driver_info->version,
+               BFA_SYMNAME_MAXLEN);
+       strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
+               BFA_SYMNAME_MAXLEN);
 
        /* Host machine name */
-       strncat((char *)&port_cfg->sym_name,
-               (char *)driver_info->host_machine_name,
-               BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
-       strncat((char *)&port_cfg->sym_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-               sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+       strlcat(port_cfg->sym_name.symname,
+               driver_info->host_machine_name,
+               BFA_SYMNAME_MAXLEN);
+       strlcat(port_cfg->sym_name.symname, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
+               BFA_SYMNAME_MAXLEN);
 
        /*
         * Host OS Info :
@@ -793,24 +793,24 @@ bfa_fcs_fabric_psymb_init(struct bfa_fcs_fabric_s *fabric)
         * OS name string and instead copy the entire OS info string (64 bytes).
         */
        if (driver_info->host_os_patch[0] == '\0') {
-               strncat((char *)&port_cfg->sym_name,
-                       (char *)driver_info->host_os_name,
-                       BFA_FCS_OS_STR_LEN);
-               strncat((char *)&port_cfg->sym_name,
+               strlcat(port_cfg->sym_name.symname,
+                       driver_info->host_os_name,
+                       BFA_SYMNAME_MAXLEN);
+               strlcat(port_cfg->sym_name.symname,
                        BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-                       sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+                       BFA_SYMNAME_MAXLEN);
        } else {
-               strncat((char *)&port_cfg->sym_name,
-                       (char *)driver_info->host_os_name,
-                       BFA_FCS_PORT_SYMBNAME_OSINFO_SZ);
-               strncat((char *)&port_cfg->sym_name,
+               strlcat(port_cfg->sym_name.symname,
+                       driver_info->host_os_name,
+                       BFA_SYMNAME_MAXLEN);
+               strlcat(port_cfg->sym_name.symname,
                        BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-                       sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+                       BFA_SYMNAME_MAXLEN);
 
                /* Append host OS Patch Info */
-               strncat((char *)&port_cfg->sym_name,
-                       (char *)driver_info->host_os_patch,
-                       BFA_FCS_PORT_SYMBNAME_OSPATCH_SZ);
+               strlcat(port_cfg->sym_name.symname,
+                       driver_info->host_os_patch,
+                       BFA_SYMNAME_MAXLEN);
        }
 
        /* null terminate */
@@ -830,26 +830,26 @@ bfa_fcs_fabric_nsymb_init(struct bfa_fcs_fabric_s *fabric)
        bfa_ioc_get_adapter_model(&fabric->fcs->bfa->ioc, model);
 
        /* Model name/number */
-       strncpy((char *)&port_cfg->node_sym_name, model,
-               BFA_FCS_PORT_SYMBNAME_MODEL_SZ);
-       strncat((char *)&port_cfg->node_sym_name,
+       strlcpy(port_cfg->node_sym_name.symname, model,
+               BFA_SYMNAME_MAXLEN);
+       strlcat(port_cfg->node_sym_name.symname,
                        BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-                       sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+                       BFA_SYMNAME_MAXLEN);
 
        /* Driver Version */
-       strncat((char *)&port_cfg->node_sym_name, (char *)driver_info->version,
-               BFA_FCS_PORT_SYMBNAME_VERSION_SZ);
-       strncat((char *)&port_cfg->node_sym_name,
+       strlcat(port_cfg->node_sym_name.symname, (char *)driver_info->version,
+               BFA_SYMNAME_MAXLEN);
+       strlcat(port_cfg->node_sym_name.symname,
                        BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-                       sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+                       BFA_SYMNAME_MAXLEN);
 
        /* Host machine name */
-       strncat((char *)&port_cfg->node_sym_name,
-               (char *)driver_info->host_machine_name,
-               BFA_FCS_PORT_SYMBNAME_MACHINENAME_SZ);
-       strncat((char *)&port_cfg->node_sym_name,
+       strlcat(port_cfg->node_sym_name.symname,
+               driver_info->host_machine_name,
+               BFA_SYMNAME_MAXLEN);
+       strlcat(port_cfg->node_sym_name.symname,
                        BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-                       sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
+                       BFA_SYMNAME_MAXLEN);
 
        /* null terminate */
        port_cfg->node_sym_name.symname[BFA_SYMNAME_MAXLEN - 1] = 0;
index 638c0a2857f79d678a54f2a8a9c8ed7edbeeeb6f..b4f2c1d8742e8a8276f4de6bc930bf6c7b5fcf44 100644 (file)
@@ -2642,10 +2642,10 @@ bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
        bfa_ioc_get_adapter_fw_ver(&port->fcs->bfa->ioc,
                                        hba_attr->fw_version);
 
-       strncpy(hba_attr->driver_version, (char *)driver_info->version,
+       strlcpy(hba_attr->driver_version, (char *)driver_info->version,
                sizeof(hba_attr->driver_version));
 
-       strncpy(hba_attr->os_name, driver_info->host_os_name,
+       strlcpy(hba_attr->os_name, driver_info->host_os_name,
                sizeof(hba_attr->os_name));
 
        /*
@@ -2653,23 +2653,23 @@ bfa_fcs_fdmi_get_hbaattr(struct bfa_fcs_lport_fdmi_s *fdmi,
         * to the os name along with a separator
         */
        if (driver_info->host_os_patch[0] != '\0') {
-               strncat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
-                       sizeof(BFA_FCS_PORT_SYMBNAME_SEPARATOR));
-               strncat(hba_attr->os_name, driver_info->host_os_patch,
-                               sizeof(driver_info->host_os_patch));
+               strlcat(hba_attr->os_name, BFA_FCS_PORT_SYMBNAME_SEPARATOR,
+                       sizeof(hba_attr->os_name));
+               strlcat(hba_attr->os_name, driver_info->host_os_patch,
+                               sizeof(hba_attr->os_name));
        }
 
        /* Retrieve the max frame size from the port attr */
        bfa_fcs_fdmi_get_portattr(fdmi, &fcs_port_attr);
        hba_attr->max_ct_pyld = fcs_port_attr.max_frm_size;
 
-       strncpy(hba_attr->node_sym_name.symname,
+       strlcpy(hba_attr->node_sym_name.symname,
                port->port_cfg.node_sym_name.symname, BFA_SYMNAME_MAXLEN);
        strcpy(hba_attr->vendor_info, "QLogic");
        hba_attr->num_ports =
                cpu_to_be32(bfa_ioc_get_nports(&port->fcs->bfa->ioc));
        hba_attr->fabric_name = port->fabric->lps->pr_nwwn;
-       strncpy(hba_attr->bios_ver, hba_attr->option_rom_ver, BFA_VERSION_LEN);
+       strlcpy(hba_attr->bios_ver, hba_attr->option_rom_ver, BFA_VERSION_LEN);
 
 }
 
@@ -2736,20 +2736,20 @@ bfa_fcs_fdmi_get_portattr(struct bfa_fcs_lport_fdmi_s *fdmi,
        /*
         * OS device Name
         */
-       strncpy(port_attr->os_device_name, (char *)driver_info->os_device_name,
+       strlcpy(port_attr->os_device_name, driver_info->os_device_name,
                sizeof(port_attr->os_device_name));
 
        /*
         * Host name
         */
-       strncpy(port_attr->host_name, (char *)driver_info->host_machine_name,
+       strlcpy(port_attr->host_name, driver_info->host_machine_name,
                sizeof(port_attr->host_name));
 
        port_attr->node_name = bfa_fcs_lport_get_nwwn(port);
        port_attr->port_name = bfa_fcs_lport_get_pwwn(port);
 
-       strncpy(port_attr->port_sym_name.symname,
-               (char *)&bfa_fcs_lport_get_psym_name(port), BFA_SYMNAME_MAXLEN);
+       strlcpy(port_attr->port_sym_name.symname,
+               bfa_fcs_lport_get_psym_name(port).symname, BFA_SYMNAME_MAXLEN);
        bfa_fcs_lport_get_attr(port, &lport_attr);
        port_attr->port_type = cpu_to_be32(lport_attr.port_type);
        port_attr->scos = pport_attr.cos_supported;
@@ -3229,7 +3229,7 @@ bfa_fcs_lport_ms_gmal_response(void *fcsarg, struct bfa_fcxp_s *fcxp,
                                        rsp_str[gmal_entry->len-1] = 0;
 
                                /* copy IP Address to fabric */
-                               strncpy(bfa_fcs_lport_get_fabric_ipaddr(port),
+                               strlcpy(bfa_fcs_lport_get_fabric_ipaddr(port),
                                        gmal_entry->ip_addr,
                                        BFA_FCS_FABRIC_IPADDR_SZ);
                                break;
@@ -4667,21 +4667,13 @@ bfa_fcs_lport_ns_send_rspn_id(void *ns_cbarg, struct bfa_fcxp_s *fcxp_alloced)
                 * to that of the base port.
                 */
 
-               strncpy((char *)psymbl,
-                       (char *) &
-                       (bfa_fcs_lport_get_psym_name
+               strlcpy(symbl,
+                       (char *)&(bfa_fcs_lport_get_psym_name
                         (bfa_fcs_get_base_port(port->fcs))),
-                       strlen((char *) &
-                              bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
-                                                         (port->fcs))));
-
-               /* Ensure we have a null terminating string. */
-               ((char *)psymbl)[strlen((char *) &
-                       bfa_fcs_lport_get_psym_name(bfa_fcs_get_base_port
-                                               (port->fcs)))] = 0;
-               strncat((char *)psymbl,
-                       (char *) &(bfa_fcs_lport_get_psym_name(port)),
-               strlen((char *) &bfa_fcs_lport_get_psym_name(port)));
+                       sizeof(symbl));
+
+               strlcat(symbl, (char *)&(bfa_fcs_lport_get_psym_name(port)),
+                       sizeof(symbl));
        } else {
                psymbl = (u8 *) &(bfa_fcs_lport_get_psym_name(port));
        }
@@ -5173,7 +5165,6 @@ bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg, struct bfa_fcxp_s *fcxp_alloced)
        struct fchs_s fchs;
        struct bfa_fcxp_s *fcxp;
        u8 symbl[256];
-       u8 *psymbl = &symbl[0];
        int len;
 
        /* Avoid sending RSPN in the following states. */
@@ -5203,22 +5194,17 @@ bfa_fcs_lport_ns_util_send_rspn_id(void *cbarg, struct bfa_fcxp_s *fcxp_alloced)
                 * For Vports, we append the vport's port symbolic name
                 * to that of the base port.
                 */
-               strncpy((char *)psymbl, (char *)&(bfa_fcs_lport_get_psym_name
+               strlcpy(symbl, (char *)&(bfa_fcs_lport_get_psym_name
                        (bfa_fcs_get_base_port(port->fcs))),
-                       strlen((char *)&bfa_fcs_lport_get_psym_name(
-                       bfa_fcs_get_base_port(port->fcs))));
-
-               /* Ensure we have a null terminating string. */
-               ((char *)psymbl)[strlen((char *)&bfa_fcs_lport_get_psym_name(
-                bfa_fcs_get_base_port(port->fcs)))] = 0;
+                       sizeof(symbl));
 
-               strncat((char *)psymbl,
+               strlcat(symbl,
                        (char *)&(bfa_fcs_lport_get_psym_name(port)),
-                       strlen((char *)&bfa_fcs_lport_get_psym_name(port)));
+                       sizeof(symbl));
        }
 
        len = fc_rspnid_build(&fchs, bfa_fcxp_get_reqbuf(fcxp),
-                             bfa_fcs_lport_get_fcid(port), 0, psymbl);
+                             bfa_fcs_lport_get_fcid(port), 0, symbl);
 
        bfa_fcxp_send(fcxp, NULL, port->fabric->vf_id, port->lp_tag, BFA_FALSE,
                      FC_CLASS_3, len, &fchs, NULL, NULL, FC_MAX_PDUSZ, 0);
index 256f4afaccf9633ebcd0b74c6efd04c87f4043be..a1a183ece0936ddc65302d98eb45be54f776d5ae 100644 (file)
@@ -2803,7 +2803,7 @@ void
 bfa_ioc_get_adapter_manufacturer(struct bfa_ioc_s *ioc, char *manufacturer)
 {
        memset((void *)manufacturer, 0, BFA_ADAPTER_MFG_NAME_LEN);
-       strncpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
+       strlcpy(manufacturer, BFA_MFG_NAME, BFA_ADAPTER_MFG_NAME_LEN);
 }
 
 void
index e640223bab3c6845fff6d686c7f894c0a900d15e..7356fdec79f560b54dc9b0ff90a920c2b6f8541f 100644 (file)
@@ -350,8 +350,8 @@ bfa_plog_str(struct bfa_plog_s *plog, enum bfa_plog_mid mid,
                lp.eid = event;
                lp.log_type = BFA_PL_LOG_TYPE_STRING;
                lp.misc = misc;
-               strncpy(lp.log_entry.string_log, log_str,
-                       BFA_PL_STRING_LOG_SZ - 1);
+               strlcpy(lp.log_entry.string_log, log_str,
+                       BFA_PL_STRING_LOG_SZ);
                lp.log_entry.string_log[BFA_PL_STRING_LOG_SZ - 1] = '\0';
                bfa_plog_add(plog, &lp);
        }
index 5caf5f3ff642282ee13776e9df9ca9a18f494536..ae37010af50fe999dc2481ae7de656505ed93d1e 100644 (file)
@@ -983,20 +983,20 @@ bfad_start_ops(struct bfad_s *bfad) {
 
        /* Fill the driver_info info to fcs*/
        memset(&driver_info, 0, sizeof(driver_info));
-       strncpy(driver_info.version, BFAD_DRIVER_VERSION,
-               sizeof(driver_info.version) - 1);
+       strlcpy(driver_info.version, BFAD_DRIVER_VERSION,
+               sizeof(driver_info.version));
        if (host_name)
-               strncpy(driver_info.host_machine_name, host_name,
-                       sizeof(driver_info.host_machine_name) - 1);
+               strlcpy(driver_info.host_machine_name, host_name,
+                       sizeof(driver_info.host_machine_name));
        if (os_name)
-               strncpy(driver_info.host_os_name, os_name,
-                       sizeof(driver_info.host_os_name) - 1);
+               strlcpy(driver_info.host_os_name, os_name,
+                       sizeof(driver_info.host_os_name));
        if (os_patch)
-               strncpy(driver_info.host_os_patch, os_patch,
-                       sizeof(driver_info.host_os_patch) - 1);
+               strlcpy(driver_info.host_os_patch, os_patch,
+                       sizeof(driver_info.host_os_patch));
 
-       strncpy(driver_info.os_device_name, bfad->pci_name,
-               sizeof(driver_info.os_device_name) - 1);
+       strlcpy(driver_info.os_device_name, bfad->pci_name,
+               sizeof(driver_info.os_device_name));
 
        /* FCS driver info init */
        spin_lock_irqsave(&bfad->bfad_lock, flags);
index 13db3b7bc8737fc949b68129385c5291f3f7c018..d0a504af5b4f836df14dcbd04908b62a237d2ce0 100644 (file)
@@ -843,7 +843,7 @@ bfad_im_symbolic_name_show(struct device *dev, struct device_attribute *attr,
        char symname[BFA_SYMNAME_MAXLEN];
 
        bfa_fcs_lport_get_attr(&bfad->bfa_fcs.fabric.bport, &port_attr);
-       strncpy(symname, port_attr.port_cfg.sym_name.symname,
+       strlcpy(symname, port_attr.port_cfg.sym_name.symname,
                        BFA_SYMNAME_MAXLEN);
        return snprintf(buf, PAGE_SIZE, "%s\n", symname);
 }
index 1aa46d0763a075e6daf5a8c5a257d73dbd737903..9081a5f93aae447e96187b1d0daf9c308f27850d 100644 (file)
@@ -127,7 +127,7 @@ bfad_iocmd_ioc_get_attr(struct bfad_s *bfad, void *cmd)
 
        /* fill in driver attr info */
        strcpy(iocmd->ioc_attr.driver_attr.driver, BFAD_DRIVER_NAME);
-       strncpy(iocmd->ioc_attr.driver_attr.driver_ver,
+       strlcpy(iocmd->ioc_attr.driver_attr.driver_ver,
                BFAD_DRIVER_VERSION, BFA_VERSION_LEN);
        strcpy(iocmd->ioc_attr.driver_attr.fw_ver,
                iocmd->ioc_attr.adapter_attr.fw_ver);
@@ -315,9 +315,9 @@ bfad_iocmd_port_get_attr(struct bfad_s *bfad, void *cmd)
        iocmd->attr.port_type = port_attr.port_type;
        iocmd->attr.loopback = port_attr.loopback;
        iocmd->attr.authfail = port_attr.authfail;
-       strncpy(iocmd->attr.port_symname.symname,
+       strlcpy(iocmd->attr.port_symname.symname,
                port_attr.port_cfg.sym_name.symname,
-               sizeof(port_attr.port_cfg.sym_name.symname));
+               sizeof(iocmd->attr.port_symname.symname));
 
        iocmd->status = BFA_STATUS_OK;
        return 0;