drm/xe: Fail xe_device_create() if wq allocation fails
authorGustavo Sousa <gustavo.sousa@intel.com>
Thu, 18 May 2023 21:56:51 +0000 (18:56 -0300)
committerRodrigo Vivi <rodrigo.vivi@intel.com>
Tue, 19 Dec 2023 23:34:00 +0000 (18:34 -0500)
Let's make sure we give the driver a valid workqueue.

While at it, also make sure to call destroy_workqueue() only if the
workqueue is a valid one. That is necessary because xe_device_destroy()
is indirectly called as part of the cleanup process of a failed
xe_device_create().

Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
Link: https://lore.kernel.org/r/20230518215651.502159-3-gustavo.sousa@intel.com
Signed-off-by: Gustavo Sousa <gustavo.sousa@intel.com>
Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
drivers/gpu/drm/xe/xe_device.c

index 42456d0448278c251c94f548fc5adcf5e5613236..2c65eb84e6e98d57160fadc5366fd1f9044c1481 100644 (file)
@@ -10,6 +10,7 @@
 #include <drm/drm_gem_ttm_helper.h>
 #include <drm/drm_ioctl.h>
 #include <drm/drm_managed.h>
+#include <drm/drm_print.h>
 #include <drm/xe_drm.h>
 
 #include "regs/xe_regs.h"
@@ -157,7 +158,9 @@ static void xe_device_destroy(struct drm_device *dev, void *dummy)
 {
        struct xe_device *xe = to_xe_device(dev);
 
-       destroy_workqueue(xe->ordered_wq);
+       if (xe->ordered_wq)
+               destroy_workqueue(xe->ordered_wq);
+
        ttm_device_fini(&xe->ttm);
 }
 
@@ -205,6 +208,11 @@ struct xe_device *xe_device_create(struct pci_dev *pdev,
        INIT_LIST_HEAD(&xe->pinned.evicted);
 
        xe->ordered_wq = alloc_ordered_workqueue("xe-ordered-wq", 0);
+       if (!xe->ordered_wq) {
+               drm_err(&xe->drm, "Failed to allocate xe-ordered-wq\n");
+               err = -ENOMEM;
+               goto err_put;
+       }
 
        drmm_mutex_init(&xe->drm, &xe->sb_lock);
        xe->enabled_irq_mask = ~0;