[PATCH] drm/vmwgfx: fix a potential memory leak in vmw_ttm_bind()

Haoxiang Li posted 1 patch 2 weeks ago
drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
[PATCH] drm/vmwgfx: fix a potential memory leak in vmw_ttm_bind()
Posted by Haoxiang Li 2 weeks ago
In vmw_ttm_bind(), if vmw_mob_create() fails, call
vmw_ttm_unmap_dma() to release the memory allocated
by vmw_ttm_map_dma().

Signed-off-by: Haoxiang Li <lihaoxiang@isrc.iscas.ac.cn>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
index 5553892d7c3e..6f6a73a7c857 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
@@ -299,8 +299,10 @@ static int vmw_ttm_bind(struct ttm_device *bdev,
 		if (unlikely(vmw_be->mob == NULL)) {
 			vmw_be->mob =
 				vmw_mob_create(ttm->num_pages);
-			if (unlikely(vmw_be->mob == NULL))
+			if (unlikely(vmw_be->mob == NULL)) {
+				vmw_ttm_unmap_dma(vmw_be);
 				return -ENOMEM;
+			}
 		}
 
 		ret = vmw_mob_bind(vmw_be->dev_priv, vmw_be->mob,
-- 
2.25.1
Re: [PATCH] drm/vmwgfx: fix a potential memory leak in vmw_ttm_bind()
Posted by Markus Elfring 1 week, 6 days ago
> In vmw_ttm_bind(), if vmw_mob_create() fails, call
> vmw_ttm_unmap_dma() to release the memory allocated
> by vmw_ttm_map_dma().

* Would an other word wrapping be nicer?
  https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/Documentation/process/submitting-patches.rst?h=v6.19-rc7#n659

* How do you think about to add any tags (like “Fixes” and “Cc”) accordingly?


Regards,
Markus