[PATCH 1/2] drm/amdgpu: protect potential NULL pointer dereferencing

David (Ming Qiang) Wu David.Wu3 at amd.com
Tue Aug 26 19:38:20 UTC 2025


to_amdgpu_userq_fence() could return NULL which should be
protected.

Signed-off-by: David (Ming Qiang) Wu <David.Wu3 at amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
index a86616c6deeff..01d30544c30d1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c
@@ -297,15 +297,18 @@ static const char *amdgpu_userq_fence_get_timeline_name(struct dma_fence *f)
 {
 	struct amdgpu_userq_fence *fence = to_amdgpu_userq_fence(f);
 
-	return fence->fence_drv->timeline_name;
+	return fence ? fence->fence_drv->timeline_name : "";
 }
 
 static bool amdgpu_userq_fence_signaled(struct dma_fence *f)
 {
 	struct amdgpu_userq_fence *fence = to_amdgpu_userq_fence(f);
-	struct amdgpu_userq_fence_driver *fence_drv = fence->fence_drv;
+	struct amdgpu_userq_fence_driver *fence_drv;
 	u64 rptr, wptr;
 
+	if (!fence)
+		return false;
+	fence_drv = fence->fence_drv;
 	rptr = amdgpu_userq_fence_read(fence_drv);
 	wptr = fence->base.seqno;
 
@@ -319,8 +322,11 @@ static void amdgpu_userq_fence_free(struct rcu_head *rcu)
 {
 	struct dma_fence *fence = container_of(rcu, struct dma_fence, rcu);
 	struct amdgpu_userq_fence *userq_fence = to_amdgpu_userq_fence(fence);
-	struct amdgpu_userq_fence_driver *fence_drv = userq_fence->fence_drv;
+	struct amdgpu_userq_fence_driver *fence_drv;
 
+	if (!userq_fence)
+		return;
+	fence_drv = userq_fence->fence_drv;
 	/* Release the fence driver reference */
 	amdgpu_userq_fence_driver_put(fence_drv);
 
-- 
2.43.0



More information about the amd-gfx mailing list