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 2422445C76; Mon, 4 Nov 2024 12:12:01 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2475F40ED2; Mon, 4 Nov 2024 12:10:56 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id D70E840E2E for ; Mon, 4 Nov 2024 12:10:42 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.88.194]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Xhpbn6bwszfdh7; Mon, 4 Nov 2024 19:08:05 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id D63811400F4; 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 21/52] crypto/caam_jr: replace strerror with reentrant version Date: Mon, 4 Nov 2024 19:10:06 +0800 Message-ID: <20241104111037.3632161-22-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/crypto/caam_jr/caam_jr_uio.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/drivers/crypto/caam_jr/caam_jr_uio.c b/drivers/crypto/caam_jr/caam_jr_uio.c index 8956f7750d..13e982c9f4 100644 --- a/drivers/crypto/caam_jr/caam_jr_uio.c +++ b/drivers/crypto/caam_jr/caam_jr_uio.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -325,6 +326,7 @@ void free_job_ring(int uio_fd) { struct uio_job_ring *job_ring = NULL; + char errmsg[RTE_STRERR_BUFSIZE]; int i; if (uio_fd == -1) @@ -353,9 +355,11 @@ free_job_ring(int uio_fd) /* Unmap the PCI memory resource of device */ if (munmap(job_ring->register_base_addr, job_ring->map_size)) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); CAAM_JR_INFO("cannot munmap(%p, 0x%lx): %s", job_ring->register_base_addr, - (unsigned long)job_ring->map_size, strerror(errno)); + (unsigned long)job_ring->map_size, errmsg); } else CAAM_JR_DEBUG("JR UIO memory is unmapped"); @@ -409,6 +413,7 @@ uio_job_ring *config_job_ring(void) int sec_configure(void) { + char errmsg[RTE_STRERR_BUFSIZE]; char uio_name[32]; int config_jr_no = 0, jr_id = -1; int uio_minor_number = -1; @@ -418,8 +423,10 @@ sec_configure(void) d = opendir(SEC_UIO_DEVICE_SYS_ATTR_PATH); if (d == NULL) { + if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno); CAAM_JR_ERR("Error opening directory '%s': %s", - SEC_UIO_DEVICE_SYS_ATTR_PATH, strerror(errno)); + SEC_UIO_DEVICE_SYS_ATTR_PATH, errmsg); return -1; } -- 2.33.0