[v4,27/42] net/failsafe: use rte strerror

Message ID 20241023082852.2780488-28-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/net/failsafe/failsafe.c         | 8 ++++----
 drivers/net/failsafe/failsafe_args.c    | 4 ++--
 drivers/net/failsafe/failsafe_eal.c     | 4 ++--
 drivers/net/failsafe/failsafe_flow.c    | 4 ++--
 drivers/net/failsafe/failsafe_ops.c     | 2 +-
 drivers/net/failsafe/failsafe_private.h | 6 +++---
 6 files changed, 14 insertions(+), 14 deletions(-)
  

Patch

diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c
index 32811403b4..f89c946ce4 100644
--- a/drivers/net/failsafe/failsafe.c
+++ b/drivers/net/failsafe/failsafe.c
@@ -92,7 +92,7 @@  failsafe_hotplug_alarm_cancel(struct rte_eth_dev *dev)
 	rte_eal_alarm_cancel(fs_hotplug_alarm, dev);
 	if (rte_errno) {
 		ERROR("rte_eal_alarm_cancel failed (errno: %s)",
-		      strerror(rte_errno));
+		      rte_strerror(rte_errno));
 		ret = -rte_errno;
 	} else {
 		PRIV(dev)->pending_alarm = 0;
@@ -138,18 +138,18 @@  fs_mutex_init(struct fs_priv *priv)
 
 	ret = pthread_mutexattr_init(&attr);
 	if (ret) {
-		ERROR("Cannot initiate mutex attributes - %s", strerror(ret));
+		ERROR("Cannot initiate mutex attributes - %s", rte_strerror(ret));
 		return ret;
 	}
 	/* Allow mutex relocks for the thread holding the mutex. */
 	ret = pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE);
 	if (ret) {
-		ERROR("Cannot set mutex type - %s", strerror(ret));
+		ERROR("Cannot set mutex type - %s", rte_strerror(ret));
 		return ret;
 	}
 	ret = pthread_mutex_init(&priv->hotplug_mutex, &attr);
 	if (ret) {
-		ERROR("Cannot initiate mutex - %s", strerror(ret));
+		ERROR("Cannot initiate mutex - %s", rte_strerror(ret));
 		return ret;
 	}
 	return 0;
diff --git a/drivers/net/failsafe/failsafe_args.c b/drivers/net/failsafe/failsafe_args.c
index 1b8f1d3050..cc15428b7b 100644
--- a/drivers/net/failsafe/failsafe_args.c
+++ b/drivers/net/failsafe/failsafe_args.c
@@ -112,7 +112,7 @@  fs_execute_cmd(struct sub_device *sdev, char *cmdline)
 	fp = popen(sdev->cmdline, "r");
 	if (fp == NULL) {
 		ret = -errno;
-		ERROR("popen: %s", strerror(errno));
+		ERROR("popen: %s", rte_strerror(errno));
 		return ret;
 	}
 	/* We only read one line */
@@ -131,7 +131,7 @@  fs_execute_cmd(struct sub_device *sdev, char *cmdline)
 		ERROR("Parsing device '%s' failed", output);
 ret_pclose:
 	if (pclose(fp) == -1)
-		ERROR("pclose: %s", strerror(errno));
+		ERROR("pclose: %s", rte_strerror(errno));
 	return ret;
 }
 
diff --git a/drivers/net/failsafe/failsafe_eal.c b/drivers/net/failsafe/failsafe_eal.c
index e79d3b4120..07fa802653 100644
--- a/drivers/net/failsafe/failsafe_eal.c
+++ b/drivers/net/failsafe/failsafe_eal.c
@@ -52,7 +52,7 @@  fs_bus_init(struct rte_eth_dev *dev)
 			if (ret < 0) {
 				ERROR("sub_device %d probe failed %s%s%s", i,
 				      rte_errno ? "(" : "",
-				      rte_errno ? strerror(rte_errno) : "",
+				      rte_errno ? rte_strerror(rte_errno) : "",
 				      rte_errno ? ")" : "");
 				continue;
 			}
@@ -100,7 +100,7 @@  fs_bus_init(struct rte_eth_dev *dev)
 			ret = rte_eth_dev_owner_set(pid, &PRIV(dev)->my_owner);
 			if (ret < 0) {
 				INFO("sub_device %d owner set failed (%s), "
-				     "will try again later", i, strerror(-ret));
+				     "will try again later", i, rte_strerror(-ret));
 				continue;
 			} else if (strncmp(rte_eth_devices[pid].device->name,
 				   da->name, strlen(da->name)) != 0) {
diff --git a/drivers/net/failsafe/failsafe_flow.c b/drivers/net/failsafe/failsafe_flow.c
index 707e6c63b5..5d17182cc5 100644
--- a/drivers/net/failsafe/failsafe_flow.c
+++ b/drivers/net/failsafe/failsafe_flow.c
@@ -33,7 +33,7 @@  fs_flow_allocate(const struct rte_flow_attr *attr,
 	if (ret < 0) {
 		ERROR("Unable to process flow rule (%s): %s",
 		      error.message ? error.message : "unspecified",
-		      strerror(rte_errno));
+		      rte_strerror(rte_errno));
 		return NULL;
 	}
 	flow = rte_zmalloc(NULL, offsetof(struct rte_flow, rule) + ret,
@@ -47,7 +47,7 @@  fs_flow_allocate(const struct rte_flow_attr *attr,
 	if (ret < 0) {
 		ERROR("Failed to copy flow rule (%s): %s",
 		      error.message ? error.message : "unspecified",
-		      strerror(rte_errno));
+		      rte_strerror(rte_errno));
 		rte_free(flow);
 		return NULL;
 	}
diff --git a/drivers/net/failsafe/failsafe_ops.c b/drivers/net/failsafe/failsafe_ops.c
index 9c013e0419..f3b2daf400 100644
--- a/drivers/net/failsafe/failsafe_ops.c
+++ b/drivers/net/failsafe/failsafe_ops.c
@@ -452,7 +452,7 @@  fs_rx_queue_setup(struct rte_eth_dev *dev,
 #ifdef RTE_EXEC_ENV_LINUX
 	rxq->event_fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
 	if (rxq->event_fd < 0) {
-		ERROR("Failed to create an eventfd: %s", strerror(errno));
+		ERROR("Failed to create an eventfd: %s", rte_strerror(errno));
 		fs_unlock(dev, 0);
 		return -errno;
 	}
diff --git a/drivers/net/failsafe/failsafe_private.h b/drivers/net/failsafe/failsafe_private.h
index babea6016e..fcbb1b771e 100644
--- a/drivers/net/failsafe/failsafe_private.h
+++ b/drivers/net/failsafe/failsafe_private.h
@@ -407,14 +407,14 @@  fs_lock(struct rte_eth_dev *dev, unsigned int is_alarm)
 		ret = pthread_mutex_trylock(&PRIV(dev)->hotplug_mutex);
 		if (ret) {
 			DEBUG("Hot-plug mutex lock trying failed(%s), will try"
-			      " again later...", strerror(ret));
+			      " again later...", rte_strerror(ret));
 			return ret;
 		}
 		PRIV(dev)->alarm_lock = 1;
 	} else {
 		ret = pthread_mutex_lock(&PRIV(dev)->hotplug_mutex);
 		if (ret) {
-			ERROR("Cannot lock mutex(%s)", strerror(ret));
+			ERROR("Cannot lock mutex(%s)", rte_strerror(ret));
 			return ret;
 		}
 	}
@@ -436,7 +436,7 @@  fs_unlock(struct rte_eth_dev *dev, unsigned int is_alarm)
 	}
 	ret = pthread_mutex_unlock(&PRIV(dev)->hotplug_mutex);
 	if (ret)
-		ERROR("Cannot unlock hot-plug mutex(%s)", strerror(ret));
+		ERROR("Cannot unlock hot-plug mutex(%s)", rte_strerror(ret));
 }
 
 /*