[v4,07/42] power: use rte strerror

Message ID 20241023082852.2780488-8-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>
---
 lib/power/guest_channel.c        | 7 ++++---
 lib/power/power_kvm_vm.c         | 3 ++-
 lib/power/power_pstate_cpufreq.c | 7 ++++---
 lib/power/rte_power_pmd_mgmt.c   | 2 +-
 4 files changed, 11 insertions(+), 8 deletions(-)
  

Patch

diff --git a/lib/power/guest_channel.c b/lib/power/guest_channel.c
index bc3f55b6bf..a197113b90 100644
--- a/lib/power/guest_channel.c
+++ b/lib/power/guest_channel.c
@@ -14,6 +14,7 @@ 
 
 #include <rte_log.h>
 #include <rte_power.h>
+#include <rte_errno.h>
 
 #include "guest_channel.h"
 
@@ -78,7 +79,7 @@  guest_channel_host_connect(const char *path, unsigned int lcore_id)
 	fd = open(fd_path, O_RDWR);
 	if (fd < 0) {
 		GUEST_CHANNEL_LOG(ERR, "Unable to connect to '%s' with error "
-				"%s", fd_path, strerror(errno));
+				"%s", fd_path, rte_strerror(errno));
 		return -1;
 	}
 
@@ -107,7 +108,7 @@  guest_channel_host_connect(const char *path, unsigned int lcore_id)
 	if (ret != 0) {
 		GUEST_CHANNEL_LOG(ERR,
 				"Error on channel '%s' communications test: %s",
-				fd_path, ret > 0 ? strerror(ret) :
+				fd_path, ret > 0 ? rte_strerror(ret) :
 				"channel not connected");
 		goto error;
 	}
@@ -187,7 +188,7 @@  int power_guest_channel_read_msg(void *pkt,
 		return -1;
 	} else if (ret < 0) {
 		GUEST_CHANNEL_LOG(ERR, "Error occurred during poll function: %s",
-				strerror(errno));
+				rte_strerror(errno));
 		return -1;
 	}
 
diff --git a/lib/power/power_kvm_vm.c b/lib/power/power_kvm_vm.c
index f15be8fac5..5e5532832e 100644
--- a/lib/power/power_kvm_vm.c
+++ b/lib/power/power_kvm_vm.c
@@ -5,6 +5,7 @@ 
 #include <string.h>
 
 #include <rte_log.h>
+#include <rte_errno.h>
 
 #include "rte_power_guest_channel.h"
 #include "guest_channel.h"
@@ -83,7 +84,7 @@  send_msg(unsigned int lcore_id, uint32_t scale_direction)
 	if (ret == 0)
 		return 1;
 	POWER_LOG(DEBUG, "Error sending message: %s",
-			ret > 0 ? strerror(ret) : "channel not connected");
+			ret > 0 ? rte_strerror(ret) : "channel not connected");
 	return -1;
 }
 
diff --git a/lib/power/power_pstate_cpufreq.c b/lib/power/power_pstate_cpufreq.c
index 4755909466..acc922ea2f 100644
--- a/lib/power/power_pstate_cpufreq.c
+++ b/lib/power/power_pstate_cpufreq.c
@@ -13,6 +13,7 @@ 
 
 #include <rte_memcpy.h>
 #include <rte_stdatomic.h>
+#include <rte_errno.h>
 
 #include "rte_power_pmd_mgmt.h"
 #include "power_pstate_cpufreq.h"
@@ -83,7 +84,7 @@  power_read_turbo_pct(uint64_t *outVal)
 
 	if (fd < 0) {
 		POWER_LOG(ERR, "Error opening '%s': %s", POWER_SYSFILE_TURBO_PCT,
-				 strerror(errno));
+				 rte_strerror(errno));
 		return fd;
 	}
 
@@ -91,7 +92,7 @@  power_read_turbo_pct(uint64_t *outVal)
 
 	if (ret < 0) {
 		POWER_LOG(ERR, "Error reading '%s': %s", POWER_SYSFILE_TURBO_PCT,
-				 strerror(errno));
+				 rte_strerror(errno));
 		goto out;
 	}
 
@@ -99,7 +100,7 @@  power_read_turbo_pct(uint64_t *outVal)
 	*outVal = (uint64_t) strtol(val, &endptr, 10);
 	if (errno != 0 || (*endptr != 0 && *endptr != '\n')) {
 		POWER_LOG(ERR, "Error converting str to digits, read from %s: %s",
-				 POWER_SYSFILE_TURBO_PCT, strerror(errno));
+				 POWER_SYSFILE_TURBO_PCT, rte_strerror(errno));
 		ret = -1;
 		goto out;
 	}
diff --git a/lib/power/rte_power_pmd_mgmt.c b/lib/power/rte_power_pmd_mgmt.c
index 5e50613f5b..f52c2c08d5 100644
--- a/lib/power/rte_power_pmd_mgmt.c
+++ b/lib/power/rte_power_pmd_mgmt.c
@@ -575,7 +575,7 @@  rte_power_ethdev_pmgmt_queue_enable(unsigned int lcore_id, uint16_t port_id,
 	ret = queue_list_add(lcore_cfg, &qdata);
 	if (ret < 0) {
 		POWER_LOG(DEBUG, "Failed to add queue to list: %s",
-				strerror(-ret));
+				rte_strerror(-ret));
 		goto end;
 	}
 	/* new queue is always added last */