[PATCH v3 4/5] drm/verisilicon: check old state CRTC in plane atomic_disable

From: Icenowy Zheng

Date: Wed Nov 18 2026 - 10:36:16 EST


As atomic_update hooks of both planes would utilize atomic_disable
functions to disable the plane when it's set to invisible (even when
technically enabled), the atomic_disable functions need to check whether
the plane is really enabled before.

Add such a check to prevent NULL dereference.

Fixes: dbf21777caa8 ("drm: verisilicon: add a driver for Verisilicon display controllers")
Fixes: 8c4ae2189125 ("drm: verisilicon: add support for cursor planes")
Signed-off-by: Icenowy Zheng <zhengxingda@xxxxxxxxxxx>
---
drivers/gpu/drm/verisilicon/vs_cursor_plane.c | 13 ++++++++++---
drivers/gpu/drm/verisilicon/vs_primary_plane.c | 13 ++++++++++---
2 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/verisilicon/vs_cursor_plane.c b/drivers/gpu/drm/verisilicon/vs_cursor_plane.c
index 1e1805eb88704..a58e4a47cf286 100644
--- a/drivers/gpu/drm/verisilicon/vs_cursor_plane.c
+++ b/drivers/gpu/drm/verisilicon/vs_cursor_plane.c
@@ -105,9 +105,16 @@ static void vs_cursor_plane_atomic_disable(struct drm_plane *plane,
struct drm_plane_state *state = drm_atomic_get_old_plane_state(atomic_state,
plane);
struct drm_crtc *crtc = state->crtc;
- struct vs_crtc *vcrtc = drm_crtc_to_vs_crtc(crtc);
- unsigned int output = vcrtc->id;
- struct vs_dc *dc = vcrtc->dc;
+ struct vs_crtc *vcrtc;
+ unsigned int output;
+ struct vs_dc *dc;
+
+ if (!crtc)
+ return;
+
+ vcrtc = drm_crtc_to_vs_crtc(crtc);
+ output = vcrtc->id;
+ dc = vcrtc->dc;

regmap_update_bits(dc->regs, VSDC_CURSOR_CONFIG(output),
VSDC_CURSOR_CONFIG_FMT_MASK,
diff --git a/drivers/gpu/drm/verisilicon/vs_primary_plane.c b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
index 7add4669f5803..730dab6204e98 100644
--- a/drivers/gpu/drm/verisilicon/vs_primary_plane.c
+++ b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
@@ -66,9 +66,16 @@ static void vs_primary_plane_atomic_disable(struct drm_plane *plane,
struct drm_plane_state *state = drm_atomic_get_old_plane_state(atomic_state,
plane);
struct drm_crtc *crtc = state->crtc;
- struct vs_crtc *vcrtc = drm_crtc_to_vs_crtc(crtc);
- unsigned int output = vcrtc->id;
- struct vs_dc *dc = vcrtc->dc;
+ struct vs_crtc *vcrtc;
+ unsigned int output;
+ struct vs_dc *dc;
+
+ if (!crtc)
+ return;
+
+ vcrtc = drm_crtc_to_vs_crtc(crtc);
+ output = vcrtc->id;
+ dc = vcrtc->dc;

regmap_clear_bits(dc->regs, VSDC_FB_CONFIG_EX(output),
VSDC_FB_CONFIG_EX_FB_EN);
--
2.56.0