Commit fb4f4f42 authored by Alex Deucher's avatar Alex Deucher

drm/amdgpu/psp: fix memory leak in terminate functions

Make sure we free the memory even if the unload fails.
Reviewed-by: default avatarHawking Zhang <Hawking.Zhang@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent f03d97b0
...@@ -752,14 +752,12 @@ static int psp_tmr_terminate(struct psp_context *psp) ...@@ -752,14 +752,12 @@ static int psp_tmr_terminate(struct psp_context *psp)
void **pptr; void **pptr;
ret = psp_tmr_unload(psp); ret = psp_tmr_unload(psp);
if (ret)
return ret;
/* free TMR memory buffer */ /* free TMR memory buffer */
pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL; pptr = amdgpu_sriov_vf(psp->adev) ? &tmr_buf : NULL;
amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, pptr); amdgpu_bo_free_kernel(&psp->tmr_bo, &psp->tmr_mc_addr, pptr);
return 0; return ret;
} }
int psp_get_fw_attestation_records_addr(struct psp_context *psp, int psp_get_fw_attestation_records_addr(struct psp_context *psp,
...@@ -1101,15 +1099,13 @@ int psp_xgmi_terminate(struct psp_context *psp) ...@@ -1101,15 +1099,13 @@ int psp_xgmi_terminate(struct psp_context *psp)
return 0; return 0;
ret = psp_ta_unload(psp, &psp->xgmi_context.context); ret = psp_ta_unload(psp, &psp->xgmi_context.context);
if (ret)
return ret;
psp->xgmi_context.context.initialized = false; psp->xgmi_context.context.initialized = false;
/* free xgmi shared memory */ /* free xgmi shared memory */
psp_ta_free_shared_buf(&psp->xgmi_context.context.mem_context); psp_ta_free_shared_buf(&psp->xgmi_context.context.mem_context);
return 0; return ret;
} }
int psp_xgmi_initialize(struct psp_context *psp, bool set_extended_data, bool load_ta) int psp_xgmi_initialize(struct psp_context *psp, bool set_extended_data, bool load_ta)
...@@ -1466,15 +1462,13 @@ int psp_ras_terminate(struct psp_context *psp) ...@@ -1466,15 +1462,13 @@ int psp_ras_terminate(struct psp_context *psp)
return 0; return 0;
ret = psp_ta_unload(psp, &psp->ras_context.context); ret = psp_ta_unload(psp, &psp->ras_context.context);
if (ret)
return ret;
psp->ras_context.context.initialized = false; psp->ras_context.context.initialized = false;
/* free ras shared memory */ /* free ras shared memory */
psp_ta_free_shared_buf(&psp->ras_context.context.mem_context); psp_ta_free_shared_buf(&psp->ras_context.context.mem_context);
return 0; return ret;
} }
static int psp_ras_initialize(struct psp_context *psp) static int psp_ras_initialize(struct psp_context *psp)
...@@ -1657,15 +1651,15 @@ static int psp_hdcp_terminate(struct psp_context *psp) ...@@ -1657,15 +1651,15 @@ static int psp_hdcp_terminate(struct psp_context *psp)
return 0; return 0;
if (!psp->hdcp_context.context.initialized) { if (!psp->hdcp_context.context.initialized) {
if (psp->hdcp_context.context.mem_context.shared_buf) if (psp->hdcp_context.context.mem_context.shared_buf) {
ret = 0;
goto out; goto out;
else } else {
return 0; return 0;
}
} }
ret = psp_ta_unload(psp, &psp->hdcp_context.context); ret = psp_ta_unload(psp, &psp->hdcp_context.context);
if (ret)
return ret;
psp->hdcp_context.context.initialized = false; psp->hdcp_context.context.initialized = false;
...@@ -1673,7 +1667,7 @@ static int psp_hdcp_terminate(struct psp_context *psp) ...@@ -1673,7 +1667,7 @@ static int psp_hdcp_terminate(struct psp_context *psp)
/* free hdcp shared memory */ /* free hdcp shared memory */
psp_ta_free_shared_buf(&psp->hdcp_context.context.mem_context); psp_ta_free_shared_buf(&psp->hdcp_context.context.mem_context);
return 0; return ret;
} }
// HDCP end // HDCP end
...@@ -1734,15 +1728,15 @@ static int psp_dtm_terminate(struct psp_context *psp) ...@@ -1734,15 +1728,15 @@ static int psp_dtm_terminate(struct psp_context *psp)
return 0; return 0;
if (!psp->dtm_context.context.initialized) { if (!psp->dtm_context.context.initialized) {
if (psp->dtm_context.context.mem_context.shared_buf) if (psp->dtm_context.context.mem_context.shared_buf) {
ret = 0;
goto out; goto out;
else } else {
return 0; return 0;
}
} }
ret = psp_ta_unload(psp, &psp->dtm_context.context); ret = psp_ta_unload(psp, &psp->dtm_context.context);
if (ret)
return ret;
psp->dtm_context.context.initialized = false; psp->dtm_context.context.initialized = false;
...@@ -1750,7 +1744,7 @@ static int psp_dtm_terminate(struct psp_context *psp) ...@@ -1750,7 +1744,7 @@ static int psp_dtm_terminate(struct psp_context *psp)
/* free dtm shared memory */ /* free dtm shared memory */
psp_ta_free_shared_buf(&psp->dtm_context.context.mem_context); psp_ta_free_shared_buf(&psp->dtm_context.context.mem_context);
return 0; return ret;
} }
// DTM end // DTM end
...@@ -1922,8 +1916,6 @@ static int psp_securedisplay_terminate(struct psp_context *psp) ...@@ -1922,8 +1916,6 @@ static int psp_securedisplay_terminate(struct psp_context *psp)
return 0; return 0;
ret = psp_ta_unload(psp, &psp->securedisplay_context.context); ret = psp_ta_unload(psp, &psp->securedisplay_context.context);
if (ret)
return ret;
psp->securedisplay_context.context.initialized = false; psp->securedisplay_context.context.initialized = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment