[PATCH v2] drm/meson: disable OSD1 for invisible planes in atomic_update

Shirong Zhao shxzhaosr at 163.com
Fri Dec 4 18:41:23 PST 2026


meson_plane_atomic_update() computes the scaler phase steps as

	hf_phase_step = ((src_w << 18) / dst_w) << 6;
	vf_phase_step = (src_h << 20) / dst_h;

using the plane destination size.  When a plane becomes invisible (for
example a zero destination size submitted through the atomic ioctl),
drm_atomic_helper_commit_planes() does not call ->atomic_disable() for a
plane that keeps its CRTC; it calls ->atomic_update() instead, so dst_w or
dst_h can be 0 and the divisions raise a divide error.

Handling only the division is not enough: returning early would leave OSD1
enabled and still scanning out the previous buffer's DMA address, so a
commit that replaced the framebuffer and freed the old GEM buffer would
become a DMA use-after-free.  Call meson_plane_atomic_disable(), which
clears priv->viu.osd1_enabled and disables OSD1, and return.

Fixes: 7db647aa8b13 ("drm/meson: Add primary plane scaling")
Signed-off-by: Shirong Zhao <shxzhaosr at 163.com>
---
 drivers/gpu/drm/meson/meson_plane.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 76eb8b8..f836c8f 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -131,6 +131,9 @@ static u32 meson_g12a_afbcd_line_stride(struct meson_drm *priv)
 	return ((line_stride + 1) >> 1) << 1;
 }
 
+static void meson_plane_atomic_disable(struct drm_plane *plane,
+				       struct drm_atomic_commit *state);
+
 static void meson_plane_atomic_update(struct drm_plane *plane,
 				      struct drm_atomic_commit *state)
 {
@@ -152,6 +155,17 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
 	int vf_bank_len;
 	u8 canvas_id_osd1;
 
+	/*
+	 * A zero destination size makes the plane invisible and
+	 * drm_atomic_helper_commit_planes() still calls ->atomic_update() for a
+	 * plane that keeps its CRTC.  Disable OSD1 instead of dividing by a zero
+	 * dst_w/dst_h below, and to avoid leaving it scanning out a stale buffer.
+	 */
+	if (!new_state->visible) {
+		meson_plane_atomic_disable(plane, state);
+		return;
+	}
+
 	/*
 	 * Update Coordinates
 	 * Update Formats
-- 
2.53.0




More information about the linux-amlogic mailing list