[PATCH 57/70] drm/amd/display: Make dc_state_update const in commit path

Wayne Lin <[email protected]>
Newsgroups org.freedesktop.lists.amd-gfx
Message-ID <[email protected]>
From: Wenjing Liu <[email protected]>

[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 <[email protected]>
Signed-off-by: Wenjing Liu <[email protected]>
Signed-off-by: Wayne Lin <[email protected]>
---
 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 2bd579340b64..318c3b28e918 100644
--- a/drivers/gpu/drm/amd/display/dc/core/dc.c
+++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
@@ -3282,7 +3282,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};
 
@@ -6264,7 +6264,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;
@@ -8525,11 +8525,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;
@@ -8544,20 +8544,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;
 
-- 
2.43.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.