From: Elena Agostini <eagost...@nvidia.com>

gpudev free and unregister functions return
gracefully if input pointer is NULL because
API doc was indicating NULL as a no-op
accepted value.

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 <eagost...@nvidia.com>
---
 drivers/gpu/cuda/cuda.c | 6 ------
 lib/gpudev/gpudev.c     | 9 +++++++++
 2 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/cuda/cuda.c b/drivers/gpu/cuda/cuda.c
index 24ae630d04..47a3bbf256 100644
--- a/drivers/gpu/cuda/cuda.c
+++ b/drivers/gpu/cuda/cuda.c
@@ -764,9 +764,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 +800,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..d6224a3828 100644
--- a/lib/gpudev/gpudev.c
+++ b/lib/gpudev/gpudev.c
@@ -576,6 +576,9 @@ rte_gpu_mem_free(int16_t dev_id, void *ptr)
                return -rte_errno;
        }
 
+       if (ptr == NULL)
+               return 0;
+
        if (dev->ops.mem_free == NULL) {
                rte_errno = ENOTSUP;
                return -rte_errno;
@@ -595,6 +598,9 @@ rte_gpu_mem_register(int16_t dev_id, size_t size, void *ptr)
                return -rte_errno;
        }
 
+       if (ptr == NULL)
+               return 0;
+
        if (dev->ops.mem_register == NULL) {
                GPU_LOG(ERR, "mem registration not supported");
                rte_errno = ENOTSUP;
@@ -619,6 +625,9 @@ rte_gpu_mem_unregister(int16_t dev_id, void *ptr)
                return -rte_errno;
        }
 
+       if( ptr == NULL)
+               return 0;
+
        if (dev->ops.mem_unregister == NULL) {
                rte_errno = ENOTSUP;
                return -rte_errno;
-- 
2.17.1

Reply via email to