[v5,13/52] bus/dpaa: replace strerror with reentrant version

Message ID 20241104111037.3632161-14-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>
---
 drivers/bus/dpaa/base/fman/fman.c | 8 ++++++--
 drivers/bus/dpaa/dpaa_bus.c       | 5 ++++-
 2 files changed, 10 insertions(+), 3 deletions(-)
  

Patch

diff --git a/drivers/bus/dpaa/base/fman/fman.c b/drivers/bus/dpaa/base/fman/fman.c
index d49339d81e..d9593cf459 100644
--- a/drivers/bus/dpaa/base/fman/fman.c
+++ b/drivers/bus/dpaa/base/fman/fman.c
@@ -1132,6 +1132,7 @@  fman_init(void)
 void
 fman_finish(void)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct __fman_if *__if, *tmpif;
 
 	assert(fman_ccsr_map_fd != -1);
@@ -1153,8 +1154,11 @@  fman_finish(void)
 				 in_be32(__if->ccsr_map + 8) & ~(u32)3);
 		/* release the mapping */
 		_errno = munmap(__if->ccsr_map, __if->regs_size);
-		if (unlikely(_errno < 0))
-			FMAN_ERR(_errno, "munmap() = (%s)", strerror(errno));
+		if (unlikely(_errno < 0)) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+			FMAN_ERR(_errno, "munmap() = (%s)", errmsg);
+		}
 		DPAA_BUS_INFO("Tearing down %s", __if->node_path);
 		list_del(&__if->__if.node);
 		rte_free(__if);
diff --git a/drivers/bus/dpaa/dpaa_bus.c b/drivers/bus/dpaa/dpaa_bus.c
index 9ffbe07c93..8fabd74899 100644
--- a/drivers/bus/dpaa/dpaa_bus.c
+++ b/drivers/bus/dpaa/dpaa_bus.c
@@ -627,12 +627,15 @@  rte_dpaa_bus_dev_build(void)
 
 static int rte_dpaa_setup_intr(struct rte_intr_handle *intr_handle)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int fd;
 
 	fd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
 	if (fd < 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		DPAA_BUS_ERR("Cannot set up eventfd, error %i (%s)",
-			     errno, strerror(errno));
+			     errno, errmsg);
 		return errno;
 	}