drm/amd/pm: fix a memleak in aldebaran_tables_init
authorDinghao Liu <dinghao.liu@zju.edu.cn>
Thu, 23 Nov 2023 07:33:22 +0000 (15:33 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 29 Nov 2023 23:09:14 +0000 (18:09 -0500)
When kzalloc() for smu_table->ecc_table fails, we should free
the previously allocated resources to prevent memleak.

Fixes: edd794208555 ("drm/amd/pm: add message smu to get ecc_table v2")
Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c

index 1a6675d..f144086 100644 (file)
@@ -257,8 +257,11 @@ static int aldebaran_tables_init(struct smu_context *smu)
        }
 
        smu_table->ecc_table = kzalloc(tables[SMU_TABLE_ECCINFO].size, GFP_KERNEL);
-       if (!smu_table->ecc_table)
+       if (!smu_table->ecc_table) {
+               kfree(smu_table->metrics_table);
+               kfree(smu_table->gpu_metrics_table);
                return -ENOMEM;
+       }
 
        return 0;
 }