[8/9] panfrost: Handle the bo == NULL case in panfrost_bo_[un]reference()

Submitted by Boris Brezillon on Aug. 2, 2019, 10:12 a.m.

Details

Message ID 20190802101257.10495-9-boris.brezillon@collabora.com
State Accepted
Commit ed501c00cb6c723b13e10f10b02f9c675fc23d98
Headers show
Series "panfrost: Allocate the polygon lists on-demand" ( rev: 1 ) in Mesa

Commit Message

Boris Brezillon Aug. 2, 2019, 10:12 a.m.
Allows us to pass BOs without checking if they're NULL or not.

Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
---
 src/gallium/drivers/panfrost/pan_resource.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
index 71da383d4c7a..f74a39555b45 100644
--- a/src/gallium/drivers/panfrost/pan_resource.c
+++ b/src/gallium/drivers/panfrost/pan_resource.c
@@ -443,12 +443,16 @@  panfrost_resource_create(struct pipe_screen *screen,
 void
 panfrost_bo_reference(struct panfrost_bo *bo)
 {
-        pipe_reference(NULL, &bo->reference);
+        if (bo)
+                pipe_reference(NULL, &bo->reference);
 }
 
 void
 panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo)
 {
+        if (!bo)
+                return;
+
         /* When the reference count goes to zero, we need to cleanup */
 
         if (pipe_reference(&bo->reference, NULL))

Comments


On Fri, 2 Aug 2019 08:14:05 -0700
Alyssa Rosenzweig <alyssa.rosenzweig@collabora.com> wrote:

> Is there any cleanup we can simultaneously? (Where the check was done
> outside?) Or is this a futureproofing?

Was hitting a NULL pointer dereference when on the
panfrost_bo_unreference(job->polygon_list) done in panfrost_free_job().
Don't know having a NULL polygon_list is valid case (I guess that's
possible for a job that does not involve the tiler) but I was facing
this problem when running the deqp testsuite.

> 
> On Fri, Aug 02, 2019 at 12:12:56PM +0200, Boris Brezillon wrote:
> > Allows us to pass BOs without checking if they're NULL or not.
> > 
> > Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com>
> > ---
> >  src/gallium/drivers/panfrost/pan_resource.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> > 
> > diff --git a/src/gallium/drivers/panfrost/pan_resource.c b/src/gallium/drivers/panfrost/pan_resource.c
> > index 71da383d4c7a..f74a39555b45 100644
> > --- a/src/gallium/drivers/panfrost/pan_resource.c
> > +++ b/src/gallium/drivers/panfrost/pan_resource.c
> > @@ -443,12 +443,16 @@ panfrost_resource_create(struct pipe_screen *screen,
> >  void
> >  panfrost_bo_reference(struct panfrost_bo *bo)
> >  {
> > -        pipe_reference(NULL, &bo->reference);
> > +        if (bo)
> > +                pipe_reference(NULL, &bo->reference);
> >  }
> >  
> >  void
> >  panfrost_bo_unreference(struct pipe_screen *screen, struct panfrost_bo *bo)
> >  {
> > +        if (!bo)
> > +                return;
> > +
> >          /* When the reference count goes to zero, we need to cleanup */
> >  
> >          if (pipe_reference(&bo->reference, NULL))
> > -- 
> > 2.21.0
> >