drm/amd/display: Fix overlapping copy within dml_core_mode_programming
authorHersen Wu <hersenxs.wu@amd.com>
Tue, 23 Apr 2024 14:57:37 +0000 (10:57 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Fri, 26 Apr 2024 21:22:44 +0000 (17:22 -0400)
[WHY]
&mode_lib->mp.Watermark and &locals->Watermark are
the same address. memcpy may lead to unexpected behavior.

[HOW]
memmove should be used.

Reviewed-by: Rodrigo Siqueira <rodrigo.siqueira@amd.com>
Acked-by: Wayne Lin <wayne.lin@amd.com>
Reviewed-by: Alex Hung <alex.hung@amd.com>
Signed-off-by: Hersen Wu <hersenxs.wu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/display/dc/dml2/display_mode_core.c

index 6255101737b5d05e124103518e82f25c12e1ec58..3e919f5c00ca2b36e8873173048da36430ba52bb 100644 (file)
@@ -9460,8 +9460,10 @@ void dml_core_mode_programming(struct display_mode_lib_st *mode_lib, const struc
 
                /* Copy the calculated watermarks to mp.Watermark as the getter functions are
                 * implemented by the DML team to copy the calculated values from the mp.Watermark interface.
+                * &mode_lib->mp.Watermark and &locals->Watermark are the same address, memcpy may lead to
+                * unexpected behavior. memmove should be used.
                 */
-               memcpy(&mode_lib->mp.Watermark, CalculateWatermarks_params->Watermark, sizeof(struct Watermarks));
+               memmove(&mode_lib->mp.Watermark, CalculateWatermarks_params->Watermark, sizeof(struct Watermarks));
 
                for (k = 0; k < mode_lib->ms.num_active_planes; ++k) {
                        if (mode_lib->ms.cache_display_cfg.writeback.WritebackEnable[k] == true) {