OSDN Git Service

drm/amd/display: fix memleak in aconnector->timing_requested
authorHersen Wu <hersenxs.wu@amd.com>
Mon, 27 Mar 2023 13:10:48 +0000 (09:10 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 27 Apr 2023 02:28:37 +0000 (22:28 -0400)
[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 <Qingqing.Zhuo@amd.com>
Acked-by: Qingqing Zhuo <qingqing.zhuo@amd.com>
Signed-off-by: Hersen Wu <hersenxs.wu@amd.com>
Tested-by: Daniel Wheeler <daniel.wheeler@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c

index c432436..8b03c8d 100644 (file)
@@ -3128,9 +3128,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);