<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"> P {margin-top:0;margin-bottom:0;} </style>
</head>
<body dir="ltr">
<p style="font-family:Arial;font-size:10pt;color:#0000FF;margin:5pt;" align="Left">
[AMD Official Use Only]<br>
</p>
<br>
<div>
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<br>
</div>
<hr tabindex="-1" style="display:inline-block; width:98%">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" color="#000000" style="font-size:11pt"><b>From:</b> amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Ma Jun <Jun.Ma2@amd.com><br>
<b>Sent:</b> Monday, April 11, 2022 8:42 PM<br>
<b>To:</b> amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org><br>
<b>Cc:</b> Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; Zhang, Hawking <Hawking.Zhang@amd.com><br>
<b>Subject:</b> [PATCH] drm/amdgpu: Release memory when psp sw_init is failed</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText elementToProof">Release the memory (psp->cmd) when psp initialization is<br>
failed in psp_sw_init<br>
<br>
Signed-off-by: Ma Jun <Jun.Ma2@amd.com><br>
Change-Id: I2f88b5919142d55dd7d3820a7da94823286db235<br>
---<br>
drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c | 15 +++++++++------<br>
1 file changed, 9 insertions(+), 6 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c<br>
index a6acec1a6155..1227dc014c80 100644<br>
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c<br>
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_psp.c<br>
@@ -305,9 +305,10 @@ static int psp_sw_init(void *handle)<br>
ret = psp_init_sriov_microcode(psp);<br>
else<br>
ret = psp_init_microcode(psp);<br>
+<br>
if (ret) {<br>
DRM_ERROR("Failed to load psp firmware!\n");<br>
- return ret;<br>
+ goto failure;<br>
}<br>
<br>
adev->psp.xgmi_context.supports_extended_data =<br>
@@ -339,25 +340,27 @@ static int psp_sw_init(void *handle)<br>
ret = psp_memory_training_init(psp);<br>
if (ret) {<br>
DRM_ERROR("Failed to initialize memory training!\n");<br>
- return ret;<br>
+ goto failure;<br>
}<br>
<br>
ret = psp_mem_training(psp, PSP_MEM_TRAIN_COLD_BOOT);<br>
if (ret) {<br>
DRM_ERROR("Failed to process memory training!\n");<br>
- return ret;<br>
+ goto failure;<br>
}<br>
}<br>
<br>
if (adev->ip_versions[MP0_HWIP][0] == IP_VERSION(11, 0, 0) ||<br>
adev->ip_versions[MP0_HWIP][0] == IP_VERSION(11, 0, 7)) {<br>
ret= psp_sysfs_init(adev);<br>
- if (ret) {<br>
- return ret;<br>
- }<br>
+ if (ret)<br>
+ goto failure;<br>
}<br>
<br>
return 0;<br>
+failure:<br>
+ kfree(psp->cmd);<br>
+ return ret;</div>
<div class="PlainText elementToProof">[kevin]:</div>
<div class="PlainText elementToProof">
<ol>
<li><span>do you forget to set 'psp->cmd' to NULL?<br>
</span></li><li><span>according to my understanding, the buf will not be used in the function (in psp sw init stage), can you move this to end of function to mke patch logic is clearly.<br>
<span></span></span></li></ol>
</div>
<div class="PlainText elementToProof">Best Regards,</div>
<div class="PlainText elementToProof">Kevin<br>
}<br>
<br>
static int psp_sw_fini(void *handle)<br>
-- <br>
2.25.1<br>
<br>
</div>
</span></font></div>
</div>
</body>
</html>