Commit

3c516a5646285442e1cd71dff2584b77eb4fc421

drm/amdgpu: fix GEM object leak on ENOMEM in userptr ioctl

When amdgpu_hmm_range_alloc() fails amdgpu_gem_userptr_ioctl() returns
-ENOMEM right away and skips the cleanup every other error path goes
through. The GEM object, the bo->parent reference on the VM root and the
MMU notifier registration are all left behind.

Use release_object here, not user_pages_done, range is still NULL at
this point.

Fixes: e095b55155ef ("drm/amdgpu: use user provided hmm_range buffer in amdgpu_ttm_tt_get_user_pages")
Signed-off-by: Perry Yuan <perry.yuan@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
(cherry picked from commit bbe739e407a542073ec1a7872b14843566b4919e)
Cc: stable@vger.kernel.org

Perry Yuan <perry.yuan@amd.com> · 2026-09-10 09:13 UTC · committed by Alex Deucher

Browse files
1 file changed, +4 −2
modified drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c
@@ -567,8 +567,10 @@ int amdgpu_gem_userptr_ioctl(struct drm_device *dev, void *data,
567 567
568 568 if (args->flags & AMDGPU_GEM_USERPTR_VALIDATE) {
569 569 range = amdgpu_hmm_range_alloc(NULL);
570 - if (unlikely(!range))
571 - return -ENOMEM;
570 + if (unlikely(!range)) {
571 + r = -ENOMEM;
572 + goto release_object;
573 + }
572 574 r = amdgpu_ttm_tt_get_user_pages(bo, range);
573 575 if (r) {
574 576 amdgpu_hmm_range_free(range);