[PATCH v5 18/52] common/cnxk: replace strerror with reentrant version
Dengdui Huang
huangdengdui at huawei.com
Mon Nov 4 12:10:03 CET 2024
The function strerror() is insecure in a multi-thread environment.
This patch uses strerror_r() to replace it.
Signed-off-by: Dengdui Huang <huangdengdui at huawei.com>
Acked-by: Chengwen Feng <fengchengwen at huawei.com>
Acked-by: Morten Brørup <mb at smartsharesystems.com>
Acked-by: Huisong Li <lihuisong at huawei.com>
---
drivers/common/cnxk/roc_dev.c | 12 ++++++++++--
drivers/common/cnxk/roc_model.c | 8 ++++++--
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/drivers/common/cnxk/roc_dev.c b/drivers/common/cnxk/roc_dev.c
index 45f007325e..74c71036fe 100644
--- a/drivers/common/cnxk/roc_dev.c
+++ b/drivers/common/cnxk/roc_dev.c
@@ -8,6 +8,8 @@
#include <sys/mman.h>
#include <unistd.h>
+#include <rte_errno.h>
+
#include "roc_api.h"
#include "roc_priv.h"
@@ -1303,6 +1305,7 @@ dev_vf_hwcap_update(struct plt_pci_device *pci_dev, struct dev *dev)
static uintptr_t
cn20k_pfvf_mbox_alloc(struct dev *dev, uint16_t max_vfs)
{
+ char errmsg[RTE_STRERR_BUFSIZE];
char name[PLT_MEMZONE_NAMESIZE];
const struct plt_memzone *mz;
uint32_t vf_mbox_region;
@@ -1313,7 +1316,9 @@ cn20k_pfvf_mbox_alloc(struct dev *dev, uint16_t max_vfs)
mz = plt_memzone_reserve_aligned(name, vf_mbox_region, 0, MBOX_SIZE);
if (!mz) {
- plt_err("Memory alloc failed: %s", strerror(errno));
+ if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+ snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+ plt_err("Memory alloc failed: %s", errmsg);
goto fail;
}
@@ -1397,6 +1402,7 @@ dev_setup_shared_lmt_region(struct mbox *mbox, bool valid_iova, uint64_t iova)
static int
dev_lmt_setup(struct dev *dev)
{
+ char errmsg[RTE_STRERR_BUFSIZE];
char name[PLT_MEMZONE_NAMESIZE];
const struct plt_memzone *mz;
struct idev_cfg *idev;
@@ -1435,7 +1441,9 @@ dev_lmt_setup(struct dev *dev)
*/
mz = plt_lmt_region_reserve_aligned(name, LMT_REGION_SIZE, LMT_REGION_SIZE);
if (!mz) {
- plt_err("Memory alloc failed: %s", strerror(errno));
+ if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+ snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+ plt_err("Memory alloc failed: %s", errmsg);
goto fail;
}
diff --git a/drivers/common/cnxk/roc_model.c b/drivers/common/cnxk/roc_model.c
index 6289461db4..63288e53ff 100644
--- a/drivers/common/cnxk/roc_model.c
+++ b/drivers/common/cnxk/roc_model.c
@@ -6,6 +6,8 @@
#include <fcntl.h>
#include <unistd.h>
+#include <rte_errno.h>
+
#include "roc_api.h"
#include "roc_priv.h"
@@ -149,6 +151,7 @@ static int
cn10k_part_pass_get(uint32_t *part, uint32_t *pass)
{
#define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
+ char errmsg[RTE_STRERR_BUFSIZE];
char dirname[PATH_MAX];
struct dirent *e;
int ret = -1;
@@ -156,8 +159,9 @@ cn10k_part_pass_get(uint32_t *part, uint32_t *pass)
dir = opendir(SYSFS_PCI_DEVICES);
if (dir == NULL) {
- plt_err("%s(): opendir failed: %s", __func__,
- strerror(errno));
+ if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+ snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+ plt_err("%s(): opendir failed: %s", __func__, errmsg);
return -errno;
}
--
2.33.0
More information about the dev
mailing list