From b3506b8bc45ed6d4005eb32a994df0e33d6613f1 Mon Sep 17 00:00:00 2001
From: Donald Robson <donald.robson@imgtec.com>
Date: Tue, 31 Oct 2023 16:26:07 +0000
Subject: [PATCH] drm/imagination: Fixed null deref in
 pvr_queue_cleanup_fw_context()

When sending a bad stream ptr through the CREATE_CONTEXT ioctl it was
possible to create queues without a fw ctx being alloced, but the
error path tried to clean it up all the same.

Signed-off-by: Donald Robson <donald.robson@imgtec.com>
---
 drivers/gpu/drm/imagination/pvr_queue.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/gpu/drm/imagination/pvr_queue.c b/drivers/gpu/drm/imagination/pvr_queue.c
index c1e7bc57eface..d72fd8d715a77 100644
--- a/drivers/gpu/drm/imagination/pvr_queue.c
+++ b/drivers/gpu/drm/imagination/pvr_queue.c
@@ -1152,6 +1152,9 @@ static void init_fw_context(struct pvr_queue *queue, void *fw_ctx_map)
  */
 static int pvr_queue_cleanup_fw_context(struct pvr_queue *queue)
 {
+	if (!queue->ctx->fw_obj)
+		return 0;
+
 	return pvr_fw_structure_cleanup(queue->ctx->pvr_dev,
 					ROGUE_FWIF_CLEANUP_FWCOMMONCONTEXT,
 					queue->ctx->fw_obj, queue->ctx_offset);
-- 
GitLab