From 1674c56dc30d0faacc642c40ff308c3944184564 Mon Sep 17 00:00:00 2001 From: Elena Agostini Date: Tue, 23 Nov 2021 00:42:07 +0000 Subject: [PATCH] gpudev: manage null parameters in memory functions The gpudev functions free, register and unregister return gracefully if input pointer is NULL or size 0, as API doc was indicating no-op accepted values. CUDA driver checks are removed because redundant with the checks added in gpudev library. Fixes: e818c4e2bf50 ("gpudev: add memory API") Signed-off-by: Elena Agostini --- drivers/gpu/cuda/cuda.c | 11 ----------- lib/gpudev/gpudev.c | 12 ++++++++++-- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/cuda/cuda.c b/drivers/gpu/cuda/cuda.c index 24ae630d04..a4869da186 100644 --- a/drivers/gpu/cuda/cuda.c +++ b/drivers/gpu/cuda/cuda.c @@ -569,8 +569,6 @@ cuda_mem_alloc(struct rte_gpu *dev, size_t size, void **ptr) if (dev == NULL) return -ENODEV; - if (size == 0) - return -EINVAL; /* Store current ctx */ res = pfn_cuCtxGetCurrent(¤t_ctx); @@ -652,9 +650,6 @@ cuda_mem_register(struct rte_gpu *dev, size_t size, void *ptr) if (dev == NULL) return -ENODEV; - if (size == 0 || ptr == NULL) - return -EINVAL; - /* Store current ctx */ res = pfn_cuCtxGetCurrent(¤t_ctx); if (res != 0) { @@ -764,9 +759,6 @@ cuda_mem_free(struct rte_gpu *dev, void *ptr) if (dev == NULL) return -ENODEV; - if (ptr == NULL) - return -EINVAL; - hk = get_hash_from_ptr((void *)ptr); mem_item = mem_list_find_item(hk); @@ -803,9 +795,6 @@ cuda_mem_unregister(struct rte_gpu *dev, void *ptr) if (dev == NULL) return -ENODEV; - if (ptr == NULL) - return -EINVAL; - hk = get_hash_from_ptr((void *)ptr); mem_item = mem_list_find_item(hk); diff --git a/lib/gpudev/gpudev.c b/lib/gpudev/gpudev.c index 2b174d8bd5..1d8200e71b 100644 --- a/lib/gpudev/gpudev.c +++ b/lib/gpudev/gpudev.c @@ -580,6 +580,10 @@ rte_gpu_mem_free(int16_t dev_id, void *ptr) rte_errno = ENOTSUP; return -rte_errno; } + + if (ptr == NULL) /* dry-run */ + return 0; + return GPU_DRV_RET(dev->ops.mem_free(dev, ptr)); } @@ -601,8 +605,8 @@ rte_gpu_mem_register(int16_t dev_id, size_t size, void *ptr) return -rte_errno; } - if (size == 0 || ptr == NULL) /* dry-run */ - return -EINVAL; + if (ptr == NULL || size == 0) /* dry-run */ + return 0; return GPU_DRV_RET(dev->ops.mem_register(dev, size, ptr)); } @@ -623,6 +627,10 @@ rte_gpu_mem_unregister(int16_t dev_id, void *ptr) rte_errno = ENOTSUP; return -rte_errno; } + + if (ptr == NULL) /* dry-run */ + return 0; + return GPU_DRV_RET(dev->ops.mem_unregister(dev, ptr)); }