drm/vmwgfx: fix a memleak in vmw_gmrid_man_get_node
Subsystems (3)
PATCH v2 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")
Signed-off-by Zhipeng Lu <[email protected]>
---
Changelog:
v2: Adding {} to correct the if statement
--- drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c +4 -1
@@ -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);
Signature · 1 line
2.34.1
Zack Rusin
maintainerQuoted 21 lines · Zhipeng Lu
When
ida_alloc_maxfails, resources allocated before should be freed, including *res allocated by kmalloc andttm_resource_init.Fixes d3bcb4b02fe9 ("drm/vmwgfx: switch the TTM backends to self alloc")Signed-off-by Zhipeng Lu <[email protected]>---
Changelog:
v2: Adding {} to correct the if statement
--- drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c +0
-0@@ -64,8 +64,11 @@ static int vmw_gmrid_man_get_node(struct ttm_resource_manager *man,ttm_resource_init (bo, place, *res);
drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c static int vmw_gmrid_man_get_node(struct ttm_resource_manager *man, · line 73
Quoted 10 lines
drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c +4
-1id =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);
Thanks, I pushed it to drm-misc-next.
z