]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/amd/powerplay: Fix error handling in smu_init_fb_allocations()
authorDan Carpenter <dan.carpenter@oracle.com>
Mon, 7 Oct 2019 09:02:06 +0000 (12:02 +0300)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 7 Oct 2019 20:10:56 +0000 (15:10 -0500)
The error handling is off by one.  We should not free the first
"tables[i].bo" without decrementing "i" because that might result in a
double free.  The second problem is that when an error occurs, then the
zeroth element "tables[0].bo" isn't freed.

I had make "i" signed int for the error handling to work, so I just
updated "ret" as well as a clean up.

Fixes: f96357a991b9 ("drm/amd/powerplay: implement smu_init(fini)_fb_allocations function")
Reviewed-by: Kevin Wang <kevin1.wang@amd.com>
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/powerplay/amdgpu_smu.c

index f1fbbc8b77ee101f49c04941ed0cddc4651d768d..c9266ea7033104f2486b0e8a7f1099b385c14553 100644 (file)
@@ -896,8 +896,7 @@ static int smu_init_fb_allocations(struct smu_context *smu)
        struct amdgpu_device *adev = smu->adev;
        struct smu_table_context *smu_table = &smu->smu_table;
        struct smu_table *tables = smu_table->tables;
-       uint32_t i = 0;
-       int32_t ret = 0;
+       int ret, i;
 
        for (i = 0; i < SMU_TABLE_COUNT; i++) {
                if (tables[i].size == 0)
@@ -915,7 +914,7 @@ static int smu_init_fb_allocations(struct smu_context *smu)
 
        return 0;
 failed:
-       for (; i > 0; i--) {
+       while (--i >= 0) {
                if (tables[i].size == 0)
                        continue;
                amdgpu_bo_free_kernel(&tables[i].bo,