[Mesa-dev] [PATCH 2/3] st/vdpau: fix bogus error handling in output/bitmap creation

Ilia Mirkin imirkin at alum.mit.edu
Fri Jan 17 20:58:23 PST 2014


Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
---

I can't say I'm happy about re-grabbing the mutex in the error path, but I
assume it must be taken to delete a sampler view. I could move the AddDataHTAB
thing inside the mutex, but I assumed it was like that for a reason -- could
be a perf issue? Or could be a non-issue, happy to switch it around.

The new failure paths haven't gotten much testing, but they couldn't be _more_
wrong than before, freeing dev.

 src/gallium/state_trackers/vdpau/bitmap.c | 26 ++++++++++++-------
 src/gallium/state_trackers/vdpau/output.c | 43 +++++++++++++------------------
 2 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/src/gallium/state_trackers/vdpau/bitmap.c b/src/gallium/state_trackers/vdpau/bitmap.c
index 469f3e8..6110fc7 100644
--- a/src/gallium/state_trackers/vdpau/bitmap.c
+++ b/src/gallium/state_trackers/vdpau/bitmap.c
@@ -45,6 +45,7 @@ vlVdpBitmapSurfaceCreate(VdpDevice device,
    struct pipe_context *pipe;
    struct pipe_resource res_tmpl, *res;
    struct pipe_sampler_view sv_templ;
+   VdpStatus ret;
 
    vlVdpBitmapSurface *vlsurface = NULL;
 
@@ -81,30 +82,37 @@ vlVdpBitmapSurfaceCreate(VdpDevice device,
    pipe_mutex_lock(dev->mutex);
    res = pipe->screen->resource_create(pipe->screen, &res_tmpl);
    if (!res) {
-      pipe_mutex_unlock(dev->mutex);
-      FREE(dev);
-      FREE(vlsurface);
-      return VDP_STATUS_RESOURCES;
+      ret = VDP_STATUS_RESOURCES;
+      goto err_unlock;
    }
 
    vlVdpDefaultSamplerViewTemplate(&sv_templ, res);
    vlsurface->sampler_view = pipe->create_sampler_view(pipe, res, &sv_templ);
 
    pipe_resource_reference(&res, NULL);
-   pipe_mutex_unlock(dev->mutex);
 
    if (!vlsurface->sampler_view) {
-      FREE(dev);
-      return VDP_STATUS_RESOURCES;
+      ret = VDP_STATUS_RESOURCES;
+      goto err_unlock;
    }
 
+   pipe_mutex_unlock(dev->mutex);
+
    *surface = vlAddDataHTAB(vlsurface);
    if (*surface == 0) {
-      FREE(dev);
-      return VDP_STATUS_ERROR;
+      pipe_mutex_lock(dev->mutex);
+      ret = VDP_STATUS_ERROR;
+      goto err_sampler;
    }
 
    return VDP_STATUS_OK;
+
+err_sampler:
+   pipe_sampler_view_reference(&vlsurface->sampler_view, NULL);
+err_unlock:
+   pipe_mutex_unlock(dev->mutex);
+   FREE(vlsurface);
+   return ret;
 }
 
 /**
diff --git a/src/gallium/state_trackers/vdpau/output.c b/src/gallium/state_trackers/vdpau/output.c
index e4e1433..58edd37 100644
--- a/src/gallium/state_trackers/vdpau/output.c
+++ b/src/gallium/state_trackers/vdpau/output.c
@@ -84,40 +84,24 @@ vlVdpOutputSurfaceCreate(VdpDevice device,
 
    pipe_mutex_lock(dev->mutex);
    res = pipe->screen->resource_create(pipe->screen, &res_tmpl);
-   if (!res) {
-      pipe_mutex_unlock(dev->mutex);
-      FREE(dev);
-      FREE(vlsurface);
-      return VDP_STATUS_ERROR;
-   }
+   if (!res)
+      goto err_unlock;
 
    vlVdpDefaultSamplerViewTemplate(&sv_templ, res);
    vlsurface->sampler_view = pipe->create_sampler_view(pipe, res, &sv_templ);
-   if (!vlsurface->sampler_view) {
-      pipe_resource_reference(&res, NULL);
-      pipe_mutex_unlock(dev->mutex);
-      FREE(dev);
-      return VDP_STATUS_ERROR;
-   }
+   if (!vlsurface->sampler_view)
+      goto err_resource;
 
    memset(&surf_templ, 0, sizeof(surf_templ));
    surf_templ.format = res->format;
    vlsurface->surface = pipe->create_surface(pipe, res, &surf_templ);
-   if (!vlsurface->surface) {
-      pipe_resource_reference(&res, NULL);
-      pipe_mutex_unlock(dev->mutex);
-      FREE(dev);
-      return VDP_STATUS_ERROR;
-   }
+   if (!vlsurface->surface)
+      goto err_resource;
 
    *surface = vlAddDataHTAB(vlsurface);
-   if (*surface == 0) {
-      pipe_resource_reference(&res, NULL);
-      pipe_mutex_unlock(dev->mutex);
-      FREE(dev);
-      return VDP_STATUS_ERROR;
-   }
-   
+   if (*surface == 0)
+      goto err_resource;
+
    pipe_resource_reference(&res, NULL);
 
    vl_compositor_init_state(&vlsurface->cstate, pipe);
@@ -125,6 +109,15 @@ vlVdpOutputSurfaceCreate(VdpDevice device,
    pipe_mutex_unlock(dev->mutex);
 
    return VDP_STATUS_OK;
+
+err_resource:
+   pipe_sampler_view_reference(&vlsurface->sampler_view, NULL);
+   pipe_surface_reference(&vlsurface->surface, NULL);
+   pipe_surface_reference(&res, NULL);
+err_unlock:
+   pipe_mutex_unlock(dev->mutex);
+   FREE(vlsurface);
+   return VDP_STATUS_ERROR;
 }
 
 /**
-- 
1.8.3.2



More information about the mesa-dev mailing list