<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">
<div style="font-family: Calibri, Arial, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif">
thanks correct it.</div>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif">
<br>
</div>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif">
Revie<span style="margin: 0px">wed-by: Kevin Wang <kevin1.wang@amd.com></span></div>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif">
<br>
</div>
<div style="margin: 0px; font-size: 12pt; font-family: Calibri, Arial, Helvetica, sans-serif">
Best Regards,<br>
Kevin</div>
</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> Dan Carpenter <dan.carpenter@oracle.com><br>
<b>Sent:</b> Monday, October 7, 2019 5:02 PM<br>
<b>To:</b> Rex Zhu <rex.zhu@amd.com>; Wang, Kevin(Yang) <Kevin1.Wang@amd.com><br>
<b>Cc:</b> Quan, Evan <Evan.Quan@amd.com>; Deucher, Alexander <Alexander.Deucher@amd.com>; Koenig, Christian <Christian.Koenig@amd.com>; Zhou, David(ChunMing) <David1.Zhou@amd.com>; David Airlie <airlied@linux.ie>; Daniel Vetter <daniel@ffwll.ch>; amd-gfx@lists.freedesktop.org
 <amd-gfx@lists.freedesktop.org>; dri-devel@lists.freedesktop.org <dri-devel@lists.freedesktop.org>; kernel-janitors@vger.kernel.org <kernel-janitors@vger.kernel.org><br>
<b>Subject:</b> [PATCH] drm/amd/powerplay: Fix error handling in smu_init_fb_allocations()</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt">
<div class="PlainText">The error handling is off by one.  We should not free the first<br>
"tables[i].bo" without decrementing "i" because that might result in a<br>
double free.  The second problem is that when an error occurs, then the<br>
zeroth element "tables[0].bo" isn't freed.<br>
<br>
I had make "i" signed int for the error handling to work, so I just<br>
updated "ret" as well as a clean up.<br>
<br>
Fixes: f96357a991b9 ("drm/amd/powerplay: implement smu_init(fini)_fb_allocations function")<br>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com><br>
---<br>
 drivers/gpu/drm/amd/powerplay/amdgpu_smu.c | 5 ++---<br>
 1 file changed, 2 insertions(+), 3 deletions(-)<br>
<br>
diff --git a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c<br>
index f1fbbc8b77ee..c9266ea70331 100644<br>
--- a/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c<br>
+++ b/drivers/gpu/drm/amd/powerplay/amdgpu_smu.c<br>
@@ -896,8 +896,7 @@ static int smu_init_fb_allocations(struct smu_context *smu)<br>
         struct amdgpu_device *adev = smu->adev;<br>
         struct smu_table_context *smu_table = &smu->smu_table;<br>
         struct smu_table *tables = smu_table->tables;<br>
-       uint32_t i = 0;<br>
-       int32_t ret = 0;<br>
+       int ret, i;<br>
 <br>
         for (i = 0; i < SMU_TABLE_COUNT; i++) {<br>
                 if (tables[i].size == 0)<br>
@@ -915,7 +914,7 @@ static int smu_init_fb_allocations(struct smu_context *smu)<br>
 <br>
         return 0;<br>
 failed:<br>
-       for (; i > 0; i--) {<br>
+       while (--i >= 0) {<br>
                 if (tables[i].size == 0)<br>
                         continue;<br>
                 amdgpu_bo_free_kernel(&tables[i].bo,<br>
-- <br>
2.20.1<br>
<br>
</div>
</span></font></div>
</body>
</html>