[PATCH] drm/amd/display: Fix NULL dereference when preferred_mode is NULL

Nicholas Kazlauskas nicholas.kazlauskas at amd.com
Thu Nov 29 15:17:39 UTC 2018


[Why]
When preferred_mode is NULL a null pointer dereference can occur
when trying to get the preferred refresh in create_stream_for_sink.

[How]
Only query preferred_refresh when preferred_mode is not NULL. Consider
preferred_refresh if it is since it's only being used to compare to
the previous value.

Fixes: b333730d126e ("drm/amd/display: Fix Scaling (RMX_*) for DC driver")

Signed-off-by: Nicholas Kazlauskas <nicholas.kazlauskas at amd.com>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
index ce00e56814ed..478fa810438e 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
@@ -2848,7 +2848,7 @@ create_stream_for_sink(struct amdgpu_dm_connector *aconnector,
 	bool native_mode_found = false;
 	bool scale = dm_state ? (dm_state->scaling != RMX_OFF) : false;
 	int mode_refresh;
-	int preferred_refresh;
+	int preferred_refresh = 0;
 
 	struct dc_sink *sink = NULL;
 	if (aconnector == NULL) {
@@ -2907,7 +2907,8 @@ create_stream_for_sink(struct amdgpu_dm_connector *aconnector,
 	if (!dm_state)
 		drm_mode_set_crtcinfo(&mode, 0);
 
-	preferred_refresh = drm_mode_vrefresh(preferred_mode);
+	if (preferred_mode)
+		preferred_refresh = drm_mode_vrefresh(preferred_mode);
 
 	/*
 	* If scaling is enabled and refresh rate didn't change
-- 
2.17.1



More information about the amd-gfx mailing list