a6f750f
From patchwork Thu Feb  9 18:16:00 2017
a6f750f
Content-Type: text/plain; charset="utf-8"
a6f750f
MIME-Version: 1.0
a6f750f
Content-Transfer-Encoding: 7bit
a6f750f
Subject: drm/vc4: Fix OOPSes from trying to cache a partially constructed BO.
a6f750f
From: Eric Anholt <eric@anholt.net>
a6f750f
X-Patchwork-Id: 138087
a6f750f
Message-Id: <20170209181600.24048-1-eric@anholt.net>
a6f750f
To: dri-devel@lists.freedesktop.org
a6f750f
Cc: linux-kernel@vger.kernel.org, pbrobinson@gmail.com
a6f750f
Date: Thu,  9 Feb 2017 10:16:00 -0800
a6f750f
a6f750f
If a CMA allocation failed, the partially constructed BO would be
a6f750f
unreferenced through the normal path, and we might choose to put it in
a6f750f
the BO cache.  If we then reused it before it expired from the cache,
a6f750f
the kernel would OOPS.
a6f750f
a6f750f
Signed-off-by: Eric Anholt <eric@anholt.net>
a6f750f
Fixes: c826a6e10644 ("drm/vc4: Add a BO cache.")
a6f750f
---
a6f750f
 drivers/gpu/drm/vc4/vc4_bo.c | 8 ++++++++
a6f750f
 1 file changed, 8 insertions(+)
a6f750f
a6f750f
diff --git a/drivers/gpu/drm/vc4/vc4_bo.c b/drivers/gpu/drm/vc4/vc4_bo.c
a6f750f
index 5ec14f25625d..fd83a2807656 100644
a6f750f
--- a/drivers/gpu/drm/vc4/vc4_bo.c
a6f750f
+++ b/drivers/gpu/drm/vc4/vc4_bo.c
a6f750f
@@ -314,6 +314,14 @@ void vc4_free_object(struct drm_gem_object *gem_bo)
a6f750f
 		goto out;
a6f750f
 	}
a6f750f
 
a6f750f
+	/* If this object was partially constructed but CMA allocation
a6f750f
+	 * had failed, just free it.
a6f750f
+	 */
a6f750f
+	if (!bo->base.vaddr) {
a6f750f
+		vc4_bo_destroy(bo);
a6f750f
+		goto out;
a6f750f
+	}
a6f750f
+
a6f750f
 	cache_list = vc4_get_cache_list_for_size(dev, gem_bo->size);
a6f750f
 	if (!cache_list) {
a6f750f
 		vc4_bo_destroy(bo);