Skip to content

Commit 76555b1

Browse files
ShuichengLinLucas De Marchi
authored andcommitted
drm/xe/guc: Fix resource leak in xe_guc_ct_init_noalloc()
xe_guc_ct_init_noalloc() allocates the CT workqueue and other helpers before it tries to initialize ct->lock. If drmm_mutex_init() fails we currently bail out without releasing those resources because the guc_ct_fini() hasn’t been registered yet. Since destroy_workqueue() in guc_ct_fini() may flush the workqueue, which in turn can take the ct lock, the initialization sequence is restructured to first initialize the ct->lock, then set up all CT state, and finally register guc_ct_fini(). v2: guc_ct_fini() does take ct lock. (Matt) v3: move primelockdep() together with drmm_mutex_init(). (Lucas) Fixes: dd08ebf ("drm/xe: Introduce a new DRM driver for Intel GPUs") Cc: Lucas De Marchi <[email protected]> Cc: Matthew Brost <[email protected]> Signed-off-by: Shuicheng Lin <[email protected]> Reviewed-by: Lucas De Marchi <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Lucas De Marchi <[email protected]> (cherry picked from commit 2e4ad5b) Signed-off-by: Lucas De Marchi <[email protected]>
1 parent ac3fd01 commit 76555b1

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

drivers/gpu/drm/xe/xe_guc_ct.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ int xe_guc_ct_init_noalloc(struct xe_guc_ct *ct)
226226

227227
xe_gt_assert(gt, !(guc_ct_size() % PAGE_SIZE));
228228

229+
err = drmm_mutex_init(&xe->drm, &ct->lock);
230+
if (err)
231+
return err;
232+
233+
primelockdep(ct);
234+
229235
ct->g2h_wq = alloc_ordered_workqueue("xe-g2h-wq", WQ_MEM_RECLAIM);
230236
if (!ct->g2h_wq)
231237
return -ENOMEM;
@@ -241,12 +247,6 @@ int xe_guc_ct_init_noalloc(struct xe_guc_ct *ct)
241247
init_waitqueue_head(&ct->wq);
242248
init_waitqueue_head(&ct->g2h_fence_wq);
243249

244-
err = drmm_mutex_init(&xe->drm, &ct->lock);
245-
if (err)
246-
return err;
247-
248-
primelockdep(ct);
249-
250250
err = drmm_add_action_or_reset(&xe->drm, guc_ct_fini, ct);
251251
if (err)
252252
return err;

0 commit comments

Comments
 (0)