Skip to content

Commit

Permalink
drm/vmwgfx: fix a memleak in vmw_gmrid_man_get_node
Browse files Browse the repository at this point in the history
When ida_alloc_max fails, resources allocated before should be freed,
including *res allocated by kmalloc and ttm_resource_init.

Fixes: d3bcb4b ("drm/vmwgfx: switch the TTM backends to self alloc")
Signed-off-by: Zhipeng Lu <alexious@zju.edu.cn>
Signed-off-by: Zack Rusin <zack.rusin@broadcom.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20231204091416.3308430-1-alexious@zju.edu.cn
  • Loading branch information
AlexiousLu authored and zackr committed Jan 4, 2024
1 parent 834b1d7 commit 8970910
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ static int vmw_gmrid_man_get_node(struct ttm_resource_manager *man,
ttm_resource_init(bo, place, *res);

id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL);
if (id < 0)
if (id < 0) {
ttm_resource_fini(man, *res);
kfree(*res);
return id;
}

spin_lock(&gman->lock);

Expand Down

0 comments on commit 8970910

Please sign in to comment.