Commit 846883f6 authored by Zhipeng Lu's avatar Zhipeng Lu Committed by Baogen Shang
Browse files

drm/amd/pm: fix a double-free in si_dpm_init

stable inclusion
from stable-v5.10.209
commit aeed2b4e4a70c7568d4a5eecd6a109713c0dfbf4
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I9J6AL
CVE: NA

Reference: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-5.10.y&id=aeed2b4e4a70c7568d4a5eecd6a109713c0dfbf4



-------------------------

[ Upstream commit ac16667237a82e2597e329eb9bc520d1cf9dff30 ]

When the allocation of
adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries fails,
amdgpu_free_extended_power_table is called to free some fields of adev.
However, when the control flow returns to si_dpm_sw_init, it goes to
label dpm_failed and calls si_dpm_fini, which calls
amdgpu_free_extended_power_table again and free those fields again. Thus
a double-free is triggered.

Fixes: 841686df ("drm/amdgpu: add SI DPM support (v4)")
Signed-off-by: default avatarZhipeng Lu <alexious@zju.edu.cn>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
Signed-off-by: default avatarBaogen Shang <baogen.shang@windriver.com>
parent 34c4be6c
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -7349,10 +7349,9 @@ static int si_dpm_init(struct amdgpu_device *adev)
		kcalloc(4,
			sizeof(struct amdgpu_clock_voltage_dependency_entry),
			GFP_KERNEL);
	if (!adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries) {
		amdgpu_free_extended_power_table(adev);
	if (!adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries)
		return -ENOMEM;
	}

	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.count = 4;
	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].clk = 0;
	adev->pm.dpm.dyn_state.vddc_dependency_on_dispclk.entries[0].v = 0;