public inbox for amd-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: "Christian König" <christian.koenig@amd.com>
To: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>,
	Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>,
	Alex Deucher <alexander.deucher@amd.com>
Cc: amd-gfx@lists.freedesktop.org, Dan Carpenter <dan.carpenter@linaro.org>
Subject: Re: [PATCH] drm/amdgpu: Add explicit NULL check for bo in amdgpu_vm_bo_update()
Date: Thu, 12 Mar 2026 18:21:50 +0100	[thread overview]
Message-ID: <765c97fa-b910-45d1-862e-44fb69235c17@amd.com> (raw)
In-Reply-To: <2bdb769a-7814-480c-932c-c0e44c58c2bd@igalia.com>

On 3/12/26 15:39, Tvrtko Ursulin wrote:
> 
> On 12/03/2026 14:13, Srinivasan Shanmugam wrote:
>> amdgpu_vm_bo_update() allows bo_va->base.bo to be NULL in some paths,
>> such as PRT-only updates.
>>
>> Although amdgpu_vm_is_bo_always_valid() already returns false for a NULL
>> BO, Smatch still warns that bo may be NULL before it is dereferenced
>> later in the block.
>>
>> Add an explicit `bo &&` check before calling
>> amdgpu_vm_is_bo_always_valid() to make the non-NULL condition clear and
>> fixes the below smatch error
>>
>> drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c:1353 amdgpu_vm_bo_update() error: we previously assumed 'bo' could be null (see line 1292)
>>
>> Fixes: 26e20235ce00 ("drm/amdgpu: Add amdgpu_bo_is_vm_bo helper")
>> Cc: Dan Carpenter <dan.carpenter@linaro.org>
>> Cc: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
>> Cc: Christian König <christian.koenig@amd.com>
>> Cc: Alex Deucher <alexander.deucher@amd.com>
>> Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
>> ---
>>   drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>> index b89013a6aa0b..0d26346178d4 100644
>> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vm.c
>> @@ -1349,7 +1349,7 @@ int amdgpu_vm_bo_update(struct amdgpu_device *adev, struct amdgpu_bo_va *bo_va,
>>        * the evicted list so that it gets validated again on the
>>        * next command submission.
>>        */
>> -    if (amdgpu_vm_is_bo_always_valid(vm, bo)) {
>> +    if (bo && amdgpu_vm_is_bo_always_valid(vm, bo)) {
> 
> That would be unfortunate:
> 
> bool amdgpu_vm_is_bo_always_valid(struct amdgpu_vm *vm, struct amdgpu_bo *bo)
> {
>     return bo && bo->tbo.base.resv == vm->root.bo->tbo.base.resv;
> }
> 
> Maybe Dan can make smatch smarter? :) Because I don't think papering randomly at a single call site is great. It is even in the same compilation unit. Hmm does the order matter to smatch? Should we maybe move amdgpu_vm_is_bo_always_valid() to be earlier in the file?

Yeah that patch doesn't make much sense.

We explicitly added the amdgpu_vm_is_bo_always_valid() function to avoid such NULL checks.

Regards,
Christian.

> 
> Regards,
> 
> Tvrtko
> 
>>           if (bo->tbo.resource &&
>>               !(bo->preferred_domains &
>>                 amdgpu_mem_type_to_domain(bo->tbo.resource->mem_type)))
> 


  reply	other threads:[~2026-03-12 17:22 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-12 14:13 [PATCH] drm/amdgpu: Add explicit NULL check for bo in amdgpu_vm_bo_update() Srinivasan Shanmugam
2026-03-12 14:39 ` Tvrtko Ursulin
2026-03-12 17:21   ` Christian König [this message]
2026-03-16 10:07   ` Dan Carpenter

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=765c97fa-b910-45d1-862e-44fb69235c17@amd.com \
    --to=christian.koenig@amd.com \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dan.carpenter@linaro.org \
    --cc=srinivasan.shanmugam@amd.com \
    --cc=tvrtko.ursulin@igalia.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