The memory allocated by vmw_cmdbuf_res_man_create() is not
released on error path, causing a potential leak. Furthermore,
the failed allocations leave error pointers, which the cleanup
functions may treat as valid pointers.

Call vmw_cmdbuf_res_man_destroy() on error paths and clear the
error pointers.

Fixes: d80efd5cb3de ("drm/vmwgfx: Initial DX support")
Signed-off-by: Haoxiang Li <[email protected]>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_context.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c 
b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
index bd96f4d5e090..525bba8bcc5d 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_context.c
@@ -207,7 +207,8 @@ static int vmw_gb_context_init(struct vmw_private *dev_priv,
        uctx->cbs = vmw_binding_state_alloc(dev_priv);
        if (IS_ERR(uctx->cbs)) {
                ret = PTR_ERR(uctx->cbs);
-               goto out_err;
+               uctx->cbs = NULL;
+               goto out_man;
        }
 
        spin_lock_init(&uctx->cotable_lock);
@@ -220,6 +221,7 @@ static int vmw_gb_context_init(struct vmw_private *dev_priv,
                                                              &uctx->res, i);
                        if (IS_ERR(uctx->cotables[i])) {
                                ret = PTR_ERR(uctx->cotables[i]);
+                               uctx->cotables[i] = NULL;
                                goto out_cotables;
                        }
                }
@@ -230,6 +232,8 @@ static int vmw_gb_context_init(struct vmw_private *dev_priv,
 
 out_cotables:
        vmw_context_cotables_unref(dev_priv, uctx);
+out_man:
+       vmw_cmdbuf_res_man_destroy(uctx->man);
 out_err:
        if (res_free)
                res_free(res);
-- 
2.25.1

Reply via email to