[v3,13/42] bus/pci: use rte strerror

Message ID 20231114123552.398072-14-huangdengdui@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: David Marchand
Headers
Series replace strerror |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Dengdui Huang Nov. 14, 2023, 12:35 p.m. UTC
  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 <huangdengdui@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
---
 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(-)
  

Patch

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 <rte_devargs.h>
 #include <rte_memcpy.h>
 #include <rte_vfio.h>
+#include <rte_errno.h>
 
 #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 <rte_bus_pci.h>
 #include <rte_common.h>
 #include <rte_malloc.h>
+#include <rte_errno.h>
 
 #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 <bus_driver.h>
 #include <rte_spinlock.h>
 #include <rte_tailq.h>
+#include <rte_errno.h>
 
 #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, &reg, 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 <rte_tailq.h>
 #include <rte_log.h>
 #include <rte_malloc.h>
+#include <rte_errno.h>
 
 #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;
 			}