Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Souza, Jose" <jose.souza@intel.com>
To: "Vivi, Rodrigo" <rodrigo.vivi@intel.com>
Cc: "intel-xe@lists.freedesktop.org" <intel-xe@lists.freedesktop.org>,
	"Dixit,  Ashutosh" <ashutosh.dixit@intel.com>,
	"Ghimiray, Himal Prasad" <himal.prasad.ghimiray@intel.com>
Subject: Re: [PATCH v3] drm/xe/xe_devcoredump: Check NULL before dereferencing
Date: Fri, 22 Mar 2024 16:08:31 +0000	[thread overview]
Message-ID: <4cd61e1479695ed6d48bf4c8ec90d897d4b584ee.camel@intel.com> (raw)
In-Reply-To: <Zf2oz5ItlLT97Qf7@intel.com>

On Fri, 2024-03-22 at 11:50 -0400, Rodrigo Vivi wrote:
> On Fri, Mar 22, 2024 at 09:57:32AM -0400, Souza, Jose wrote:
> > On Fri, 2024-03-22 at 09:28 +0530, Himal Prasad Ghimiray wrote:
> > > Dereference 'coredump' to access 'xe_devcoredump_snapshot' only if
> > > 'coredump' is not NULL,
> > > 
> > > v2
> > > - Fix commit messages.
> > > 
> > > v3
> > > - Define variables before code.(Ashutosh/Jose)
> > > 
> > > Cc: Ashutosh Dixit <ashutosh.dixit@intel.com>
> > > Cc: José Roberto de Souza <jose.souza@intel.com>
> > > Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
> > > Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
> > > Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> > > ---
> > >  drivers/gpu/drm/xe/xe_devcoredump.c | 13 +++++++++----
> > >  1 file changed, 9 insertions(+), 4 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/xe/xe_devcoredump.c b/drivers/gpu/drm/xe/xe_devcoredump.c
> > > index 7d3aa6bd3524..5b7be3b5b906 100644
> > > --- a/drivers/gpu/drm/xe/xe_devcoredump.c
> > > +++ b/drivers/gpu/drm/xe/xe_devcoredump.c
> > > @@ -77,17 +77,22 @@ static ssize_t xe_devcoredump_read(char *buffer, loff_t offset,
> > >  				   size_t count, void *data, size_t datalen)
> > >  {
> > >  	struct xe_devcoredump *coredump = data;
> > > -	struct xe_device *xe = coredump_to_xe(coredump);
> > > -	struct xe_devcoredump_snapshot *ss = &coredump->snapshot;
> > > +	struct xe_device *xe;
> > > +	struct xe_devcoredump_snapshot *ss;
> > >  	struct drm_printer p;
> > >  	struct drm_print_iterator iter;
> > >  	struct timespec64 ts;
> > >  	int i;
> > >  
> > > -	/* Our device is gone already... */
> > > -	if (!data || !coredump_to_xe(coredump))
> > > +	if (!coredump)
> > > +		return -ENODATA;
> > > +
> > > +	xe = coredump_to_xe(coredump);
> > > +	if (!xe)
> > >  		return -ENODEV;
> > 
> > this is real bug? because I can't see how this function is called with a null data.
> > 
> > if yes...
> > 
> > if coredump is not null this will never return -ENODEV.
> > 
> > would drop it and return ENODEV in the check above.
> 
> yeap, very good point
> 
> this patch could be simply a 2 line patch:
> 
> - if (!data || !coredump_to_xe(coredump))
> + if (!coredump_to_xe(coredump))
> 
> we are happy and the static analyzer is happy

coredump_to_xe() will always return something so not a good idea do this check.

> 
> > 
> > >  
> > > +	ss = &coredump->snapshot;
> > > +
> > >  	/* Ensure delayed work is captured before continuing */
> > >  	flush_work(&ss->work);
> > >  
> > 


  reply	other threads:[~2024-03-22 16:08 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-22  3:58 [PATCH v3] drm/xe/xe_devcoredump: Check NULL before dereferencing Himal Prasad Ghimiray
2024-03-22  5:39 ` ✓ CI.Patch_applied: success for drm/xe/xe_devcoredump: Check NULL before dereferencing (rev2) Patchwork
2024-03-22  5:39 ` ✓ CI.checkpatch: " Patchwork
2024-03-22  5:40 ` ✓ CI.KUnit: " Patchwork
2024-03-22  5:51 ` ✓ CI.Build: " Patchwork
2024-03-22  5:53 ` ✓ CI.Hooks: " Patchwork
2024-03-22  5:55 ` ✓ CI.checksparse: " Patchwork
2024-03-22  6:21 ` ✓ CI.BAT: " Patchwork
2024-03-22 13:57 ` [PATCH v3] drm/xe/xe_devcoredump: Check NULL before dereferencing Souza, Jose
2024-03-22 15:50   ` Rodrigo Vivi
2024-03-22 16:08     ` Souza, Jose [this message]
2024-03-22 16:53       ` Rodrigo Vivi

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=4cd61e1479695ed6d48bf4c8ec90d897d4b584ee.camel@intel.com \
    --to=jose.souza@intel.com \
    --cc=ashutosh.dixit@intel.com \
    --cc=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=rodrigo.vivi@intel.com \
    /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