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: sta...@dpdk.org

Signed-off-by: Huisong Li <lihuis...@huawei.com>
---
 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

Reply via email to