Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: apoorva.singh@intel.com
To: intel-xe@lists.freedesktop.org
Cc: Apoorva Singh <apoorva.singh@intel.com>
Subject: [PATCH] drm/xe: Add NULL check before deferencing pointer
Date: Mon, 19 Aug 2024 12:45:57 +0530	[thread overview]
Message-ID: <20240819071557.964326-1-apoorva.singh@intel.com> (raw)

From: Apoorva Singh <apoorva.singh@intel.com>

Add NULL check before deferencing of lrc->bo in
xe_lrc_snapshot_capture().

Free the dynamically allocated memory for snapshot
to avoid memory leak

Signed-off-by: Apoorva Singh <apoorva.singh@intel.com>
---
 drivers/gpu/drm/xe/xe_lrc.c | 32 ++++++++++++++++++--------------
 1 file changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_lrc.c b/drivers/gpu/drm/xe/xe_lrc.c
index 974a9cd8c379..e31d9bc64ff6 100644
--- a/drivers/gpu/drm/xe/xe_lrc.c
+++ b/drivers/gpu/drm/xe/xe_lrc.c
@@ -1652,20 +1652,24 @@ struct xe_lrc_snapshot *xe_lrc_snapshot_capture(struct xe_lrc *lrc)
 	if (lrc->bo && lrc->bo->vm)
 		xe_vm_get(lrc->bo->vm);
 
-	snapshot->context_desc = xe_lrc_ggtt_addr(lrc);
-	snapshot->indirect_context_desc = xe_lrc_indirect_ring_ggtt_addr(lrc);
-	snapshot->head = xe_lrc_ring_head(lrc);
-	snapshot->tail.internal = lrc->ring.tail;
-	snapshot->tail.memory = xe_lrc_ring_tail(lrc);
-	snapshot->start_seqno = xe_lrc_start_seqno(lrc);
-	snapshot->seqno = xe_lrc_seqno(lrc);
-	snapshot->lrc_bo = xe_bo_get(lrc->bo);
-	snapshot->lrc_offset = xe_lrc_pphwsp_offset(lrc);
-	snapshot->lrc_size = lrc->bo->size - snapshot->lrc_offset;
-	snapshot->lrc_snapshot = NULL;
-	snapshot->ctx_timestamp = xe_lrc_ctx_timestamp(lrc);
-	snapshot->ctx_job_timestamp = xe_lrc_ctx_job_timestamp(lrc);
-	return snapshot;
+	if (lrc->bo) {
+		snapshot->context_desc = xe_lrc_ggtt_addr(lrc);
+		snapshot->indirect_context_desc = xe_lrc_indirect_ring_ggtt_addr(lrc);
+		snapshot->head = xe_lrc_ring_head(lrc);
+		snapshot->tail.internal = lrc->ring.tail;
+		snapshot->tail.memory = xe_lrc_ring_tail(lrc);
+		snapshot->start_seqno = xe_lrc_start_seqno(lrc);
+		snapshot->seqno = xe_lrc_seqno(lrc);
+		snapshot->lrc_bo = xe_bo_get(lrc->bo);
+		snapshot->lrc_offset = xe_lrc_pphwsp_offset(lrc);
+		snapshot->lrc_size = lrc->bo->size - snapshot->lrc_offset;
+		snapshot->lrc_snapshot = NULL;
+		snapshot->ctx_timestamp = xe_lrc_ctx_timestamp(lrc);
+		snapshot->ctx_job_timestamp = xe_lrc_ctx_job_timestamp(lrc);
+		return snapshot;
+	}
+	kfree(snapshot);
+	return NULL;
 }
 
 void xe_lrc_snapshot_capture_delayed(struct xe_lrc_snapshot *snapshot)
-- 
2.34.1


             reply	other threads:[~2024-08-19  7:17 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-19  7:15 apoorva.singh [this message]
2024-08-19  7:22 ` ✓ CI.Patch_applied: success for drm/xe: Add NULL check before deferencing pointer (rev2) Patchwork
2024-08-19  7:22 ` ✓ CI.checkpatch: " Patchwork
2024-08-19  7:24 ` ✓ CI.KUnit: " Patchwork
2024-08-19  7:35 ` ✓ CI.Build: " Patchwork
2024-08-19  7:38 ` ✓ CI.Hooks: " Patchwork
2024-08-19  7:39 ` ✓ CI.checksparse: " Patchwork
2024-08-19  7:54 ` ✓ CI.BAT: " Patchwork
2024-08-19  8:58 ` [PATCH] drm/xe: Add NULL check before deferencing pointer Jani Nikula
2024-08-19  9:33   ` Singh, Apoorva
2024-08-19  8:59 ` ✓ CI.FULL: success for drm/xe: Add NULL check before deferencing pointer (rev2) Patchwork
  -- strict thread matches above, loose matches on Subject: below --
2024-08-14 10:17 [PATCH] drm/xe: Add NULL check before deferencing pointer apoorva.singh
2024-08-14 11:02 ` Nirmoy Das
2024-08-14 16:42   ` Matthew Brost
2024-08-14 11:21 ` Jani Nikula

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240819071557.964326-1-apoorva.singh@intel.com \
    --to=apoorva.singh@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox