Skip to content

Commit d394669

Browse files
ShuichengLingregkh
authored andcommitted
drm/xe: Fix dma-buf attachment leak in xe_gem_prime_import()
commit 111ab67 upstream. When xe_dma_buf_init_obj() fails, the attachment from dma_buf_dynamic_attach() is not detached. Add dma_buf_detach() before returning the error. Note: we cannot use goto out_err here because xe_dma_buf_init_obj() already frees bo on failure, and out_err would double-free it. Fixes: dd08ebf ("drm/xe: Introduce a new DRM driver for Intel GPUs") Cc: stable@vger.kernel.org Assisted-by: Claude:claude-opus-4.6 Reviewed-by: Mattheq Brost <matthew.brost@intel.com> Link: https://patch.msgid.link/20260408175255.3402838-5-shuicheng.lin@intel.com Signed-off-by: Shuicheng Lin <shuicheng.lin@intel.com> (cherry picked from commit a828eb1) Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent d8fc5ac commit d394669

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

drivers/gpu/drm/xe/xe_dma_buf.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,15 @@ struct drm_gem_object *xe_gem_prime_import(struct drm_device *dev,
299299
goto out_err;
300300
}
301301

302-
/* Errors here will take care of freeing the bo. */
302+
/*
303+
* xe_dma_buf_init_obj() takes ownership of bo on both success
304+
* and failure, so we must not touch bo after this call.
305+
*/
303306
obj = xe_dma_buf_init_obj(dev, bo, dma_buf);
304-
if (IS_ERR(obj))
307+
if (IS_ERR(obj)) {
308+
dma_buf_detach(dma_buf, attach);
305309
return obj;
306-
307-
310+
}
308311
get_dma_buf(dma_buf);
309312
obj->import_attach = attach;
310313
return obj;

0 commit comments

Comments
 (0)