From 53c401502778c0a2fcb33df8cb2197ac72c9f73d Mon Sep 17 00:00:00 2001
From: Ilyes Gouta <ilyes.gouta@st.com>
Date: Fri, 3 Jan 2014 14:07:40 -0500
Subject: [PATCH - RFC 2/2] surfacepool: validate allocation::buffer before
 displacing a buffer

It could happen that the allocation's parent buffer (a CoreSurfaceBuffer)
has been released by the concurrent Fusion dispatch thread before
dfb_surfacemanager_displace() gets called. As such the associated
allocation and the underlying surface manager chunk should be accounted
as free.

Signed-off-by: Ilyes Gouta <ilyes.gouta@st.com>
---
 src/core/surface_pool.c         |    2 +-
 systems/devmem/surfacemanager.c |    2 +-
 systems/fbdev/surfacemanager.c  |    2 +-
 systems/x11/surfacemanager.c    |    2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/core/surface_pool.c b/src/core/surface_pool.c
index f31e8f7..6b06f9f 100644
--- a/src/core/surface_pool.c
+++ b/src/core/surface_pool.c
@@ -866,7 +866,7 @@ fixme_retry:
      fusion_vector_foreach (allocation, i, pool->allocs) {
           CORE_SURFACE_ALLOCATION_ASSERT( allocation );
 
-          if (allocation->flags & CSALF_MUCKOUT) {
+          if (allocation->buffer && (allocation->flags & CSALF_MUCKOUT)) {
                CoreSurface       *alloc_surface;
                CoreSurfaceBuffer *alloc_buffer;
 
diff --git a/systems/devmem/surfacemanager.c b/systems/devmem/surfacemanager.c
index 3a6dd3b..bdc6181 100644
--- a/systems/devmem/surfacemanager.c
+++ b/systems/devmem/surfacemanager.c
@@ -281,7 +281,7 @@ DFBResult dfb_surfacemanager_displace( CoreDFB           *core,
           D_MAGIC_ASSERT( chunk, Chunk );
 
           allocation = chunk->allocation;
-          if (allocation) {
+          if (allocation && allocation->buffer) {
                CoreSurfaceBuffer *other;
                int                size, locks;
 
diff --git a/systems/fbdev/surfacemanager.c b/systems/fbdev/surfacemanager.c
index 38beb25..6de8323 100644
--- a/systems/fbdev/surfacemanager.c
+++ b/systems/fbdev/surfacemanager.c
@@ -322,7 +322,7 @@ DFBResult dfb_surfacemanager_displace( CoreDFB           *core,
           D_MAGIC_ASSERT( chunk, Chunk );
 
           allocation = chunk->allocation;
-          if (allocation) {
+          if (allocation && allocation->buffer) {
                CoreSurfaceBuffer *other;
                int                size, locks;
 
diff --git a/systems/x11/surfacemanager.c b/systems/x11/surfacemanager.c
index 9988e25..3d84bbb 100644
--- a/systems/x11/surfacemanager.c
+++ b/systems/x11/surfacemanager.c
@@ -266,7 +266,7 @@ DFBResult dfb_surfacemanager_displace( CoreDFB           *core,
           D_MAGIC_ASSERT( chunk, Chunk );
 
           allocation = chunk->allocation;
-          if (allocation) {
+          if (allocation && allocation->buffer) {
                CoreSurfaceBuffer *other;
                int                size, locks;
 
-- 
1.7.7.6

