Skip to contentSkip to conversation

drm/vmwgfx: Add some checks to vmw_cursor_plane_atomic_update

PATCH New Maaz Mombasawala 1 participant 1 message Nov 17

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v7 1/1 drm/vmwgfx: Add some checks to vmw_cursor_plane_atomic_update

In cases where old_state may not be present we hit a null dereference. Get display unit from cursor plane instead to fix this and also do an early return if there is no new_state since there is nothing to do in that case.
This fixes igt test kms_cursor_legacy@torture-bo.

Fixes 965544150d1c ("drm/vmwgfx: Refactor cursor handling")
Cc Zack Rusin <[email protected]>
Cc Broadcom internal kernel review list <[email protected]>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c | 18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/gpu/drm/vmwgfx/vmwgfx_cursor_plane.c +11 -7
index b678e5b68db7..16e6635ef4ce 100644
@@ -22,6 +22,9 @@
 #define VMW_CURSOR_SNOOP_WIDTH 64
 #define VMW_CURSOR_SNOOP_HEIGHT 64
 
+#define vmw_cursor_to_du(cursor_plane) \
+	container_of(cursor_plane, struct vmw_display_unit, cursor.base)
+
 struct vmw_svga_fifo_cmd_define_cursor {
 	u32 cmd;
 	SVGAFifoCmdDefineAlphaCursor cursor;
@@ -866,16 +869,17 @@ void
 vmw_cursor_plane_atomic_update(struct drm_plane *plane,
 			       struct drm_atomic_commit *state)
 {
-	struct drm_plane_state *new_state =
-		drm_atomic_get_new_plane_state(state, plane);
-	struct drm_plane_state *old_state =
-		drm_atomic_get_old_plane_state(state, plane);
-	struct drm_crtc *crtc = new_state->crtc ?: old_state->crtc;
+	struct drm_plane_state *new_state;
 	struct vmw_private *dev_priv = vmw_priv(plane->dev);
-	struct vmw_display_unit *du = vmw_crtc_to_du(crtc);
-	struct vmw_plane_state *vps = vmw_plane_state_to_vps(new_state);
+	struct vmw_display_unit *du = vmw_cursor_to_du(plane);
+	struct vmw_plane_state *vps;
 	s32 hotspot_x, hotspot_y, cursor_x, cursor_y;
 
+	new_state = drm_atomic_get_new_plane_state(state, plane);
+	if (!new_state)
+		return;
+	vps = vmw_plane_state_to_vps(new_state);
+
 	/*
 	 * Hide the cursor if the new bo is null
 	 */
Signature · 1 line
2.56.1