From a63f63f473e0ad53351c99e9602ee00c8428af2a Mon Sep 17 00:00:00 2001 From: Wenjing Liu Date: Tue, 7 Jul 2026 17:15:48 -0400 Subject: [PATCH] drm/amd/display: Make dc_state_update const in commit path [Why] The state-update commit path only reads the caller's update descriptor, it never mutates the dc_state_update root. Making the pointer const documents that contract. [How] Add const to the updates parameter of dc_update_state and dc_check_state_update. Mark the single-assignment locals in dc_update_state_init const and replace the memset plus field-by-field assignment with a compound literal initializer. Reviewed-by: Dominik Kaszewski Signed-off-by: Wenjing Liu Signed-off-by: Wayne Lin Tested-by: Dan Wheeler Signed-off-by: Alex Deucher --- drivers/gpu/drm/amd/display/dc/core/dc.c | 42 ++++++++++++------------ drivers/gpu/drm/amd/display/dc/dc.h | 4 +-- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c b/drivers/gpu/drm/amd/display/dc/core/dc.c index 78408fc60eb8..01a469f34ad4 100644 --- a/drivers/gpu/drm/amd/display/dc/core/dc.c +++ b/drivers/gpu/drm/amd/display/dc/core/dc.c @@ -3281,7 +3281,7 @@ static struct dc_update_descriptor check_update_surfaces_for_stream( */ struct dc_update_descriptor dc_check_state_update( const struct dc_check_config *check_config, - struct dc_state_update *updates) + const struct dc_state_update *updates) { struct dc_update_descriptor desc = {0}; @@ -6263,7 +6263,7 @@ static void dc_update_scratch_release(struct dc *dc, * @updates: root update object carrying stream, plane, and probe updates * Return: true on success, false on failure. */ -bool dc_update_state(struct dc *dc, struct dc_state_update *updates) +bool dc_update_state(struct dc *dc, const struct dc_state_update *updates) { struct dc_update_scratch_space *scratch; bool more = true; @@ -8524,11 +8524,11 @@ struct dc_update_scratch_space *dc_update_state_init( { const enum dce_version version = dc->ctx->dce_version; struct dc_update_scratch_space *scratch = dc_update_scratch_acquire(dc); - bool has_stream_or_plane = updates->stream || updates->stream_update || updates->surface_updates; - bool has_probe = updates->probe_updates; - bool surface_without_stream = updates->surface_updates && !updates->stream; - bool stream_update_without_stream = updates->stream_update && !updates->stream; - bool bad_surface_count = updates->surface_count > 0 && !updates->surface_updates; + const bool has_stream_or_plane = updates->stream || updates->stream_update || updates->surface_updates; + const bool has_probe = updates->probe_updates; + const bool surface_without_stream = updates->surface_updates && !updates->stream; + const bool stream_update_without_stream = updates->stream_update && !updates->stream; + const bool bad_surface_count = updates->surface_count > 0 && !updates->surface_updates; if (!scratch) return NULL; @@ -8543,20 +8543,20 @@ struct dc_update_scratch_space *dc_update_state_init( return NULL; } - memset(scratch, 0, sizeof(*scratch)); - - scratch->dc = dc; - scratch->surface_updates = updates->surface_updates; - scratch->surface_count = updates->surface_count; - scratch->stream = updates->stream; - scratch->stream_update = updates->stream_update; - scratch->probe_updates = updates->probe_updates; - scratch->update_v3 = version >= DCN_VERSION_4_01 - || version == DCN_VERSION_3_2 - || version == DCN_VERSION_3_21; - scratch->do_clear_update_bits = version >= DCN_VERSION_1_0; - scratch->new_context = NULL; - scratch->flow = UPDATE_V3_FLOW_INVALID; + *scratch = (struct dc_update_scratch_space){ + .dc = dc, + .surface_updates = updates->surface_updates, + .surface_count = updates->surface_count, + .stream = updates->stream, + .stream_update = updates->stream_update, + .probe_updates = updates->probe_updates, + .update_v3 = version >= DCN_VERSION_4_01 + || version == DCN_VERSION_3_2 + || version == DCN_VERSION_3_21, + .do_clear_update_bits = version >= DCN_VERSION_1_0, + .new_context = NULL, + .flow = UPDATE_V3_FLOW_INVALID, + }; return scratch; } diff --git a/drivers/gpu/drm/amd/display/dc/dc.h b/drivers/gpu/drm/amd/display/dc/dc.h index 0913fab7504c..743dde3d10ab 100644 --- a/drivers/gpu/drm/amd/display/dc/dc.h +++ b/drivers/gpu/drm/amd/display/dc/dc.h @@ -2125,7 +2125,7 @@ struct dc_state_update { */ struct dc_update_descriptor dc_check_state_update( const struct dc_check_config *check_config, - struct dc_state_update *updates); + const struct dc_state_update *updates); /** * dc_update_state - Commit an absolute dc_state_update. @@ -2134,7 +2134,7 @@ struct dc_update_descriptor dc_check_state_update( * * Return: true on success, false on failure. */ -bool dc_update_state(struct dc *dc, struct dc_state_update *updates); +bool dc_update_state(struct dc *dc, const struct dc_state_update *updates); struct dc_update_scratch_space;