Intel-XE Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "Ghimiray, Himal Prasad" <himal.prasad.ghimiray@intel.com>
To: Rodrigo Vivi <rodrigo.vivi@intel.com>,
	Michal Wajdeczko <michal.wajdeczko@intel.com>
Cc: <intel-xe@lists.freedesktop.org>
Subject: Re: [PATCH 2/3] drm/xe/vf: Remove lmtt->ops null check in xe_lmtt_estimate_pt_size
Date: Fri, 8 Mar 2024 21:52:51 +0530	[thread overview]
Message-ID: <ad13f0ba-4dbb-4f37-8a1d-879b2cb111cd@intel.com> (raw)
In-Reply-To: <ZesmInDmDsLY1uPh@intel.com>


On 08-03-2024 20:22, Rodrigo Vivi wrote:
> On Fri, Mar 08, 2024 at 10:06:50AM +0530, Himal Prasad Ghimiray wrote:
>> In xe_lmtt_estimate_pt_size: Pointer is checked against null but then
>> dereferenced anyway.
> And what's the problem?
>
> In the line below it access beyond this pointer, so it is a fair
> case.

The problem is even if it is NULL it will be  try to derefrence it. 
Which might lead to segmentation fault.

>
>> Since xe_lmtt_init ensures lmtt->ops is populated
>> remove the check.
> With this in mind we could simply remove all the asserts in the code.
>
> I believe that if someone introduced it here it is likely because
> during some development or refactor this ended up being a problem
> and want some earlier kind of warning with backtrace information.
>
>> Reported by static analyzer.
> Perhaps then replace with an
> if (!lmtt->ops) {
>      drm_WARN(...);
>      return;
> }

I am also of the opinion that this is the correct check to have instead 
of just warning

about lmtt->ops being NULL and continue to dereference it. Need clarity 
on what should we return in

case of lmtt->ops being NULL since expected return type is u64.

>
> and/or mark the tool as a false positive?!
>
>> Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
>> Signed-off-by: Himal Prasad Ghimiray <himal.prasad.ghimiray@intel.com>
>> ---
>>   drivers/gpu/drm/xe/xe_lmtt.c | 1 -
>>   1 file changed, 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/xe/xe_lmtt.c b/drivers/gpu/drm/xe/xe_lmtt.c
>> index 0d7c5514e092..d6d75414bb99 100644
>> --- a/drivers/gpu/drm/xe/xe_lmtt.c
>> +++ b/drivers/gpu/drm/xe/xe_lmtt.c
>> @@ -487,7 +487,6 @@ u64 xe_lmtt_estimate_pt_size(struct xe_lmtt *lmtt, u64 size)
>>   
>>   	lmtt_assert(lmtt, IS_SRIOV_PF(lmtt_to_xe(lmtt)));
>>   	lmtt_assert(lmtt, IS_DGFX(lmtt_to_xe(lmtt)));
>> -	lmtt_assert(lmtt, lmtt->ops);
>>   
>>   	pt_size = PAGE_ALIGN(lmtt->ops->lmtt_pte_size(level) *
>>   			     lmtt->ops->lmtt_pte_num(level));
>> -- 
>> 2.25.1
>>

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

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-08  4:36 [PATCH 0/3] Minor fixes for errors reported by static analyzer Himal Prasad Ghimiray
2024-03-08  4:33 ` ✓ CI.Patch_applied: success for " Patchwork
2024-03-08  4:33 ` ✓ CI.checkpatch: " Patchwork
2024-03-08  4:35 ` ✓ CI.KUnit: " Patchwork
2024-03-08  4:36 ` [PATCH 1/3] drm/xe: Return if kobj creation is failed Himal Prasad Ghimiray
2024-03-08  5:18   ` Upadhyay, Tejas
2024-03-08  4:36 ` [PATCH 2/3] drm/xe/vf: Remove lmtt->ops null check in xe_lmtt_estimate_pt_size Himal Prasad Ghimiray
2024-03-08 14:52   ` Rodrigo Vivi
2024-03-08 16:22     ` Ghimiray, Himal Prasad [this message]
2024-03-11 13:13       ` Michal Wajdeczko
2024-03-11 14:21         ` Lucas De Marchi
2024-03-08  4:36 ` [PATCH 3/3] drm/xe/xe_exec : In xe_exec_ioctl remove deadcode Himal Prasad Ghimiray
2024-03-08  5:27   ` Upadhyay, Tejas
2024-03-08  4:46 ` ✓ CI.Build: success for Minor fixes for errors reported by static analyzer Patchwork
2024-03-08  4:46 ` ✗ CI.Hooks: failure " Patchwork
2024-03-08  4:48 ` ✓ CI.checksparse: success " Patchwork
2024-03-08  5:38 ` ✓ CI.BAT: " Patchwork

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=ad13f0ba-4dbb-4f37-8a1d-879b2cb111cd@intel.com \
    --to=himal.prasad.ghimiray@intel.com \
    --cc=intel-xe@lists.freedesktop.org \
    --cc=michal.wajdeczko@intel.com \
    --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