From be51e7c45aa450edd013ec21a8bb017c6f165f02 Mon Sep 17 00:00:00 2001 From: Ryan Seto Date: Fri, 1 Nov 2024 10:19:56 -0400 Subject: [PATCH] drm/amd/display: Handle dml allocation failure to avoid crash BugLink: https://bugs.launchpad.net/bugs/2101042 commit 6825cb07b79ffeb1d90ffaa7a1227462cdca34ae upstream. [Why] In the case where a dml allocation fails for any reason, the current state's dml contexts would no longer be valid. Then subsequent calls dc_state_copy_internal would shallow copy invalid memory and if the new state was released, a double free would occur. [How] Reset dml pointers in new_state to NULL and avoid invalid pointer Reviewed-by: Dillon Varone Signed-off-by: Ryan Seto Signed-off-by: Hamza Mahfooz Signed-off-by: Alex Deucher (cherry picked from commit bcafdc61529a48f6f06355d78eb41b3aeda5296c) Cc: stable@vger.kernel.org Signed-off-by: Greg Kroah-Hartman [diewald: do not set dml2_dc_power_state that was introduced in missing commit e779f4587f61 drm/amd/display: Add handling for DC power mode] Signed-off-by: Manuel Diewald Signed-off-by: Stefan Bader --- drivers/gpu/drm/amd/display/dc/core/dc_state.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/gpu/drm/amd/display/dc/core/dc_state.c b/drivers/gpu/drm/amd/display/dc/core/dc_state.c index 5273068cf852..22267085e7cb 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc_state.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc_state.c @@ -244,6 +244,8 @@ struct dc_state *dc_state_create_copy(struct dc_state *src_state) dc_state_copy_internal(new_state, src_state); #ifdef CONFIG_DRM_AMD_DC_FP + new_state->bw_ctx.dml2 = NULL; + if (src_state->bw_ctx.dml2 && !dml2_create_copy(&new_state->bw_ctx.dml2, src_state->bw_ctx.dml2)) { dc_state_release(new_state);