drm/amdgpu: fix memory leak open when CWSR allocation fails
Subsystems (2)
PATCH 1/1 drm/amdgpu: fix memory leak open when CWSR allocation fails
amdgpu_driver_open_kms() returns CWSR allocation errors without releasing previously allocated resources. The DRM core does not call postclose after a failed open, so these resources leak.
Allocate CWSR before mapping seq64 and initializing the managers, and use the VM cleanup path on failure. Free CWSR if seq64 mapping fails. Keep ignoring -EOPNOTSUPP.
Fixes eed183d63b1f ("drm/amdgpu: Integrate CWSR with user queues")
Signed-off-by Jesse Zhang <[email protected]>
--- drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c +9 -7
@@ -1569,10 +1569,17 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv) goto error_vm; } - r =amdgpu_seq64_map (adev, &fpriv->vm, &fpriv->seq64_va); -if (r) + r =amdgpu_cwsr_alloc (adev, &fpriv->vm, &fpriv->cwsr_trap); +if (r == -EOPNOTSUPP ) + r =0 ; +else if (r) goto error_vm; + r =amdgpu_seq64_map (adev, &fpriv->vm, &fpriv->seq64_va); +if (r) { +amdgpu_cwsr_free (adev, &fpriv->vm, &fpriv->cwsr_trap); + goto error_vm; + }xa_init_flags (&fpriv->bo_list_handles,XA_FLAGS_ALLOC1 ); r =amdgpu_userq_mgr_init (&fpriv->userq_mgr, file_priv, adev);
@@ -1583,11 +1590,6 @@ int amdgpu_driver_open_kms(struct drm_device *dev, struct drm_file *file_priv)amdgpu_evf_mgr_init (&fpriv->evf_mgr); - r =amdgpu_cwsr_alloc (adev, &fpriv->vm, - &fpriv->cwsr_trap); -if (r == -EOPNOTSUPP ) - r =0 ; -amdgpu_ctx_mgr_init (&fpriv->ctx_mgr, adev); file_priv->driver_priv = fpriv;
Signature · 1 line
2.50.1