Skip to content

Commit 111ab67

Browse files
ShuichengLinrodrigovivi
authored andcommitted
drm/xe: Fix dma-buf attachment leak in xe_gem_prime_import()
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>
1 parent 93a528f commit 111ab67

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
@@ -378,12 +378,15 @@ struct drm_gem_object *xe_gem_prime_import(struct drm_device *dev,
378378
goto out_err;
379379
}
380380

381-
/* Errors here will take care of freeing the bo. */
381+
/*
382+
* xe_dma_buf_init_obj() takes ownership of bo on both success
383+
* and failure, so we must not touch bo after this call.
384+
*/
382385
obj = xe_dma_buf_init_obj(dev, bo, dma_buf);
383-
if (IS_ERR(obj))
386+
if (IS_ERR(obj)) {
387+
dma_buf_detach(dma_buf, attach);
384388
return obj;
385-
386-
389+
}
387390
get_dma_buf(dma_buf);
388391
obj->import_attach = attach;
389392
return obj;

0 commit comments

Comments
 (0)