[PATCH] drm/xe: Add NULL check before deferencing pointer
Matthew Brost
matthew.brost at intel.com
Wed Aug 14 16:42:49 UTC 2024
On Wed, Aug 14, 2024 at 01:02:45PM +0200, Nirmoy Das wrote:
>
> On 8/14/2024 12:17 PM, apoorva.singh at intel.com wrote:
> > From: Apoorva Singh <apoorva.singh at intel.com>
> >
> > - Add NULL check before deferencing of lrc->bo in
> > xe_lrc_snapshot_capture()
> >
> > Signed-off-by: Apoorva Singh <apoorva.singh at 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);
>
>
> Looking into xe_lrc_init(), it seems we are always allocating a bo for lrc
> so remove the NULL bo check instead.
>
I agree. I recently touched this area and thought the lrc->bo was
unnecessary but didn't care to remove it. Let's go ahead and do that.
Matt
>
> Regards,
>
> Nirmoy
>
> > - 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)
More information about the Intel-xe
mailing list