[PATCH] drm/amd/display: avoid amdgpu_crtc dereference before crtc check

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



'amdgpu_crtc' is set with 'container_of(crtc, ...)', and at
the same time 'crtc' ptr is checked for NULL before and after
'amdgpu_crtc' dereference in args passed to drm_dbg_atomic():

  * when setting 'struct dm_crtc_state *crtc_state'
  * inside amdgpu_dm_plane_get_cursor_position(), the function
    doesn't set position.enable when crtc is NULL.

Considering all this, it is safer to move drm_dbg_atomic() after
'position.enable' check. It can guarantee that 'crtc' is valid
and that 'amdgpu_crtc' also has a valid pointer.

Detected using the static analysis tool - Svace.

Signed-off-by: Alexey Kodanev <aleksei.kodanev@xxxxxxxxxxx>
---
 drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
index 116121e647ca..47d8d569d9eb 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_plane.c
@@ -1242,10 +1242,6 @@ void amdgpu_dm_plane_handle_cursor_update(struct drm_plane *plane,
 	if (!plane->state->fb && !old_plane_state->fb)
 		return;
 
-	drm_dbg_atomic(plane->dev, "crtc_id=%d with size %d to %d\n",
-		       amdgpu_crtc->crtc_id, plane->state->crtc_w,
-		       plane->state->crtc_h);
-
 	ret = amdgpu_dm_plane_get_cursor_position(plane, crtc, &position);
 	if (ret)
 		return;
@@ -1261,6 +1257,10 @@ void amdgpu_dm_plane_handle_cursor_update(struct drm_plane *plane,
 		return;
 	}
 
+	drm_dbg_atomic(plane->dev, "crtc_id=%d with size %d to %d\n",
+		       amdgpu_crtc->crtc_id, plane->state->crtc_w,
+		       plane->state->crtc_h);
+
 	amdgpu_crtc->cursor_width = plane->state->crtc_w;
 	amdgpu_crtc->cursor_height = plane->state->crtc_h;
 
-- 
2.25.1




[Index of Archives]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux