[v5,05/52] latency: replace strerror with reentrant version

Message ID 20241104111037.3632161-6-huangdengdui@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series replace strerror |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

huangdengdui Nov. 4, 2024, 11:09 a.m. UTC
The function strerror() is insecure in a multi-thread environment.
This patch uses strerror_r() to replace it.

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
---
 lib/latencystats/rte_latencystats.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
  

Patch

diff --git a/lib/latencystats/rte_latencystats.c b/lib/latencystats/rte_latencystats.c
index 6a261309f9..8957f6f6ac 100644
--- a/lib/latencystats/rte_latencystats.c
+++ b/lib/latencystats/rte_latencystats.c
@@ -220,6 +220,7 @@  rte_latencystats_init(uint64_t app_samp_intvl,
 	struct rxtx_cbs *cbs = NULL;
 	const char *ptr_strings[NUM_LATENCY_STATS] = {0};
 	const struct rte_memzone *mz = NULL;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	const unsigned int flags = 0;
 	int ret;
 
@@ -266,9 +267,11 @@  rte_latencystats_init(uint64_t app_samp_intvl,
 
 		ret = rte_eth_dev_info_get(pid, &dev_info);
 		if (ret != 0) {
+			if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret);
 			LATENCY_STATS_LOG(INFO,
 				"Error during getting device (port %u) info: %s",
-				pid, strerror(-ret));
+				pid, errmsg);
 
 			continue;
 		}
@@ -303,6 +306,7 @@  rte_latencystats_uninit(void)
 	int ret = 0;
 	struct rxtx_cbs *cbs = NULL;
 	const struct rte_memzone *mz = NULL;
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	/** De register Rx/Tx callbacks */
 	RTE_ETH_FOREACH_DEV(pid) {
@@ -310,9 +314,11 @@  rte_latencystats_uninit(void)
 
 		ret = rte_eth_dev_info_get(pid, &dev_info);
 		if (ret != 0) {
+			if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret);
 			LATENCY_STATS_LOG(INFO,
 				"Error during getting device (port %u) info: %s",
-				pid, strerror(-ret));
+				pid, errmsg);
 
 			continue;
 		}