From: Hersen Wu <[email protected]>

[ Upstream commit 025ce392b5f213696ca0af3e07735d0fae020694 ]

[Why]
when amdgpu_dm_update_connector_after_detect is called
two times successively with valid sink, memory allocated of
aconnector->timing_requested for the first call is not free.
this causes memeleak.

[How]
allocate memory only when aconnector->timing_requested
is null.

Reviewed-by: Qingqing Zhuo <[email protected]>
Acked-by: Qingqing Zhuo <[email protected]>
Signed-off-by: Hersen Wu <[email protected]>
Tested-by: Daniel Wheeler <[email protected]>
Signed-off-by: Alex Deucher <[email protected]>
Signed-off-by: Sasha Levin <[email protected]>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index a01fd41643fc2..5dced13f4ae8d 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -3094,9 +3094,12 @@ void amdgpu_dm_update_connector_after_detect(
                                                    aconnector->edid);
                }
 
-               aconnector->timing_requested = kzalloc(sizeof(struct 
dc_crtc_timing), GFP_KERNEL);
-               if (!aconnector->timing_requested)
-                       dm_error("%s: failed to create 
aconnector->requested_timing\n", __func__);
+               if (!aconnector->timing_requested) {
+                       aconnector->timing_requested =
+                               kzalloc(sizeof(struct dc_crtc_timing), 
GFP_KERNEL);
+                       if (!aconnector->timing_requested)
+                               dm_error("failed to create 
aconnector->requested_timing\n");
+               }
 
                drm_connector_update_edid_property(connector, aconnector->edid);
                amdgpu_dm_update_freesync_caps(connector, aconnector->edid);
-- 
2.39.2

Reply via email to