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 6D0CE46085; Wed, 15 Jan 2025 04:53:11 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id E5B6C402A0; Wed, 15 Jan 2025 04:53:10 +0100 (CET) Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mails.dpdk.org (Postfix) with ESMTP id 3AC104003C for ; Wed, 15 Jan 2025 04:53:08 +0100 (CET) Received: from mail.maildlp.com (unknown [172.19.163.174]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4YXsVk0ZMNzrS7Y; Wed, 15 Jan 2025 11:51:26 +0800 (CST) Received: from dggemv704-chm.china.huawei.com (unknown [10.3.19.47]) by mail.maildlp.com (Postfix) with ESMTPS id 5AA4D140203; Wed, 15 Jan 2025 11:53:06 +0800 (CST) Received: from kwepemn100009.china.huawei.com (7.202.194.112) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.39; Wed, 15 Jan 2025 11:53:06 +0800 Received: from localhost.localdomain (10.28.79.22) by kwepemn100009.china.huawei.com (7.202.194.112) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Wed, 15 Jan 2025 11:53:05 +0800 From: Huisong Li To: CC: , , , Subject: [PATCH v1 2/2] ethdev: fix some APIs can be used in the new event Date: Wed, 15 Jan 2025 11:41:10 +0800 Message-ID: <20250115034110.15245-3-lihuisong@huawei.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20250115034110.15245-1-lihuisong@huawei.com> References: <20250115034110.15245-1-lihuisong@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-Originating-IP: [10.28.79.22] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemn100009.china.huawei.com (7.202.194.112) 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 rte_eth_dev_socket_id() and rte_eth_dev_owner_*() can be used after allocating an ethdev. So this patch relaxes the conditions for using them. Fixes: 7dcd73e37965 ("drivers/bus: set device NUMA node to unknown by default") Fixes: 53ef1b34776b ("ethdev: add sanity checks in control APIs") Cc: stable@dpdk.org Signed-off-by: Huisong Li --- lib/ethdev/rte_ethdev.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c index 6413c54e3b..9cfb397cee 100644 --- a/lib/ethdev/rte_ethdev.c +++ b/lib/ethdev/rte_ethdev.c @@ -600,9 +600,10 @@ rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner) struct rte_eth_dev *ethdev; int ret; - RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); - ethdev = &rte_eth_devices[port_id]; + if (port_id >= RTE_MAX_ETHPORTS) + return -ENODEV; + ethdev = &rte_eth_devices[port_id]; if (!eth_dev_is_allocated(ethdev)) { RTE_ETHDEV_LOG_LINE(ERR, "Port ID %"PRIu16" is not allocated", port_id); @@ -635,8 +636,15 @@ int rte_eth_dev_socket_id(uint16_t port_id) { int socket_id = SOCKET_ID_ANY; + struct rte_eth_dev *ethdev; - if (!rte_eth_dev_is_valid_port(port_id)) { + if (port_id >= RTE_MAX_ETHPORTS) { + rte_errno = EINVAL; + return socket_id; + } + + ethdev = &rte_eth_devices[port_id]; + if (!eth_dev_is_allocated(ethdev)) { rte_errno = EINVAL; } else { socket_id = rte_eth_devices[port_id].data->numa_node; -- 2.22.0