[v4,15/42] bus/vmbus: use rte strerror

Message ID 20241023082852.2780488-16-huangdengdui@huawei.com (mailing list archive)
State Changes Requested, archived
Delegated to: Thomas Monjalon
Headers
Series replace strerror |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

huangdengdui Oct. 23, 2024, 8:28 a.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>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
---
 drivers/bus/vmbus/linux/vmbus_bus.c  |  7 ++++---
 drivers/bus/vmbus/linux/vmbus_uio.c  | 21 +++++++++++----------
 drivers/bus/vmbus/vmbus_common.c     |  4 ++--
 drivers/bus/vmbus/vmbus_common_uio.c |  3 ++-
 4 files changed, 19 insertions(+), 16 deletions(-)
  

Patch

diff --git a/drivers/bus/vmbus/linux/vmbus_bus.c b/drivers/bus/vmbus/linux/vmbus_bus.c
index 01d8111b85..0c92c1d4dd 100644
--- a/drivers/bus/vmbus/linux/vmbus_bus.c
+++ b/drivers/bus/vmbus/linux/vmbus_bus.c
@@ -18,6 +18,7 @@ 
 #include <rte_memory.h>
 #include <rte_malloc.h>
 #include <rte_bus_vmbus.h>
+#include <rte_errno.h>
 
 #include "eal_filesystem.h"
 #include "private.h"
@@ -50,7 +51,7 @@  parse_sysfs_uuid(const char *filename, rte_uuid_t uu)
 	f = fopen(filename, "r");
 	if (f == NULL) {
 		VMBUS_LOG(ERR, "cannot open sysfs value %s: %s",
-			  filename, strerror(errno));
+			  filename, rte_strerror(errno));
 		return -1;
 	}
 
@@ -92,7 +93,7 @@  get_sysfs_string(const char *filename, char *buf, size_t buflen)
 	f = fopen(filename, "r");
 	if (f == NULL) {
 		VMBUS_LOG(ERR, "cannot open sysfs value %s:%s",
-			  filename, strerror(errno));
+			  filename, rte_strerror(errno));
 		return -1;
 	}
 
@@ -350,7 +351,7 @@  rte_vmbus_scan(void)
 			return 0;
 
 		VMBUS_LOG(ERR, "opendir %s failed: %s",
-			  SYSFS_VMBUS_DEVICES, strerror(errno));
+			  SYSFS_VMBUS_DEVICES, rte_strerror(errno));
 		return -1;
 	}
 
diff --git a/drivers/bus/vmbus/linux/vmbus_uio.c b/drivers/bus/vmbus/linux/vmbus_uio.c
index 26edef342d..5fce68d880 100644
--- a/drivers/bus/vmbus/linux/vmbus_uio.c
+++ b/drivers/bus/vmbus/linux/vmbus_uio.c
@@ -18,6 +18,7 @@ 
 #include <rte_malloc.h>
 #include <rte_bus_vmbus.h>
 #include <rte_string_fns.h>
+#include <rte_errno.h>
 
 #include "private.h"
 
@@ -34,7 +35,7 @@  void vmbus_uio_irq_control(struct rte_vmbus_device *dev, int32_t onoff)
 		  sizeof(onoff)) < 0) {
 		VMBUS_LOG(ERR, "cannot write to %d:%s",
 			  rte_intr_fd_get(dev->intr_handle),
-			  strerror(errno));
+			  rte_strerror(errno));
 	}
 }
 
@@ -51,7 +52,7 @@  int vmbus_uio_irq_read(struct rte_vmbus_device *dev)
 	if (cc < (int)sizeof(count)) {
 		if (cc < 0) {
 			VMBUS_LOG(ERR, "IRQ read failed %s",
-				  strerror(errno));
+				  rte_strerror(errno));
 			return -errno;
 		}
 		VMBUS_LOG(ERR, "can't read IRQ count");
@@ -91,7 +92,7 @@  vmbus_uio_alloc_resource(struct rte_vmbus_device *dev,
 	fd = open(devname, O_RDWR);
 	if (fd < 0) {
 		VMBUS_LOG(ERR, "Cannot open %s: %s",
-			devname, strerror(errno));
+			devname, rte_strerror(errno));
 		goto error;
 	}
 
@@ -158,7 +159,7 @@  vmbus_uio_map_resource_by_index(struct rte_vmbus_device *dev, int idx,
 	fd = open(uio_res->path, O_RDWR);
 	if (fd < 0) {
 		VMBUS_LOG(ERR, "Cannot open %s: %s",
-			  uio_res->path, strerror(errno));
+			  uio_res->path, rte_strerror(errno));
 		return -1;
 	}
 
