[PATCH] drm/radeon: check radeon_ttm_tt_pin_userptr() return value in bind
From: Seongjun Hong
Date: Thu Aug 27 2026 - 12:02:19 EST
radeon_ttm_backend_bind() calls radeon_ttm_tt_pin_userptr() without
checking its return value. If pinning fails partway through (e.g.
sg_alloc_table_from_pages()/dma_map_sgtable() failure, or an invalid
userptr range), ttm->pages[] and gtt->ttm.dma_address[] are left
incompletely populated - containing stale entries left over from a
previous bind cycle, or uninitialized memory on the very first one.
radeon_ttm_backend_bind() proceeds anyway and calls
radeon_gart_bind(rdev, ..., ttm->pages, gtt->ttm.dma_address, flags),
which writes those stale/uninitialized DMA addresses straight into
the GPU's GART page table entries. This is not a bounds violation
(the table indices themselves stay in range), but it programs the
GPU to have DMA read/write access to whatever physical memory those
stale addresses happen to resolve to, which may since have been
freed and reused for something else.
Propagate the error and bail out before calling radeon_gart_bind().
Fixes: f72a113a71ab ("drm/radeon: add userptr support v8")
Reported-by: Sashiko AI Review <sashiko-bot@xxxxxxxxxx>
Signed-off-by: Seongjun Hong <hsj0512@xxxxxxxxx>
---
drivers/gpu/drm/radeon/radeon_ttm.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index cbc0339cf127..58bd1e73587a 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -431,7 +431,9 @@ static int radeon_ttm_backend_bind(struct ttm_device *bdev,
return 0;
if (gtt->userptr) {
- radeon_ttm_tt_pin_userptr(bdev, ttm);
+ r = radeon_ttm_tt_pin_userptr(bdev, ttm);
+ if (r)
+ return r;
flags &= ~RADEON_GART_PAGE_WRITE;
}
--
2.43.0