Skip to contentSkip to conversation

drm/amd/display: Add null checks for 'stream' and 'plane' before dereferencing

PATCH In review Zhi Yang 2 participants 2 messages Apr 10, 2025 Stable branch

lore
Share & tools
lore

Zhi Yang

author
#0 lore raw

PATCH 1/1 drm/amd/display: Add null checks for 'stream' and 'plane' before dereferencing

From: Srinivasan Shanmugam <[email protected]>

commit 15c2990e0f0108b9c3752d7072a97d45d4283aea upstream.

This commit adds null checks for the 'stream' and 'plane' variables in the dcn30_apply_idle_power_optimizations function. These variables were previously assumed to be null at line 922, but they were used later in the code without checking if they were null. This could potentially lead to a null pointer dereference, which would cause a crash.

The null checks ensure that 'stream' and 'plane' are not null before they are used, preventing potential crashes.

Fixes the below static smatch checker:
drivers/gpu/drm/amd/amdgpu/../display/dc/hwss/dcn30/dcn30_hwseq.c:938 dcn30_apply_idle_power_optimizations() error: we previously assumed 'stream' could be null (see line 922) drivers/gpu/drm/amd/amdgpu/../display/dc/hwss/dcn30/dcn30_hwseq.c:940 dcn30_apply_idle_power_optimizations() error: we previously assumed 'plane' could be null (see line 922)

Cc Tom Chung <[email protected]>
Cc Nicholas Kazlauskas <[email protected]>
Cc Bhawanpreet Lakha <[email protected]>
Cc Rodrigo Siqueira <[email protected]>
Cc Roman Li <[email protected]>
Cc Hersen Wu <[email protected]>
Cc Alex Hung <[email protected]>
Cc Aurabindo Pillai <[email protected]>
Cc Harry Wentland <[email protected]>

---
Build test passed.

---
 drivers/gpu/drm/amd/display/dc/dcn30/dcn30_hwseq.c | 3 +++
 1 file changed, 3 insertions(+)
drivers/gpu/drm/amd/display/dc/dcn30/dcn30_hwseq.c +3 -0
index 81547178a934..30716b88136c 100644
@@ -784,6 +784,9 @@ bool dcn30_apply_idle_power_optimizations(struct dc *dc, bool enable)
 			stream = dc->current_state->streams[0];
 			plane = (stream ? dc->current_state->stream_status[0].plane_states[0] : NULL);
 
+			if (!stream || !plane)
+				return false;
+
 			if (stream && plane) {
 				cursor_cache_enable = stream->cursor_position.enable &&
 						plane->address.grph.cursor_cache_addr.quad_part;
Signature · 1 line
2.34.1
maintainer Reviewed-by Aurabindo Pillai on v1 1/1
#1 lore raw

[ Sasha's backport helper bot ]

Hi,

✅ All tests passed successfully. No issues detected. No action required from the submitter.

The upstream commit SHA1 provided is correct: 15c2990e0f0108b9c3752d7072a97d45d4283aea

WARNING: Author mismatch between patch and upstream commit:
Backport author: Zhi Yang<[email protected]> Commit author: Srinivasan Shanmugam<[email protected]>

Status in newer kernel trees:

6.14.y | Present (exact SHA1)
6.13.y | Present (exact SHA1)
6.12.y | Present (exact SHA1)

6.6.y | Present (different SHA1: 10c20d79d59c)
6.1.y | Present (different SHA1: 5e84eda48ffb)

Note: The patch differs from the upstream commit:
---
1: 15c2990e0f010 ! 1: 23cc38e759775 drm/amd/display: Add null checks for 'stream' and 'plane' before dereferencing
@@ Metadata
## Commit message ##
drm/amd/display: Add null checks for 'stream' and 'plane' before dereferencing

+ commit 15c2990e0f0108b9c3752d7072a97d45d4283aea upstream.
+
This commit adds null checks for the 'stream' and 'plane' variables in the dcn30_apply_idle_power_optimizations function. These variables were previously assumed to be null at line 922, but they were used later in
@@ Commit message

+ Signed-off-by: Zhi Yang <[email protected]>
+ Signed-off-by: He Zhe <[email protected]>

- ## drivers/gpu/drm/amd/display/dc/hwss/dcn30/dcn30_hwseq.c ##
-@@ drivers/gpu/drm/amd/display/dc/hwss/dcn30/dcn30_hwseq.c: bool dcn30_apply_idle_power_optimizations(struct dc *dc, bool enable)
+ ## drivers/gpu/drm/amd/display/dc/dcn30/dcn30_hwseq.c ##
+@@ drivers/gpu/drm/amd/display/dc/dcn30/dcn30_hwseq.c: bool dcn30_apply_idle_power_optimizations(struct dc *dc, bool enable)
stream = dc->current_state->streams[0];
plane = (stream ? dc->current_state->stream_status[0].plane_states[0] : NULL);

---

Results of testing on various branches:

| Branch                    | Patch Apply | Build Test |
|---------------------------|-------------|------------|
| stable/linux-5.15.y       |  Success    |  Success   |