Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Jani Nikula <jani.nikula@linux.intel.com>
To: apoorva.singh@intel.com, intel-xe@lists.freedesktop.org
Cc: Apoorva Singh <apoorva.singh@intel.com>
Subject: Re: [PATCH] drm/xe: Add NULL check before deferencing pointer
Date: Mon, 19 Aug 2024 11:58:13 +0300	[thread overview]
Message-ID: <87v7zw6g9m.fsf@intel.com> (raw)
In-Reply-To: <20240819071557.964326-1-apoorva.singh@intel.com>

On Mon, 19 Aug 2024, apoorva.singh@intel.com wrote:
> From: Apoorva Singh <apoorva.singh@intel.com>

*dereferencing typo in the subject. You could also be more specific,
that subject could refer to anything anywhere in the driver. If you find
another one, what's its subject going to be?

> Add NULL check before deferencing of lrc->bo in
> xe_lrc_snapshot_capture().
>
> Free the dynamically allocated memory for snapshot
> to avoid memory leak

We've seen this patch or its variants many times now. Where's the
changelog? What's going on?

> 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) {

Please handle error cases in if branches with early returns, and do the
happy day scenario in the top indentation level.


BR,
Jani.


> +		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)

-- 
Jani Nikula, Intel

  parent reply	other threads:[~2024-08-19  8:58 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-19  7:15 [PATCH] drm/xe: Add NULL check before deferencing pointer apoorva.singh
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 ` Jani Nikula [this message]
2024-08-19  9:33   ` [PATCH] drm/xe: Add NULL check before deferencing pointer 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=87v7zw6g9m.fsf@intel.com \
    --to=jani.nikula@linux.intel.com \
    --cc=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