[v5,30/52] net/dpaa2: replace strerror with reentrant version

Message ID 20241104111037.3632161-31-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/dpaa2/dpaa2_ethdev.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
  

Patch

diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c b/drivers/net/dpaa2/dpaa2_ethdev.c
index 7b3e587a8d..6a058e90f8 100644
--- a/drivers/net/dpaa2/dpaa2_ethdev.c
+++ b/drivers/net/dpaa2/dpaa2_ethdev.c
@@ -1163,22 +1163,28 @@  dpaa2_eth_setup_irqs(struct rte_eth_dev *dev, int enable)
 	struct fsl_mc_io *dpni = (struct fsl_mc_io *)dev->process_private;
 	int irq_index = DPNI_IRQ_INDEX;
 	unsigned int mask = DPNI_IRQ_EVENT_LINK_CHANGED;
+	char errmsg[RTE_STRERR_BUFSIZE];
 
 	PMD_INIT_FUNC_TRACE();
 
 	err = dpni_set_irq_mask(dpni, CMD_PRI_LOW, priv->token,
 				irq_index, mask);
 	if (err < 0) {
+		if (strerror_r(-err, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -err);
 		DPAA2_PMD_ERR("Error: dpni_set_irq_mask():%d (%s)", err,
-			      strerror(-err));
+			      errmsg);
 		return err;
 	}
 
 	err = dpni_set_irq_enable(dpni, CMD_PRI_LOW, priv->token,
 				  irq_index, enable);
-	if (err < 0)
+	if (err < 0) {
+		if (strerror_r(-err, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -err);
 		DPAA2_PMD_ERR("Error: dpni_set_irq_enable():%d (%s)", err,
-			      strerror(-err));
+			      errmsg);
+	}
 
 	return err;
 }