[v1,2/2] ethdev: fix some APIs can be used in the new event

Message ID 20250115034110.15245-3-lihuisong@huawei.com (mailing list archive)
State Superseded
Delegated to: Stephen Hemminger
Headers
Series ethdev: clarify something about new event |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/github-robot: build success github build: passed
ci/iol-mellanox-Performance success Performance Testing PASS
ci/intel-Functional success Functional PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/iol-marvell-Functional success Functional Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-unit-amd64-testing success Testing PASS
ci/iol-sample-apps-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-unit-arm64-testing success Testing PASS
ci/iol-compile-arm64-testing success Testing PASS
ci/iol-compile-amd64-testing success Testing PASS

Commit Message

Huisong Li Jan. 15, 2025, 3:41 a.m. UTC
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 <lihuisong@huawei.com>
---
 lib/ethdev/rte_ethdev.c | 14 +++++++++++---
 1 file changed, 11 insertions(+), 3 deletions(-)
  

Comments

Thomas Monjalon Jan. 15, 2025, 11:36 a.m. UTC | #1
15/01/2025 04:41, Huisong Li:
> 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.

You should be more explicit:
"during probing, before it becomes generally available and considered as valid".

Should we add these functions in the comment for RTE_ETH_EVENT_NEW?
  
Huisong Li Jan. 16, 2025, 6:14 a.m. UTC | #2
在 2025/1/15 19:36, Thomas Monjalon 写道:
> 15/01/2025 04:41, Huisong Li:
>> 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.
> You should be more explicit:
> "during probing, before it becomes generally available and considered as valid".
"During probing, before the port becomes generally available, its socket 
id and owner id can be considered as valid."
How about say it like this?
>
> Should we add these functions in the comment for RTE_ETH_EVENT_NEW?
Ack
>
>
> .
  
Thomas Monjalon Jan. 16, 2025, 9:09 a.m. UTC | #3
16/01/2025 07:14, lihuisong (C):
> 在 2025/1/15 19:36, Thomas Monjalon 写道:
> > 15/01/2025 04:41, Huisong Li:
> >> 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.
> > You should be more explicit:
> > "during probing, before it becomes generally available and considered as valid".
> "During probing, before the port becomes generally available, its socket 
> id and owner id can be considered as valid."
> How about say it like this?

I prefer when you give the function names, it is more explicit.
  
Huisong Li Jan. 16, 2025, 9:35 a.m. UTC | #4
在 2025/1/16 17:09, Thomas Monjalon 写道:
> 16/01/2025 07:14, lihuisong (C):
>> 在 2025/1/15 19:36, Thomas Monjalon 写道:
>>> 15/01/2025 04:41, Huisong Li:
>>>> 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.
>>> You should be more explicit:
>>> "during probing, before it becomes generally available and considered as valid".
>> "During probing, before the port becomes generally available, its socket
>> id and owner id can be considered as valid."
>> How about say it like this?
> I prefer when you give the function names, it is more explicit.
ok
>
>
>
> .
  

Patch

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;