[Intel-xe] [PATCH] drm/xe: Fail xe_device_create() if wq allocation fails

Gustavo Sousa gustavo.sousa at intel.com
Thu May 18 20:45:04 UTC 2023


Quoting Gustavo Sousa (2023-05-18 17:15:00-03:00)
>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().

Hm... Just realized that xe_device_destroy() is not called in this case, because
we goto err_put, which skips the call to drmm_add_action_or_reset().

And I think I have found an issue with this: shouldn't
drmm_add_action_or_reset() (or rather drmm_add_action() in this case) be the
first thing we do after calling devm_drm_dev_alloc()? Otherwise, if anything
fails in and we goto err_put, no cleanup is actually done.

--
Gustavo Sousa

>
>Signed-off-by: Gustavo Sousa <gustavo.sousa at intel.com>
>---
> drivers/gpu/drm/xe/xe_device.c | 10 +++++++++-
> 1 file changed, 9 insertions(+), 1 deletion(-)
>
>diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c
>index f7f6a6a97757..775a2940c916 100644
>--- a/drivers/gpu/drm/xe/xe_device.c
>+++ b/drivers/gpu/drm/xe/xe_device.c
>@@ -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"
>@@ -161,7 +162,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);
> }
> 
>@@ -207,6 +210,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;
>+        }
> 
>         err = xe_display_create(xe);
>         if (WARN_ON(err))
>-- 
>2.40.1
>


More information about the Intel-xe mailing list