Re: [PATCH v3] gpudev: manage NULL pointer
From: Elena Agostini <hidden>
Date: 2021-11-22 11:34:54
From: Thomas Monjalon <redacted> Date: Monday, 22 November 2021 at 12:23 To: Elena Agostini <redacted> Cc: dev@dpdk.org <redacted> Subject: Re: [PATCH v3] gpudev: manage NULL pointer External email: Use caution opening links or attachments>
22/11/2021 19:24, eagostini@nvidia.com:quoted
From: Elena Agostini <redacted> gpudev free and unregister functions return gracefully if input pointer is NULL>
We could add that the API doc was indicating NULL as a no-op accepted value.>
Another explanation to add: cuda driver checks are removed because redundant with the checks added in gpudev library.>
quoted
Fixes: 818a067baf90 ("gpudev: manage NULL pointer")>
It should be:
Fixes: e818c4e2bf50 ("gpudev: add memory API")>quoted
Signed-off-by: Elena Agostini <redacted> --- drivers/gpu/cuda/cuda.c | 6 ------ lib/gpudev/gpudev.c | 6 ++++++ 2 files changed, 6 insertions(+), 6 deletions(-)[...]quoted
--- a/lib/gpudev/gpudev.c +++ b/lib/gpudev/gpudev.c@@ -569,6 +569,9 @@ rte_gpu_mem_free(int16_t dev_id, void *ptr) { struct rte_gpu *dev; + if (ptr == NULL) + return 0; + dev = gpu_get_by_id(dev_id); if (dev == NULL) { GPU_LOG(ERR, "free mem for invalid device ID %d", dev_id);>
I think we should keep this check first.
Why should gpudev waste more latency in looking for the device if the ptr is NULL?
quoted
@@ -612,6 +615,9 @@ rte_gpu_mem_unregister(int16_t dev_id, void *ptr) { struct rte_gpu *dev; + if (ptr == NULL) + return 0; + dev = gpu_get_by_id(dev_id); if (dev == NULL) { GPU_LOG(ERR, "unregister mem for invalid device ID %d", dev_id);>
Same here.
There is third function where NULL should be accepted: rte_gpu_mem_register>
Thanks, let me add it