Skip to contentSkip to conversation

drm/amdgpu: update userqueue BOs and PDs

bug report Dan Carpenter 1 participant 1 message Apr 10, 2025

lore
Share & tools
lore
#0 lore raw

Hello Arvind Yadav,

Commit 70773bef4e09 ("drm/amdgpu: update userqueue BOs and PDs") from Sep 25, 2024 (linux-next), leads to the following Smatch static checker warning:

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c:139 amdgpu_gem_update_bo_mapping()
error: we previously assumed 'bo_va' could be null (see line 124)

drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
115 static void
116 amdgpu_gem_update_bo_mapping(struct drm_file *filp,
117 struct amdgpu_bo_va *bo_va,
118 uint32_t operation,
119 uint64_t point,
120 struct dma_fence *fence,
121 struct drm_syncobj *syncobj,
122 struct dma_fence_chain *chain)
123 {
124 struct amdgpu_bo *bo = bo_va ? bo_va->base.bo : NULL;
^^^^^^^^^^
If bo_va is NULL then bo is also NULL

    125         struct amdgpu_fpriv *fpriv = filp->driver_priv;
    126         struct amdgpu_vm *vm = &fpriv->vm;
    127         struct dma_fence *last_update;
    128 
    129         if (!syncobj)
    130                 return;
    131 
    132         /* Find the last update fence */
    133         switch (operation) {
    134         case AMDGPU_VA_OP_MAP:
    135         case AMDGPU_VA_OP_REPLACE:
    136                 if (bo && (bo->tbo.base.resv == vm->root.bo->tbo.base.resv))
                            ^^

    137                         last_update = vm->last_update;
    138                 else
--> 139                         last_update = bo_va->last_pt_update;
                                              ^^^^^

This pointer is dereferenced without being checked.

    140                 break;
    141         case AMDGPU_VA_OP_UNMAP:
    142         case AMDGPU_VA_OP_CLEAR:
    143                 last_update = fence;
    144                 break;
    145         default:
    146                 return;
    147         }
    148 
    149         /* Add fence to timeline */
    150         if (!point)
    151                 drm_syncobj_replace_fence(syncobj, last_update);
    152         else
    153                 drm_syncobj_add_point(syncobj, chain, last_update, point);
    154 }

regards,
dan carpenter