From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 9F40B45C76; Mon, 4 Nov 2024 12:13:06 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E7256410FC; Mon, 4 Nov 2024 12:11:07 +0100 (CET) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) by mails.dpdk.org (Postfix) with ESMTP id 314E440E27 for ; Mon, 4 Nov 2024 12:10:42 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4XhpYV5FM2z1JB6K; Mon, 4 Nov 2024 19:06:06 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id AE5AF1401F3; Mon, 4 Nov 2024 19:10:40 +0800 (CST) Received: from localhost.huawei.com (10.50.165.33) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 4 Nov 2024 19:10:40 +0800 From: Dengdui Huang To: CC: , , , , , , , , , , Subject: [PATCH v5 14/52] bus/fslmc: replace strerror with reentrant version Date: Mon, 4 Nov 2024 19:09:59 +0800 Message-ID: <20241104111037.3632161-15-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241104111037.3632161-1-huangdengdui@huawei.com> References: <20231114082539.1858594-1-huangdengdui@huawei.com> <20241104111037.3632161-1-huangdengdui@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500011.china.huawei.com (7.185.36.84) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The function strerror() is insecure in a multi-thread environment. This patch uses strerror_r() to replace it. Signed-off-by: Dengdui Huang Acked-by: Chengwen Feng Acked-by: Morten Brørup Acked-by: Huisong Li --- drivers/bus/fslmc/fslmc_vfio.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/drivers/bus/fslmc/fslmc_vfio.c b/drivers/bus/fslmc/fslmc_vfio.c index 6981679a2d..b6647dc38d 100644 --- a/drivers/bus/fslmc/fslmc_vfio.c +++ b/drivers/bus/fslmc/fslmc_vfio.c @@ -448,6 +448,7 @@ fslmc_vfio_setup_device(const char *sysfs_base, const char *dev_addr, .argsz = sizeof(group_status) }; int vfio_group_fd, vfio_container_fd, iommu_group_no, ret; + char errmsg[RTE_STRERR_BUFSIZE]; /* get group number */ ret = rte_vfio_get_group_num(sysfs_base, dev_addr, &iommu_group_no); @@ -479,9 +480,11 @@ fslmc_vfio_setup_device(const char *sysfs_base, const char *dev_addr, /* check if the group is viable */ ret = ioctl(vfio_group_fd, VFIO_GROUP_GET_STATUS, &group_status); if (ret) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); DPAA2_BUS_ERR(" %s cannot get group status, " "error %i (%s)", dev_addr, - errno, strerror(errno)); + errno, errmsg); close(vfio_group_fd); rte_vfio_clear_group(vfio_group_fd); return -1; @@ -502,9 +505,11 @@ fslmc_vfio_setup_device(const char *sysfs_base, const char *dev_addr, ret = ioctl(vfio_group_fd, VFIO_GROUP_SET_CONTAINER, &vfio_container_fd); if (ret) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); DPAA2_BUS_ERR(" %s cannot add VFIO group to container, " "error %i (%s)", dev_addr, - errno, strerror(errno)); + errno, errmsg); close(vfio_group_fd); close(vfio_container_fd); rte_vfio_clear_group(vfio_group_fd); @@ -550,8 +555,10 @@ fslmc_vfio_setup_device(const char *sysfs_base, const char *dev_addr, /* test and setup the device */ ret = ioctl(*vfio_dev_fd, VFIO_DEVICE_GET_INFO, device_info); if (ret) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); DPAA2_BUS_ERR(" %s cannot get device info, error %i (%s)", - dev_addr, errno, strerror(errno)); + dev_addr, errno, errmsg); close(*vfio_dev_fd); close(vfio_group_fd); close(vfio_container_fd); @@ -599,6 +606,7 @@ int rte_dpaa2_intr_enable(struct rte_intr_handle *intr_handle, int index) char irq_set_buf[IRQ_SET_BUF_LEN]; struct vfio_irq_set *irq_set; int *fd_ptr, vfio_dev_fd; + char errmsg[RTE_STRERR_BUFSIZE]; len = sizeof(irq_set_buf); @@ -615,9 +623,10 @@ int rte_dpaa2_intr_enable(struct rte_intr_handle *intr_handle, int index) vfio_dev_fd = rte_intr_dev_fd_get(intr_handle); ret = ioctl(vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set); if (ret) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); DPAA2_BUS_ERR("Error:dpaa2 SET IRQs fd=%d, err = %d(%s)", - rte_intr_fd_get(intr_handle), errno, - strerror(errno)); + rte_intr_fd_get(intr_handle), errno, errmsg); return ret; } @@ -655,6 +664,7 @@ rte_dpaa2_vfio_setup_intr(struct rte_intr_handle *intr_handle, int vfio_dev_fd, int num_irqs) { + char errmsg[RTE_STRERR_BUFSIZE]; int i, ret; /* start from MSI-X interrupt type */ @@ -666,8 +676,10 @@ rte_dpaa2_vfio_setup_intr(struct rte_intr_handle *intr_handle, ret = ioctl(vfio_dev_fd, VFIO_DEVICE_GET_IRQ_INFO, &irq_info); if (ret < 0) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); DPAA2_BUS_ERR("Cannot get IRQ(%d) info, error %i (%s)", - i, errno, strerror(errno)); + i, errno, errmsg); return -1; } @@ -681,8 +693,10 @@ rte_dpaa2_vfio_setup_intr(struct rte_intr_handle *intr_handle, /* set up an eventfd for interrupts */ fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); if (fd < 0) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); DPAA2_BUS_ERR("Cannot set up eventfd, error %i (%s)", - errno, strerror(errno)); + errno, errmsg); return -1; } -- 2.33.0