Skip to content

Commit

Permalink
drm/xe: Fix error paths of __xe_bo_create_locked
Browse files Browse the repository at this point in the history
ttm_bo_init_reserved() calls the destroy() callback if it fails.

Because of this, __xe_bo_create_locked is required to be responsible
for freeing the bo even when it's passed in as argument.

Additionally, if the placement check fails, the bo was kept alive.
Fix it too.

Reported-by: Oded Gabbay <[email protected]>
Signed-off-by: Maarten Lankhorst <[email protected]>
Reviewed-by: Matthew Brost <[email protected]>
Signed-off-by: Rodrigo Vivi <[email protected]>
  • Loading branch information
mlankhorst authored and rodrigovivi committed Dec 21, 2023
1 parent f82686e commit 2a368a0
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions drivers/gpu/drm/xe/xe_bo.c
Original file line number Diff line number Diff line change
Expand Up @@ -1200,8 +1200,10 @@ struct xe_bo *__xe_bo_create_locked(struct xe_device *xe, struct xe_bo *bo,
/* Only kernel objects should set GT */
XE_WARN_ON(tile && type != ttm_bo_type_kernel);

if (XE_WARN_ON(!size))
if (XE_WARN_ON(!size)) {
xe_bo_free(bo);
return ERR_PTR(-EINVAL);
}

if (!bo) {
bo = xe_bo_alloc();
Expand Down Expand Up @@ -1239,8 +1241,10 @@ struct xe_bo *__xe_bo_create_locked(struct xe_device *xe, struct xe_bo *bo,

if (!(flags & XE_BO_FIXED_PLACEMENT_BIT)) {
err = __xe_bo_placement_for_flags(xe, bo, bo->flags);
if (WARN_ON(err))
if (WARN_ON(err)) {
xe_ttm_bo_destroy(&bo->ttm);
return ERR_PTR(err);
}
}

/* Defer populating type_sg bos */
Expand Down

0 comments on commit 2a368a0

Please sign in to comment.