> From: Thomas Monjalon <thomas@monjalon.net>

> Date: Monday, 22 November 2021 at 12:23

> To: Elena Agostini <eagostini@nvidia.com>

> Cc: dev@dpdk.org <dev@dpdk.org>

> Subject: Re: [PATCH v3] gpudev: manage NULL pointer

> External email: Use caution opening links or attachments>

>

 

> 22/11/2021 19:24, eagostini@nvidia.com:

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

> >

> > 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.>

 

> > Fixes: 818a067baf90 ("gpudev: manage NULL pointer")>

 

> It should be:

> Fixes: e818c4e2bf50 ("gpudev: add memory API")>

 

> >

> > Signed-off-by: Elena Agostini <eagostini@nvidia.com>

> > ---

> >  drivers/gpu/cuda/cuda.c | 6 ------

> >  lib/gpudev/gpudev.c     | 6 ++++++

> >  2 files changed, 6 insertions(+), 6 deletions(-)

> [...]

> > --- 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?

 

> > @@ -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