[v5,52/52] vdpa/sfc: replace strerror with reentrant version

Message ID 20241104111037.3632161-53-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
ci/Intel-compilation warning apply issues

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/vdpa/sfc/sfc_vdpa_ops.c | 15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)
  

Patch

diff --git a/drivers/vdpa/sfc/sfc_vdpa_ops.c b/drivers/vdpa/sfc/sfc_vdpa_ops.c
index 00f9a4b04c..7e549075c4 100644
--- a/drivers/vdpa/sfc/sfc_vdpa_ops.c
+++ b/drivers/vdpa/sfc/sfc_vdpa_ops.c
@@ -106,6 +106,7 @@  sfc_vdpa_enable_vfio_intr(struct sfc_vdpa_ops_data *ops_data)
 	struct rte_vhost_vring vring;
 	struct vfio_irq_set *irq_set;
 	struct rte_pci_device *pci_dev;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	char irq_set_buf[SFC_VDPA_MSIX_IRQ_SET_BUF_LEN];
 	void *dev;
 
@@ -135,9 +136,11 @@  sfc_vdpa_enable_vfio_intr(struct sfc_vdpa_ops_data *ops_data)
 
 	rc = ioctl(vfio_dev_fd, VFIO_DEVICE_SET_IRQS, irq_set);
 	if (rc) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		sfc_vdpa_err(ops_data->dev_handle,
 			     "error enabling MSI-X interrupts: %s",
-			     strerror(errno));
+			     errmsg);
 		return -1;
 	}
 
@@ -150,6 +153,7 @@  sfc_vdpa_disable_vfio_intr(struct sfc_vdpa_ops_data *ops_data)
 	int rc;
 	int vfio_dev_fd;
 	struct vfio_irq_set irq_set;
+	char errmsg[RTE_STRERR_BUFSIZE];
 	void *dev;
 
 	dev = ops_data->dev_handle;
@@ -163,9 +167,11 @@  sfc_vdpa_disable_vfio_intr(struct sfc_vdpa_ops_data *ops_data)
 
 	rc = ioctl(vfio_dev_fd, VFIO_DEVICE_SET_IRQS, &irq_set);
 	if (rc) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		sfc_vdpa_err(ops_data->dev_handle,
 			     "error disabling MSI-X interrupts: %s",
-			     strerror(errno));
+			     errmsg);
 		return -1;
 	}
 
@@ -812,6 +818,7 @@  sfc_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size)
 	struct rte_vdpa_device *vdpa_dev;
 	struct sfc_vdpa_ops_data *ops_data;
 	struct vfio_region_info reg = { .argsz = sizeof(reg) };
+	char errmsg[RTE_STRERR_BUFSIZE];
 	const efx_nic_cfg_t *encp;
 	int max_vring_cnt;
 	int64_t len;
@@ -840,8 +847,10 @@  sfc_vdpa_get_notify_area(int vid, int qid, uint64_t *offset, uint64_t *size)
 	reg.index = sfc_vdpa_adapter_by_dev_handle(dev)->mem_bar.esb_rid;
 	ret = ioctl(vfio_dev_fd, VFIO_DEVICE_GET_REGION_INFO, &reg);
 	if (ret != 0) {
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 		sfc_vdpa_err(dev, "could not get device region info: %s",
-			     strerror(errno));
+			     errmsg);
 		return ret;
 	}