From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id EB02445C76; Mon, 4 Nov 2024 12:16:23 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 46AA442B71; Mon, 4 Nov 2024 12:11:43 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 514E140659 for ; Mon, 4 Nov 2024 12:10:44 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.252]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4XhpcZ5tGhzpXyM; Mon, 4 Nov 2024 19:08:46 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id 5E8401800A7; Mon, 4 Nov 2024 19:10:41 +0800 (CST) Received: from localhost.huawei.com (10.50.165.33) by dggpeml500011.china.huawei.com (7.185.36.84) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Mon, 4 Nov 2024 19:10:41 +0800 From: Dengdui Huang To: CC: , , , , , , , , , , Subject: [PATCH v5 18/52] common/cnxk: replace strerror with reentrant version Date: Mon, 4 Nov 2024 19:10:03 +0800 Message-ID: <20241104111037.3632161-19-huangdengdui@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20241104111037.3632161-1-huangdengdui@huawei.com> References: <20231114082539.1858594-1-huangdengdui@huawei.com> <20241104111037.3632161-1-huangdengdui@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.50.165.33] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpeml500011.china.huawei.com (7.185.36.84) X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org The function strerror() is insecure in a multi-thread environment. This patch uses strerror_r() to replace it. Signed-off-by: Dengdui Huang Acked-by: Chengwen Feng Acked-by: Morten Brørup Acked-by: Huisong Li --- 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 #include +#include + #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 #include +#include + #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