[PATCH v3 4/5] media: verisilicon: Restore the encoder raw format when its reset fails

From: Arun Iyengar via B4 Relay

Date: Thu Nov 26 2026 - 12:01:24 EST


From: Arun Iyengar <aiyengar1990@xxxxxxxxx>

hantro_reset_raw_fmt() sets ctx->vpu_src_fmt to the default raw format
before hantro_set_fmt_out(), which fails while OUTPUT buffers exist. A
CAPTURE S_FMT then leaves NM12 in ctx->src_fmt and YM12 in
ctx->vpu_src_fmt, and the next job reads the third plane from IOVA 0
(v4l2-ctl --stream-mmap). Restore ctx->vpu_src_fmt on failure.

Fixes: 14b4bd01f8e5 ("media: verisilicon: Additional fix for the crash when opening the driver")
Signed-off-by: Arun Iyengar <aiyengar1990@xxxxxxxxx>
---
drivers/media/platform/verisilicon/hantro_v4l2.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c
index b91c0ef9b6a3..69e1ef985bff 100644
--- a/drivers/media/platform/verisilicon/hantro_v4l2.c
+++ b/drivers/media/platform/verisilicon/hantro_v4l2.c
@@ -455,7 +455,7 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx)
int
hantro_reset_raw_fmt(struct hantro_ctx *ctx, int bit_depth, bool need_postproc)
{
- const struct hantro_fmt *raw_vpu_fmt;
+ const struct hantro_fmt *raw_vpu_fmt, *old_vpu_src_fmt = NULL;
struct v4l2_pix_format_mplane raw_fmt, *encoded_fmt;
int ret;

@@ -465,6 +465,7 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx, int bit_depth, bool need_postproc)

if (ctx->is_encoder) {
encoded_fmt = &ctx->dst_fmt;
+ old_vpu_src_fmt = ctx->vpu_src_fmt;
ctx->vpu_src_fmt = raw_vpu_fmt;
} else {
encoded_fmt = &ctx->src_fmt;
@@ -481,6 +482,8 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx, int bit_depth, bool need_postproc)
if (!ret) {
ctx->bit_depth = bit_depth;
ctx->need_postproc = need_postproc;
+ } else if (ctx->is_encoder) {
+ ctx->vpu_src_fmt = old_vpu_src_fmt;
}

return ret;

--
2.55.0