[PATCH drm-misc-next v4 4/4] drm: verisilicon: fill plane's vs_format in atomic_check

Icenowy Zheng
2026-03-31T06:01:47Z

Move the conversion from drm_format to vs_format to atomic_check, which
is before the point of no return and can properly bail out.

Signed-off-by: Icenowy Zheng <zhengxingda@iscas.ac.cn>
Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>
---
Changes in v4:
- Make atomic_check early return if the plane isn't visible.
- Added Thomas's R-b.

Changes in v3:
- Move the code filling vs_format to after drm_atomic_helper_check_plane_state()
call.
- Add drm_WARN_ON_ONCE when filling vs_format fails.
- Add code copying vs_format in vs_plane_duplicate_state (because it no
longer memdup's the whole struct vs_plane_state).

Changes in v2:
- Add non-NULL check for drm_plane_state->fb.

drivers/gpu/drm/verisilicon/vs_plane.c | 7 +++-
drivers/gpu/drm/verisilicon/vs_plane.h | 2 ++
.../gpu/drm/verisilicon/vs_primary_plane.c | 36 +++++++++++++------
3 files changed, 33 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/verisilicon/vs_plane.c b/drivers/gpu/drm/verisilicon/vs_plane.c
index 7c6b905c9e1fa..d81f7b8f4c650 100644
--- a/drivers/gpu/drm/verisilicon/vs_plane.c
+++ b/drivers/gpu/drm/verisilicon/vs_plane.c
@@ -129,17 +129,22 @@ dma_addr_t vs_fb_get_dma_addr(struct drm_framebuffer *fb,

struct drm_plane_state *vs_plane_duplicate_state(struct drm_plane *plane)
{
- struct vs_plane_state *vs_state;
+ struct vs_plane_state *vs_state, *vs_state_old;

if (drm_WARN_ON(plane->dev, !plane->state))
return NULL;

+ vs_state_old = to_vs_plane_state(plane->state);
+
vs_state = kzalloc_obj(*vs_state, GFP_KERNEL);
if (!vs_state)
return NULL;

__drm_atomic_helper_plane_duplicate_state(plane, &vs_state->base);

+ memcpy(&vs_state->format, &vs_state_old->format,
+ sizeof(struct vs_format));
+
return &vs_state->base;
}

diff --git a/drivers/gpu/drm/verisilicon/vs_plane.h b/drivers/gpu/drm/verisilicon/vs_plane.h
index 48ed8fc754d18..f18c36ef4cd90 100644
--- a/drivers/gpu/drm/verisilicon/vs_plane.h
+++ b/drivers/gpu/drm/verisilicon/vs_plane.h
@@ -65,6 +65,8 @@ struct vs_format {

struct vs_plane_state {
struct drm_plane_state base;
+
+ struct vs_format format;
};

static inline struct vs_plane_state *to_vs_plane_state(struct drm_plane_state *state)
diff --git a/drivers/gpu/drm/verisilicon/vs_primary_plane.c b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
index 421d6f9dc547b..3576dd524f5c4 100644
--- a/drivers/gpu/drm/verisilicon/vs_primary_plane.c
+++ b/drivers/gpu/drm/verisilicon/vs_primary_plane.c
@@ -25,17 +25,32 @@ static int vs_primary_plane_atomic_check(struct drm_plane *plane,
{
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
plane);
+ struct vs_plane_state *new_vs_plane_state = to_vs_plane_state(new_plane_state);
+ struct drm_framebuffer *fb = new_plane_state->fb;
struct drm_crtc *crtc = new_plane_state->crtc;
struct drm_crtc_state *crtc_state = NULL;
+ int ret;

if (crtc)
crtc_state = drm_atomic_get_new_crtc_state(state, crtc);

- return drm_atomic_helper_check_plane_state(new_plane_state,
- crtc_state,
- DRM_PLANE_NO_SCALING,
- DRM_PLANE_NO_SCALING,
- false, true);
+ ret = drm_atomic_helper_check_plane_state(new_plane_state,
+ crtc_state,
+ DRM_PLANE_NO_SCALING,
+ DRM_PLANE_NO_SCALING,
+ false, true);
+ if (ret)
+ return ret;
+
+ if (!new_plane_state->visible)
+ return 0;
+
+ ret = drm_format_to_vs_format(fb->format->format,
+ &new_vs_plane_state->format);
+ if (drm_WARN_ON_ONCE(plane->dev, ret))
+ return ret;
+
+ return 0;
}

static void vs_primary_plane_commit(struct vs_dc *dc, unsigned int output)
@@ -84,11 +99,11 @@ static void vs_primary_plane_atomic_update(struct drm_plane *plane,
{
struct drm_plane_state *state = drm_atomic_get_new_plane_state(atomic_state,
plane);
+ struct vs_plane_state *vs_state = to_vs_plane_state(state);
struct drm_framebuffer *fb = state->fb;
struct drm_crtc *crtc = state->crtc;
struct vs_dc *dc;
struct vs_crtc *vcrtc;
- struct vs_format fmt;
unsigned int output;
dma_addr_t dma_addr;

@@ -101,16 +116,15 @@ static void vs_primary_plane_atomic_update(struct drm_plane *plane,
output = vcrtc->id;
dc = vcrtc->dc;

- drm_format_to_vs_format(state->fb->format->format, &fmt);
-
regmap_update_bits(dc->regs, VSDC_FB_CONFIG(output),
VSDC_FB_CONFIG_FMT_MASK,
- VSDC_FB_CONFIG_FMT(fmt.color));
+ VSDC_FB_CONFIG_FMT(vs_state->format.color));
regmap_update_bits(dc->regs, VSDC_FB_CONFIG(output),
VSDC_FB_CONFIG_SWIZZLE_MASK,
- VSDC_FB_CONFIG_SWIZZLE(fmt.swizzle));
+ VSDC_FB_CONFIG_SWIZZLE(vs_state->format.swizzle));
regmap_assign_bits(dc->regs, VSDC_FB_CONFIG(output),
- VSDC_FB_CONFIG_UV_SWIZZLE_EN, fmt.uv_swizzle);
+ VSDC_FB_CONFIG_UV_SWIZZLE_EN,
+ vs_state->format.uv_swizzle);

dma_addr = vs_fb_get_dma_addr(fb, &state->src);

--
2.52.0