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 EAED445C76; Mon, 4 Nov 2024 12:12:47 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 6FD8E410DF; Mon, 4 Nov 2024 12:11:04 +0100 (CET) Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by mails.dpdk.org (Postfix) with ESMTP id E495440E34 for ; Mon, 4 Nov 2024 12:10:43 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Xhpcp2TTYzyVPV; Mon, 4 Nov 2024 19:08:58 +0800 (CST) Received: from dggpeml500011.china.huawei.com (unknown [7.185.36.84]) by mail.maildlp.com (Postfix) with ESMTPS id DE65A180105; Mon, 4 Nov 2024 19:10:42 +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:42 +0800 From: Dengdui Huang To: CC: , , , , , , , , , , Subject: [PATCH v5 26/52] net/bonding: replace strerror with reentrant version Date: Mon, 4 Nov 2024 19:10:11 +0800 Message-ID: <20241104111037.3632161-27-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/net/bonding/bonding_testpmd.c | 18 ++++++++++++------ drivers/net/bonding/rte_eth_bond_api.c | 5 ++++- drivers/net/bonding/rte_eth_bond_pmd.c | 16 ++++++++++++---- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/drivers/net/bonding/bonding_testpmd.c b/drivers/net/bonding/bonding_testpmd.c index 8fcd6cadd0..56cca3d447 100644 --- a/drivers/net/bonding/bonding_testpmd.c +++ b/drivers/net/bonding/bonding_testpmd.c @@ -541,6 +541,7 @@ static void cmd_set_bond_mac_addr_parsed(void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data) { struct cmd_set_bond_mac_addr_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; int ret; if (port_id_is_invalid(res->port_num, ENABLED_WARN)) @@ -549,9 +550,11 @@ static void cmd_set_bond_mac_addr_parsed(void *parsed_result, ret = rte_eth_bond_mac_address_set(res->port_num, &res->address); /* check the return value and print it if is < 0 */ - if (ret < 0) - fprintf(stderr, "set_bond_mac_addr error: (%s)\n", - strerror(-ret)); + if (ret < 0) { + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); + fprintf(stderr, "set_bond_mac_addr error: (%s)\n", errmsg); + } } static cmdline_parse_token_string_t cmd_set_bond_mac_addr_set = @@ -597,14 +600,17 @@ static void cmd_set_bond_mon_period_parsed(void *parsed_result, __rte_unused struct cmdline *cl, __rte_unused void *data) { struct cmd_set_bond_mon_period_result *res = parsed_result; + char errmsg[RTE_STRERR_BUFSIZE]; int ret; ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms); /* check the return value and print it if is < 0 */ - if (ret < 0) - fprintf(stderr, "set_bond_mac_addr error: (%s)\n", - strerror(-ret)); + if (ret < 0) { + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); + fprintf(stderr, "set_bond_mac_addr error: (%s)\n", errmsg); + } } static cmdline_parse_token_string_t cmd_set_bond_mon_period_set = diff --git a/drivers/net/bonding/rte_eth_bond_api.c b/drivers/net/bonding/rte_eth_bond_api.c index ffc1322047..11a37dd142 100644 --- a/drivers/net/bonding/rte_eth_bond_api.c +++ b/drivers/net/bonding/rte_eth_bond_api.c @@ -465,6 +465,7 @@ __eth_bond_member_add_lock_free(uint16_t bonding_port_id, uint16_t member_port_i struct bond_dev_private *internals; struct rte_eth_link link_props; struct rte_eth_dev_info dev_info; + char errmsg[RTE_STRERR_BUFSIZE]; int ret; bonding_eth_dev = &rte_eth_devices[bonding_port_id]; @@ -481,9 +482,11 @@ __eth_bond_member_add_lock_free(uint16_t bonding_port_id, uint16_t member_port_i ret = rte_eth_dev_info_get(member_port_id, &dev_info); if (ret != 0) { + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); RTE_BOND_LOG(ERR, "%s: Error during getting device (port %u) info: %s", - __func__, member_port_id, strerror(-ret)); + __func__, member_port_id, errmsg); return ret; } diff --git a/drivers/net/bonding/rte_eth_bond_pmd.c b/drivers/net/bonding/rte_eth_bond_pmd.c index 91bf2c2345..9849e0ecb0 100644 --- a/drivers/net/bonding/rte_eth_bond_pmd.c +++ b/drivers/net/bonding/rte_eth_bond_pmd.c @@ -165,6 +165,7 @@ bond_ethdev_8023ad_flow_verify(struct rte_eth_dev *bond_dev, struct rte_eth_dev_info member_info; struct rte_flow_error error; struct bond_dev_private *internals = bond_dev->data->dev_private; + char errmsg[RTE_STRERR_BUFSIZE]; const struct rte_flow_action_queue lacp_queue_conf = { .index = 0, @@ -191,9 +192,11 @@ bond_ethdev_8023ad_flow_verify(struct rte_eth_dev *bond_dev, ret = rte_eth_dev_info_get(member_port, &member_info); if (ret != 0) { + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); RTE_BOND_LOG(ERR, "%s: Error during getting device (port %u) info: %s", - __func__, member_port, strerror(-ret)); + __func__, member_port, errmsg); return ret; } @@ -214,6 +217,7 @@ bond_8023ad_slow_pkt_hw_filter_supported(uint16_t port_id) { struct rte_eth_dev *bond_dev = &rte_eth_devices[port_id]; struct bond_dev_private *internals = bond_dev->data->dev_private; struct rte_eth_dev_info bond_info; + char errmsg[RTE_STRERR_BUFSIZE]; uint16_t idx; int ret; @@ -221,10 +225,11 @@ bond_8023ad_slow_pkt_hw_filter_supported(uint16_t port_id) { if (internals->member_count > 0) { ret = rte_eth_dev_info_get(bond_dev->data->port_id, &bond_info); if (ret != 0) { + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); RTE_BOND_LOG(ERR, "%s: Error during getting device (port %u) info: %s", - __func__, bond_dev->data->port_id, - strerror(-ret)); + __func__, bond_dev->data->port_id, errmsg); return ret; } @@ -2264,6 +2269,7 @@ bond_ethdev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) { struct bond_dev_private *internals = dev->data->dev_private; struct bond_member_details member; + char errmsg[RTE_STRERR_BUFSIZE]; int ret; uint16_t max_nb_rx_queues = UINT16_MAX; @@ -2287,11 +2293,13 @@ bond_ethdev_info(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info) member = internals->members[idx]; ret = rte_eth_dev_info_get(member.port_id, &member_info); if (ret != 0) { + if (strerror_r(-ret, errmsg, sizeof(errmsg)) != 0) + snprintf(errmsg, sizeof(errmsg), "Unknown error %d", -ret); RTE_BOND_LOG(ERR, "%s: Error during getting device (port %u) info: %s", __func__, member.port_id, - strerror(-ret)); + errmsg); return ret; } -- 2.33.0