From patchwork Tue Nov 14 12:35:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dengdui Huang X-Patchwork-Id: 134336 X-Patchwork-Delegate: david.marchand@redhat.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 48F5243329; Tue, 14 Nov 2023 13:37:31 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2241340A8A; Tue, 14 Nov 2023 13:36:14 +0100 (CET) Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by mails.dpdk.org (Postfix) with ESMTP id 723B0402E4 for ; Tue, 14 Nov 2023 13:35:56 +0100 (CET) Received: from dggpeml500011.china.huawei.com (unknown [172.30.72.56]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4SV5J81dvLzMmqJ; Tue, 14 Nov 2023 20:31:20 +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_128_GCM_SHA256) id 15.1.2507.31; Tue, 14 Nov 2023 20:35:55 +0800 From: Dengdui Huang To: CC: , , , , Subject: [PATCH v3 13/42] bus/pci: use rte strerror Date: Tue, 14 Nov 2023 20:35:23 +0800 Message-ID: <20231114123552.398072-14-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20231114123552.398072-1-huangdengdui@huawei.com> References: <20231114082539.1858594-44-huangdengdui@huawei.com> <20231114123552.398072-1-huangdengdui@huawei.com> MIME-Version: 1.0 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-CFilter-Loop: Reflected 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 rte_strerror() to replace it. Cc: stable@dpdk.org Signed-off-by: Dengdui Huang Acked-by: Chengwen Feng --- drivers/bus/pci/bsd/pci.c | 8 ++++---- drivers/bus/pci/linux/pci.c | 7 ++++--- drivers/bus/pci/linux/pci_uio.c | 23 ++++++++++++----------- drivers/bus/pci/linux/pci_vfio.c | 23 ++++++++++++----------- drivers/bus/pci/pci_common_uio.c | 3 ++- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/drivers/bus/pci/bsd/pci.c b/drivers/bus/pci/bsd/pci.c index 27f12590d4..ce08372931 100644 --- a/drivers/bus/pci/bsd/pci.c +++ b/drivers/bus/pci/bsd/pci.c @@ -125,7 +125,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, if (rte_intr_fd_get(dev->intr_handle) < 0) { RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - devname, strerror(errno)); + devname, rte_strerror(errno)); goto error; } @@ -169,7 +169,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0); if (maps[map_idx].path == NULL) { RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n", - strerror(errno)); + rte_strerror(errno)); return -1; } @@ -179,7 +179,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, fd = open(devname, O_RDWR); if (fd < 0) { RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - devname, strerror(errno)); + devname, rte_strerror(errno)); goto error; } @@ -353,7 +353,7 @@ rte_pci_scan(void) unsigned i; if (ioctl(fd, PCIOCGETCONF, &conf_io) < 0) { RTE_LOG(ERR, EAL, "%s(): error with ioctl on /dev/pci: %s\n", - __func__, strerror(errno)); + __func__, rte_strerror(errno)); goto error; } diff --git a/drivers/bus/pci/linux/pci.c b/drivers/bus/pci/linux/pci.c index 3d237398d9..7d870b43d2 100644 --- a/drivers/bus/pci/linux/pci.c +++ b/drivers/bus/pci/linux/pci.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "eal_filesystem.h" @@ -455,7 +456,7 @@ rte_pci_scan(void) dir = opendir(rte_pci_get_sysfs_path()); if (dir == NULL) { RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n", - __func__, strerror(errno)); + __func__, rte_strerror(errno)); return -1; } @@ -506,7 +507,7 @@ pci_device_iommu_support_va(const struct rte_pci_device *dev) return true; RTE_LOG(ERR, EAL, "%s(): can't open %s: %s\n", - __func__, filename, strerror(errno)); + __func__, filename, rte_strerror(errno)); return false; } @@ -557,7 +558,7 @@ pci_device_iommu_support_va(__rte_unused const struct rte_pci_device *dev) if (fp == NULL) { RTE_LOG(ERR, EAL, "%s(): can't open %s: %s\n", - __func__, filename, strerror(errno)); + __func__, filename, rte_strerror(errno)); return ret; } diff --git a/drivers/bus/pci/linux/pci_uio.c b/drivers/bus/pci/linux/pci_uio.c index 97d740dfe5..2ee0179ea2 100644 --- a/drivers/bus/pci/linux/pci_uio.c +++ b/drivers/bus/pci/linux/pci_uio.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "eal_filesystem.h" #include "pci_init.h" @@ -111,7 +112,7 @@ pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num) ret = mknod(filename, S_IFCHR | S_IRUSR | S_IWUSR, dev); if (ret != 0) { RTE_LOG(ERR, EAL, "%s(): mknod() failed %s\n", - __func__, strerror(errno)); + __func__, rte_strerror(errno)); return -1; } @@ -241,7 +242,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, fd = open(devname, O_RDWR); if (fd < 0) { RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - devname, strerror(errno)); + devname, rte_strerror(errno)); goto error; } @@ -254,7 +255,7 @@ pci_uio_alloc_resource(struct rte_pci_device *dev, uio_cfg_fd = open(cfgname, O_RDWR); if (uio_cfg_fd < 0) { RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - cfgname, strerror(errno)); + cfgname, rte_strerror(errno)); goto error; } @@ -314,7 +315,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, maps[map_idx].path = rte_malloc(NULL, sizeof(devname), 0); if (maps[map_idx].path == NULL) { RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n", - strerror(errno)); + rte_strerror(errno)); return -1; } @@ -348,7 +349,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx, fd = open(devname, O_RDWR); if (fd < 0) { RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - devname, strerror(errno)); + devname, rte_strerror(errno)); goto error; } } @@ -404,7 +405,7 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar, f = fopen(filename, "r"); if (f == NULL) { RTE_LOG(ERR, EAL, "%s(): Cannot open sysfs resource: %s\n", - __func__, strerror(errno)); + __func__, rte_strerror(errno)); return -1; } @@ -446,7 +447,7 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar, int uio_num = pci_get_uio_dev(dev, dirname, sizeof(dirname), 0); if (uio_num < 0) { RTE_LOG(ERR, EAL, "cannot open %s: %s\n", - dirname, strerror(errno)); + dirname, rte_strerror(errno)); goto error; } @@ -454,7 +455,7 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar, fd = open(filename, O_RDWR); if (fd < 0) { RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - filename, strerror(errno)); + filename, rte_strerror(errno)); goto error; } if (rte_intr_fd_set(dev->intr_handle, fd)) @@ -494,7 +495,7 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar, f = fopen(filename, "r"); if (f == NULL) { RTE_LOG(ERR, EAL, "Cannot open sysfs resource: %s\n", - strerror(errno)); + rte_strerror(errno)); return -1; } for (i = 0; i < bar + 1; i++) { @@ -518,7 +519,7 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar, fd = open(filename, O_RDWR); if (fd < 0) { RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", filename, - strerror(errno)); + rte_strerror(errno)); goto error; } addr = mmap(NULL, end_addr + 1, PROT_READ | PROT_WRITE, @@ -526,7 +527,7 @@ pci_uio_ioport_map(struct rte_pci_device *dev, int bar, close(fd); if (addr == MAP_FAILED) { RTE_LOG(ERR, EAL, "Cannot mmap IO port resource: %s\n", - strerror(errno)); + rte_strerror(errno)); goto error; } diff --git a/drivers/bus/pci/linux/pci_vfio.c b/drivers/bus/pci/linux/pci_vfio.c index 3f3201daf2..671b0f36bc 100644 --- a/drivers/bus/pci/linux/pci_vfio.c +++ b/drivers/bus/pci/linux/pci_vfio.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "eal_filesystem.h" @@ -225,7 +226,7 @@ pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd) ret = ioctl(vfio_dev_fd, VFIO_DEVICE_GET_IRQ_INFO, &irq); if (ret < 0) { RTE_LOG(ERR, EAL, "Cannot get VFIO IRQ info, error " - "%i (%s)\n", errno, strerror(errno)); + "%i (%s)\n", errno, rte_strerror(errno)); return -1; } @@ -252,7 +253,7 @@ pci_vfio_setup_interrupts(struct rte_pci_device *dev, int vfio_dev_fd) fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); if (fd < 0) { RTE_LOG(ERR, EAL, "Cannot set up eventfd, error " - "%i (%s)\n", errno, strerror(errno)); + "%i (%s)\n", errno, rte_strerror(errno)); return -1; } @@ -336,7 +337,7 @@ pci_vfio_enable_notifier(struct rte_pci_device *dev, int vfio_dev_fd) fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC); if (fd < 0) { RTE_LOG(ERR, EAL, "Cannot set up eventfd, error %i (%s)\n", - errno, strerror(errno)); + errno, rte_strerror(errno)); return -1; } @@ -460,7 +461,7 @@ pci_rte_vfio_setup_device(struct rte_pci_device *dev, int vfio_dev_fd) */ if (ioctl(vfio_dev_fd, VFIO_DEVICE_RESET) && errno != EINVAL) { RTE_LOG(ERR, EAL, "Unable to reset device! Error: %d (%s)\n", - errno, strerror(errno)); + errno, rte_strerror(errno)); return -1; } @@ -742,7 +743,7 @@ pci_vfio_fill_regions(struct rte_pci_device *dev, int vfio_dev_fd, ret = pci_vfio_get_region_info(vfio_dev_fd, ®, i); if (ret < 0) { RTE_LOG(DEBUG, EAL, "%s cannot get device region info error %i (%s)\n", - dev->name, errno, strerror(errno)); + dev->name, errno, rte_strerror(errno)); return -1; } @@ -811,7 +812,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) VFIO_PCI_CONFIG_REGION_INDEX); if (ret < 0) { RTE_LOG(ERR, EAL, "%s cannot get device region info error %i (%s)\n", - dev->name, errno, strerror(errno)); + dev->name, errno, rte_strerror(errno)); goto err_vfio_res; } pdev->region[VFIO_PCI_CONFIG_REGION_INDEX].size = reg->size; @@ -851,7 +852,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) if (ret < 0) { RTE_LOG(ERR, EAL, "%s cannot get device region info error " - "%i (%s)\n", pci_addr, errno, strerror(errno)); + "%i (%s)\n", pci_addr, errno, rte_strerror(errno)); goto err_map; } @@ -914,7 +915,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) ret = pci_vfio_sparse_mmap_bar(vfio_dev_fd, vfio_res, i, 0); if (ret < 0) { RTE_LOG(ERR, EAL, "%s sparse mapping BAR%i failed: %s\n", - pci_addr, i, strerror(errno)); + pci_addr, i, rte_strerror(errno)); free(reg); goto err_map; } @@ -922,7 +923,7 @@ pci_vfio_map_resource_primary(struct rte_pci_device *dev) ret = pci_vfio_mmap_bar(vfio_dev_fd, vfio_res, i, 0); if (ret < 0) { RTE_LOG(ERR, EAL, "%s mapping BAR%i failed: %s\n", - pci_addr, i, strerror(errno)); + pci_addr, i, rte_strerror(errno)); free(reg); goto err_map; } @@ -1019,14 +1020,14 @@ pci_vfio_map_resource_secondary(struct rte_pci_device *dev) ret = pci_vfio_sparse_mmap_bar(vfio_dev_fd, vfio_res, i, MAP_FIXED); if (ret < 0) { RTE_LOG(ERR, EAL, "%s sparse mapping BAR%i failed: %s\n", - pci_addr, i, strerror(errno)); + pci_addr, i, rte_strerror(errno)); goto err_vfio_dev_fd; } } else { ret = pci_vfio_mmap_bar(vfio_dev_fd, vfio_res, i, MAP_FIXED); if (ret < 0) { RTE_LOG(ERR, EAL, "%s mapping BAR%i failed: %s\n", - pci_addr, i, strerror(errno)); + pci_addr, i, rte_strerror(errno)); goto err_vfio_dev_fd; } } diff --git a/drivers/bus/pci/pci_common_uio.c b/drivers/bus/pci/pci_common_uio.c index 76c661f054..5d59a90b33 100644 --- a/drivers/bus/pci/pci_common_uio.c +++ b/drivers/bus/pci/pci_common_uio.c @@ -15,6 +15,7 @@ #include #include #include +#include #include "private.h" @@ -44,7 +45,7 @@ pci_uio_map_secondary(struct rte_pci_device *dev) fd = open(uio_res->maps[i].path, O_RDWR); if (fd < 0) { RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", - uio_res->maps[i].path, strerror(errno)); + uio_res->maps[i].path, rte_strerror(errno)); return -1; }