@@ -256,13 +257,13 @@  static int vmbus_uio_map_subchan(const struct rte_vmbus_device *dev,
 	fd = open(ring_path, O_RDWR);
 	if (fd < 0) {
 		VMBUS_LOG(ERR, "Cannot open %s: %s",
-			  ring_path, strerror(errno));
+			  ring_path, rte_strerror(errno));
 		return -errno;
 	}
 
 	if (fstat(fd, &sb) < 0) {
 		VMBUS_LOG(ERR, "Cannot state %s: %s",
-			  ring_path, strerror(errno));
+			  ring_path, rte_strerror(errno));
 		close(fd);
 		return -errno;
 	}
@@ -342,7 +343,7 @@  static int vmbus_uio_sysfs_read(const char *dir, const char *name,
 	f = fopen(path, "r");
 	if (!f) {
 		VMBUS_LOG(ERR, "can't open %s:%s",
-			  path, strerror(errno));
+			  path, rte_strerror(errno));
 		return -errno;
 	}
 
@@ -404,7 +405,7 @@  int vmbus_uio_get_subchan(struct vmbus_channel *primary,
 	chan_dir = opendir(chan_path);
 	if (!chan_dir) {
 		VMBUS_LOG(ERR, "cannot open %s: %s",
-			  chan_path, strerror(errno));
+			  chan_path, rte_strerror(errno));
 		return -errno;
 	}
 
@@ -441,7 +442,7 @@  int vmbus_uio_get_subchan(struct vmbus_channel *primary,
 					   &subid, UINT16_MAX);
 		if (err) {
 			VMBUS_LOG(NOTICE, "no subchannel_id in %s:%s",
-				  subchan_path, strerror(-err));
+				  subchan_path, rte_strerror(-err));
 			goto fail;
 		}
 
@@ -452,7 +453,7 @@  int vmbus_uio_get_subchan(struct vmbus_channel *primary,
 					   &monid, UINT8_MAX);
 		if (err) {
 			VMBUS_LOG(NOTICE, "no monitor_id in %s:%s",
-				  subchan_path, strerror(-err));
+				  subchan_path, rte_strerror(-err));
 			goto fail;
 		}
 
diff --git a/drivers/bus/vmbus/vmbus_common.c b/drivers/bus/vmbus/vmbus_common.c
index 8a965d10d9..ef05d62714 100644
--- a/drivers/bus/vmbus/vmbus_common.c
+++ b/drivers/bus/vmbus/vmbus_common.c
@@ -38,7 +38,7 @@  vmbus_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
 		VMBUS_LOG(ERR,
 			  "mmap(%d, %p, %zu, %ld) failed: %s",
 			  fd, requested_addr, size, (long)offset,
-			  strerror(errno));
+			  rte_strerror(errno));
 	} else {
 		VMBUS_LOG(DEBUG, "  VMBUS memory mapped at %p",
 			  mapaddr);
@@ -57,7 +57,7 @@  vmbus_unmap_resource(void *requested_addr, size_t size)
 	if (munmap(requested_addr, size)) {
 		VMBUS_LOG(ERR, "munmap(%p, 0x%lx) failed: %s",
 			requested_addr, (unsigned long)size,
-			strerror(errno));
+			rte_strerror(errno));
 	} else {
 		VMBUS_LOG(DEBUG, "  VMBUS memory unmapped at %p",
 			  requested_addr);
diff --git a/drivers/bus/vmbus/vmbus_common_uio.c b/drivers/bus/vmbus/vmbus_common_uio.c
index 4d4613513c..54c1187026 100644
--- a/drivers/bus/vmbus/vmbus_common_uio.c
+++ b/drivers/bus/vmbus/vmbus_common_uio.c
@@ -14,6 +14,7 @@ 
 #include <rte_log.h>
 #include <rte_malloc.h>
 #include <rte_bus_vmbus.h>
+#include <rte_errno.h>
 
 #include "private.h"
 
@@ -56,7 +57,7 @@  vmbus_uio_map_secondary(struct rte_vmbus_device *dev)
 	fd = open(uio_res->path, O_RDWR);
 	if (fd < 0) {
 		VMBUS_LOG(ERR, "Cannot open %s: %s",
-			  uio_res->path, strerror(errno));
+			  uio_res->path, rte_strerror(errno));
 		return -1;
 	}