Skip to contentSkip to conversation

drm/vmwgfx: fix a memleak in vmw_gmrid_man_get_node

PATCH Superseded Zhipeng Lu 1 participant 1 message Dec 4, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Zhipeng Lu

author
#0 lore raw

PATCH 1/1 drm/vmwgfx: fix a memleak in vmw_gmrid_man_get_node

When ida_alloc_max fails, resources allocated before should be freed, including *res allocated by kmalloc and ttm_resource_init.

Fixes d3bcb4b02fe9 ("drm/vmwgfx: switch the TTM backends to self alloc")
---
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c +2 -0
index ceb4d3d3b965..220561b73493 100644
@@ -65,6 +65,8 @@ static int vmw_gmrid_man_get_node(struct ttm_resource_manager *man,
 
 	id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL);
 	if (id < 0)
+		ttm_resource_fini(man, *res);
+		kfree(*res);
 		return id;
 
 	spin_lock(&gman->lock);
Signature · 1 line
2.34.1