public inbox for amd-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@linaro.org>
To: Tvrtko Ursulin <tvrtko.ursulin@igalia.com>
Cc: "Srinivasan Shanmugam" <srinivasan.shanmugam@amd.com>,
	"Christian König" <christian.koenig@amd.com>,
	"Alex Deucher" <alexander.deucher@amd.com>,
	amd-gfx@lists.freedesktop.org
Subject: Re: [PATCH] drm/amdgpu: Add explicit NULL check for bo in amdgpu_vm_bo_update()
Date: Mon, 16 Mar 2026 13:07:34 +0300	[thread overview]
Message-ID: <abfWZnDMzYFWVjTr@stanley.mountain> (raw)
In-Reply-To: <2bdb769a-7814-480c-932c-c0e44c58c2bd@igalia.com>

On Thu, Mar 12, 2026 at 02:39:34PM +0000, 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?

I'm glad moving the function earlier fixed it.  :)  The function ends
up getting inlined.  This warning should only show up if you don't have
the cross function database built.

https://staticthinking.wordpress.com/2023/05/02/the-cross-function-db/

regards,
dan carpenter



      parent reply	other threads:[~2026-03-16 13:28 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
2026-03-16 10:07   ` Dan Carpenter [this message]

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=abfWZnDMzYFWVjTr@stanley.mountain \
    --to=dan.carpenter@linaro.org \
    --cc=alexander.deucher@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --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