[PATCH v3] gpudev: manage NULL pointer

Elena Agostini eagostini at nvidia.com
Mon Nov 22 12:34:50 CET 2021


> From: Thomas Monjalon <thomas at monjalon.net>
> Date: Monday, 22 November 2021 at 12:23
> To: Elena Agostini <eagostini at nvidia.com>
> Cc: dev at dpdk.org <dev at dpdk.org>
> Subject: Re: [PATCH v3] gpudev: manage NULL pointer
> External email: Use caution opening links or attachments>
>

> 22/11/2021 19:24, eagostini at nvidia.com:
> > From: Elena Agostini <eagostini at 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 at 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mails.dpdk.org/archives/dev/attachments/20211122/22fe0a8b/attachment-0001.htm>


More information about the dev mailing list