diff --git a/src/runtime_src/core/common/drv/kds_core.c b/src/runtime_src/core/common/drv/kds_core.c index b5929486098..83a2f17fbd7 100644 --- a/src/runtime_src/core/common/drv/kds_core.c +++ b/src/runtime_src/core/common/drv/kds_core.c @@ -1999,12 +1999,12 @@ int kds_ip_layout2cu_info(struct ip_layout *ip_layout, /* ip_data->m_name format ":", * where instance name is so called CU name. */ - strncpy(kname, ip->m_name, sizeof(kname)); + strscpy(kname, ip->m_name, sizeof(kname)); kname[sizeof(kname)-1] = '\0'; kname_p = &kname[0]; - strncpy(info.kname, strsep(&kname_p, ":"), sizeof(info.kname)); + strscpy(info.kname, strsep(&kname_p, ":"), sizeof(info.kname)); info.kname[sizeof(info.kname)-1] = '\0'; - strncpy(info.iname, strsep(&kname_p, ":"), sizeof(info.iname)); + strscpy(info.iname, strsep(&kname_p, ":"), sizeof(info.iname)); info.iname[sizeof(info.kname)-1] = '\0'; info.addr = ip->m_base_address; @@ -2098,12 +2098,12 @@ int kds_ip_layout2scu_info(struct ip_layout *ip_layout, struct xrt_cu_info cu_in /* ip_data->m_name format ":", * where instance name is so called CU name. */ - strncpy(kname, ip->m_name, sizeof(kname)); + strscpy(kname, ip->m_name, sizeof(kname)); kname[sizeof(kname)-1] = '\0'; kname_p = &kname[0]; - strncpy(info.kname, strsep(&kname_p, ":"), sizeof(info.kname)); + strscpy(info.kname, strsep(&kname_p, ":"), sizeof(info.kname)); info.kname[sizeof(info.kname)-1] = '\0'; - strncpy(info.iname, strsep(&kname_p, ":"), sizeof(info.iname)); + strscpy(info.iname, strsep(&kname_p, ":"), sizeof(info.iname)); info.iname[sizeof(info.kname)-1] = '\0'; info.addr = 0; diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/axigate.c b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/axigate.c index 6d1213c4025..de2ae9fd95d 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/axigate.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/axigate.c @@ -207,7 +207,7 @@ static int axigate_probe(struct platform_device *pdev) len = p ? ((ulong)p - (ulong)res->name) : sizeof(gate->ep_name) - 1; - strncpy(gate->ep_name, res->name, len); + strscpy(gate->ep_name, res->name, len); } gate->base = ioremap_nocache(res->start, diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/feature_rom.c b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/feature_rom.c index 5e4f1bbb3d5..2405df25b33 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/feature_rom.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/feature_rom.c @@ -356,8 +356,8 @@ static void set_vbnv_name(struct platform_device *pdev) snprintf(sh_version, sizeof(sh_version), "%x", idcode); memset(rom->header.VBNVName, 0, sizeof(rom->header.VBNVName)); - strncpy(rom->header.VBNVName, AWS_F2_XDMA_SHELL_NAME, strlen(AWS_F2_XDMA_SHELL_NAME)); - strncpy(&rom->header.VBNVName[32], sh_version, sizeof(sh_version)-1); + strscpy(rom->header.VBNVName, AWS_F2_XDMA_SHELL_NAME, strlen(AWS_F2_XDMA_SHELL_NAME)); + strscpy(&rom->header.VBNVName[32], sh_version, sizeof(sh_version)-1); } static inline bool is_multi_rp(struct feature_rom *rom) @@ -651,7 +651,7 @@ static int init_rom_by_dtb(struct feature_rom *rom) header->FeatureBitMap = UNIFIED_PLATFORM; *(u32 *)header->EntryPointString = MAGIC_NUM; if (XDEV(xdev)->priv.vbnv) - strncpy(header->VBNVName, XDEV(xdev)->priv.vbnv, + strscpy(header->VBNVName, XDEV(xdev)->priv.vbnv, sizeof (header->VBNVName) - 1); /* overwrite if vbnv property exists */ @@ -659,7 +659,7 @@ static int init_rom_by_dtb(struct feature_rom *rom) vbnv = fdt_getprop(XDEV(xdev)->fdt_blob, 0, "vbnv", NULL); if (vbnv) { xocl_xdev_dbg(xdev, "found vbnv prop, %s", vbnv); - strncpy(header->VBNVName, vbnv, + strscpy(header->VBNVName, vbnv, sizeof(header->VBNVName) - 1); for (i = 0; i < strlen(header->VBNVName); i++) if (header->VBNVName[i] == ':' || @@ -754,23 +754,23 @@ static int get_header_from_iomem(struct feature_rom *rom) */ memset(rom->header.EntryPointString, 0, sizeof(rom->header.EntryPointString)); - strncpy(rom->header.EntryPointString, "xlnx", 4); + strscpy(rom->header.EntryPointString, "xlnx", 4); memset(rom->header.FPGAPartName, 0, sizeof(rom->header.FPGAPartName)); - strncpy(rom->header.FPGAPartName, "AWS VU9P", 8); + strscpy(rom->header.FPGAPartName, "AWS VU9P", 8); memset(rom->header.VBNVName, 0, sizeof(rom->header.VBNVName)); if (did == 0xf010) - strncpy(rom->header.VBNVName, + strscpy(rom->header.VBNVName, AWS_F1_XDMA_SHELL_NAME, strlen(AWS_F1_XDMA_SHELL_NAME)); else if (did == 0xf011) - strncpy(rom->header.VBNVName, + strscpy(rom->header.VBNVName, AWS_F1_NODMA_SHELL_NAME, strlen(AWS_F1_NODMA_SHELL_NAME)); else if (did == 0x9048 || did == 0x9248) - strncpy(rom->header.VBNVName, + strscpy(rom->header.VBNVName, AWS_F2_XDMA_SHELL_NAME, strlen(AWS_F2_XDMA_SHELL_NAME)); else - strncpy(rom->header.VBNVName, + strscpy(rom->header.VBNVName, AWS_F1_DYNAMIC_SHELL_NAME, strlen(AWS_F1_DYNAMIC_SHELL_NAME)); rom->header.MajorVersion = 4; rom->header.MinorVersion = 0; diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/icap.c b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/icap.c index de7b1592230..a6b06a373f7 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/icap.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/icap.c @@ -3035,7 +3035,7 @@ static int icap_cache_ps_kernel_axlf_section(const struct axlf *xclbin, (struct soft_kernel *)&blob[header->m_sectionOffset]; char *begin = (char *)sp; - strncpy(pnode->pkn_data[idx].pkd_sym_name, + strscpy(pnode->pkn_data[idx].pkd_sym_name, begin + sp->mpo_symbol_name, PS_KERNEL_NAME_LENGTH - 1); pnode->pkn_data[idx].pkd_num_instances = @@ -4579,7 +4579,7 @@ static ssize_t icap_write_rp(struct file *filp, const char __user *data, icap->rp_bit = NULL; icap->rp_bit_len = 0; - strncpy(icap->rp_vbnv, axlf->m_header.m_platformVBNV, + strscpy(icap->rp_vbnv, axlf->m_header.m_platformVBNV, sizeof(icap->rp_vbnv) - 1); section = xrt_xclbin_get_section_hdr(axlf, PARTITION_METADATA); if (!section) { diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/memory_hbm.c b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/memory_hbm.c index 33a14b5e775..46acb31471b 100755 --- a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/memory_hbm.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/memory_hbm.c @@ -536,7 +536,7 @@ static int mem_hbm_probe(struct platform_device *pdev) left_parentness = strstr(mem_hbm->label.tag, "["); right_parentness = strstr(mem_hbm->label.tag, "]"); digit_len = right_parentness-(1+left_parentness); - strncpy(temp, left_parentness+1, digit_len); + strscpy(temp, left_parentness+1, digit_len); temp[digit_len] = '\0'; if (kstrtoint(temp, 10, &idx) != 0) diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/p2p.c b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/p2p.c index e6217ef2a9d..3be95ce6dbf 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/p2p.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/p2p.c @@ -1307,7 +1307,7 @@ static ssize_t config_store(struct device *dev, struct device_attribute *da, return -ENODEV; mutex_lock(&p2p->p2p_lock); - strncpy(p2p->bank_conf[idx].bank_tag, p_tag, MAX_BANK_TAG_LEN - 1); + strscpy(p2p->bank_conf[idx].bank_tag, p_tag, MAX_BANK_TAG_LEN - 1); p2p->bank_conf[idx].size = sz; p2p->exp_mem_sz = 0; diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/xmc.c b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/xmc.c index 6f431e20a9a..7336d788449 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/xmc.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/xmc.c @@ -1782,7 +1782,7 @@ static int get_temp_by_m_tag(struct xocl_xmc *xmc, char *m_tag) if (!strncmp(m_tag, "DDR", left_parentness-start) || !strncmp(m_tag, "bank", left_parentness-start)) { - strncpy(temp, left_parentness+1, digit_len); + strscpy(temp, left_parentness+1, digit_len); /* assumption, temperature won't higher than 3 digits, or * the temp[digit_len] should be a null character */ temp[digit_len] = '\0'; @@ -4537,7 +4537,7 @@ static int xmc_load_board_info(struct xocl_xmc *xmc) tmp_str = (char *)xocl_icap_get_data(xdev, EXP_BMC_VER); if (tmp_str) { - strncpy(xmc->exp_bmc_ver, tmp_str, + strscpy(xmc->exp_bmc_ver, tmp_str, sizeof(xmc->exp_bmc_ver) - 1); } diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/xmc_u2.c b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/xmc_u2.c index 7cbc550b788..4addbaa9434 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/subdev/xmc_u2.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/subdev/xmc_u2.c @@ -1631,7 +1631,7 @@ static int get_temp_by_m_tag(struct xocl_xmc *xmc, char *m_tag) if (!strncmp(m_tag, "DDR", left_parentness-start) || !strncmp(m_tag, "bank", left_parentness-start)) { - strncpy(temp, left_parentness+1, digit_len); + strscpy(temp, left_parentness+1, digit_len); /* assumption, temperature won't higher than 3 digits, or * the temp[digit_len] should be a null character */ temp[digit_len] = '\0'; @@ -4275,9 +4275,9 @@ static int xmc_load_board_info(struct xocl_xmc *xmc) * with no sc at all. Later, sc version can be loaded * from HW, if there is one available. */ - strncpy(xmc->exp_bmc_ver, tmp_str, + strscpy(xmc->exp_bmc_ver, tmp_str, sizeof(xmc->exp_bmc_ver) - 1); - strncpy(xmc->bmc_ver, tmp_str, + strscpy(xmc->bmc_ver, tmp_str, sizeof(xmc->bmc_ver) - 1); } diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_kds.c b/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_kds.c index 2eb699a0a77..9c8e1d1bc6d 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_kds.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/userpf/xocl_kds.c @@ -1373,7 +1373,7 @@ static int xocl_scu_cfg_cmd(struct xocl_dev *xdev, struct kds_client *client, image->start_cuidx = start_cuidx; image->num_cus = scu_data->pkd_num_instances; - strncpy((char *)image->sk_name, scu_data->pkd_sym_name, + strscpy((char *)image->sk_name, scu_data->pkd_sym_name, PS_KERNEL_NAME_LENGTH - 1); ((char *)image->sk_name)[PS_KERNEL_NAME_LENGTH - 1] = 0; diff --git a/src/runtime_src/core/pcie/driver/linux/xocl/xocl_subdev.c b/src/runtime_src/core/pcie/driver/linux/xocl/xocl_subdev.c index e2a6ab4022f..231d0715e59 100644 --- a/src/runtime_src/core/pcie/driver/linux/xocl/xocl_subdev.c +++ b/src/runtime_src/core/pcie/driver/linux/xocl/xocl_subdev.c @@ -620,7 +620,7 @@ static int __xocl_subdev_create(xdev_handle_t xdev_hdl, if (sdev_info->res[i].name) { res[i].name = subdev->res_name + i * XOCL_SUBDEV_RES_NAME_LEN; - strncpy(subdev->res_name + + strscpy(subdev->res_name + i * XOCL_SUBDEV_RES_NAME_LEN, sdev_info->res[i].name, XOCL_SUBDEV_RES_NAME_LEN - 1); @@ -1435,7 +1435,7 @@ xocl_fetch_dynamic_platform(struct xocl_dev_core *core, dsa_map[i].subdevice == (u16)PCI_ANY_ID)) { *in = dsa_map[i].priv_data; core->priv.vbnv = core->vbnv_cache; - strncpy(core->vbnv_cache, dsa_map[i].vbnv, + strscpy(core->vbnv_cache, dsa_map[i].vbnv, sizeof(core->vbnv_cache) - 1); break; }