[v5,31/52] net/enetfec: replace strerror with reentrant version

Message ID 20241104111037.3632161-32-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:10 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/net/enetfec/enet_uio.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/net/enetfec/enet_uio.c b/drivers/net/enetfec/enet_uio.c
index 9f4e896985..c4d4e60c64 100644
--- a/drivers/net/enetfec/enet_uio.c
+++ b/drivers/net/enetfec/enet_uio.c
@@ -222,6 +222,7 @@  config_enetfec_uio(struct enetfec_private *fep)
 int
 enetfec_configure(void)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	char uio_name[32];
 	int uio_minor_number = -1;
 	int ret;
@@ -230,8 +231,10 @@  enetfec_configure(void)
 
 	d = opendir(FEC_UIO_DEVICE_SYS_ATTR_PATH);
 	if (d == NULL) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		ENETFEC_PMD_ERR("Error opening directory '%s': %s",
-			FEC_UIO_DEVICE_SYS_ATTR_PATH, strerror(errno));
+			FEC_UIO_DEVICE_SYS_ATTR_PATH, errmsg);
 		return -1;
 	}