drm/xe: Fix error paths of __xe_bo_create_locked
authorMaarten Lankhorst <maarten.lankhorst@linux.intel.com>
Tue, 25 Jul 2023 15:12:39 +0000 (17:12 +0200)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Thu, 21 Dec 2023 16:39:17 +0000 (11:39 -0500)
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 <ogabbay@kernel.org>
Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
Reviewed-by: Matthew Brost <matthew.brost@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/xe_bo.c

index cf0faaefd03d487b711494ecedaba097eb9aa8f1..a126130027669b0811004d80183312ed59675327 100644 (file)
@@ -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();
@@ -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 */