[v5,43/52] net/qede: replace strerror with reentrant version

Message ID 20241104111037.3632161-44-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/qede/qede_regs.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/net/qede/qede_regs.c b/drivers/net/qede/qede_regs.c
index d2ea1c9108..ca8efd796e 100644
--- a/drivers/net/qede/qede_regs.c
+++ b/drivers/net/qede/qede_regs.c
@@ -213,6 +213,7 @@  qede_set_fw_dump_file_name(struct qede_dev *qdev)
 static int
 qede_write_fwdump(const char *dump_file, void *dump, size_t len)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	int err = 0;
 	FILE *f;
 	size_t bytes;
@@ -220,8 +221,10 @@  qede_write_fwdump(const char *dump_file, void *dump, size_t len)
 	f = fopen(dump_file, "wb+");
 
 	if (!f) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		fprintf(stderr, "Can't open file %s: %s\n",
-			dump_file, strerror(errno));
+			dump_file, errmsg);
 		return 1;
 	}
 	bytes = fwrite(dump, 1, len, f);
@@ -233,8 +236,10 @@  qede_write_fwdump(const char *dump_file, void *dump, size_t len)
 	}
 
 	if (fclose(f)) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		fprintf(stderr, "Can't close file %s: %s\n",
-			dump_file, strerror(errno));
+			dump_file, errmsg);
 		err = 1;
 	}