Skip to content

Commit 6797906

Browse files
committed
drm/xe/hw_engine_group: Fix potential leak
If we fail to allocate a workqueue we will leak kzalloc'ed group object since it was designed to be kfree'ed in the drmm cleanup action, but we didn't have a chance to register this action yet. To avoid this leak allocate a group object using drmm_kzalloc() and start using predefined drmm action to release the workqueue. Signed-off-by: Michal Wajdeczko <[email protected]> Cc: Francois Dugast <[email protected]> Cc: Matthew Brost <[email protected]> Reviewed-by: Matthew Brost <[email protected]> Link: https://lore.kernel.org/r/[email protected]
1 parent a34ba68 commit 6797906

File tree

1 file changed

+5
-14
lines changed

1 file changed

+5
-14
lines changed

drivers/gpu/drm/xe/xe_hw_engine_group.c

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,6 @@
1212
#include "xe_hw_engine_group.h"
1313
#include "xe_vm.h"
1414

15-
static void
16-
hw_engine_group_free(struct drm_device *drm, void *arg)
17-
{
18-
struct xe_hw_engine_group *group = arg;
19-
20-
destroy_workqueue(group->resume_wq);
21-
kfree(group);
22-
}
23-
2415
static void
2516
hw_engine_group_resume_lr_jobs_func(struct work_struct *w)
2617
{
@@ -53,22 +44,22 @@ hw_engine_group_alloc(struct xe_device *xe)
5344
struct xe_hw_engine_group *group;
5445
int err;
5546

56-
group = kzalloc(sizeof(*group), GFP_KERNEL);
47+
group = drmm_kzalloc(&xe->drm, sizeof(*group), GFP_KERNEL);
5748
if (!group)
5849
return ERR_PTR(-ENOMEM);
5950

6051
group->resume_wq = alloc_workqueue("xe-resume-lr-jobs-wq", 0, 0);
6152
if (!group->resume_wq)
6253
return ERR_PTR(-ENOMEM);
6354

55+
err = drmm_add_action_or_reset(&xe->drm, __drmm_workqueue_release, group->resume_wq);
56+
if (err)
57+
return ERR_PTR(err);
58+
6459
init_rwsem(&group->mode_sem);
6560
INIT_WORK(&group->resume_work, hw_engine_group_resume_lr_jobs_func);
6661
INIT_LIST_HEAD(&group->exec_queue_list);
6762

68-
err = drmm_add_action_or_reset(&xe->drm, hw_engine_group_free, group);
69-
if (err)
70-
return ERR_PTR(err);
71-
7263
return group;
7364
}
7465

0 commit comments

Comments
 (0)