drm/amdgpu/powerplay/psm: Fix memory leak in power state init
authorRafael Mendonca <rafaelmendsr@gmail.com>
Tue, 18 Oct 2022 00:53:57 +0000 (21:53 -0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:03 +0000 (13:32 +0100)
[ Upstream commit 8f8033d5663b18e6efb33feb61f2287a04605ab5 ]

Commit 902bc65de0b3 ("drm/amdgpu/powerplay/psm: return an error in power
state init") made the power state init function return early in case of
failure to get an entry from the powerplay table, but it missed to clean up
the allocated memory for the current power state before returning.

Fixes: 902bc65de0b3 ("drm/amdgpu/powerplay/psm: return an error in power state init")
Reviewed-by: Evan Quan <evan.quan@amd.com>
Signed-off-by: Rafael Mendonca <rafaelmendsr@gmail.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/amd/pm/powerplay/hwmgr/pp_psm.c

index 67d7da0..1d82940 100644 (file)
@@ -75,8 +75,10 @@ int psm_init_power_state_table(struct pp_hwmgr *hwmgr)
        for (i = 0; i < table_entries; i++) {
                result = hwmgr->hwmgr_func->get_pp_table_entry(hwmgr, i, state);
                if (result) {
+                       kfree(hwmgr->current_ps);
                        kfree(hwmgr->request_ps);
                        kfree(hwmgr->ps);
+                       hwmgr->current_ps = NULL;
                        hwmgr->request_ps = NULL;
                        hwmgr->ps = NULL;
                        return -EINVAL;