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