Skip to contentSkip to conversation

media: verisilicon: Fix crash when probing encoder

PATCH Superseded Benjamin Gaignard 2 participants 2 messages Apr 13, 2023

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Benjamin Gaignard

author maintainer
#0 lore raw

PATCH 1/1 media: verisilicon: Fix crash when probing encoder

ctx->vpu_dst_fmt is no more initialized before calling hantro_try_fmt() so assigne it to vpu_fmt led to crash the kernel.
Like for decoder case use 'fmt' as vpu format for encoder and clean up the code.

Fixes db6f68b51e5c ("media: verisilicon: Do not set context src/dst formats in reset functions")
---
 drivers/media/platform/verisilicon/hantro_v4l2.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/platform/verisilicon/hantro_v4l2.c +3 -5
index 8f1414085f47..51f528f36241 100644
@@ -293,13 +293,11 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
 		pix_mp->pixelformat = fmt->fourcc;
 	}
 
+	vpu_fmt = fmt;
+
 	if (coded) {
 		pix_mp->num_planes = 1;
-		vpu_fmt = fmt;
-	} else if (ctx->is_encoder) {
-		vpu_fmt = ctx->vpu_dst_fmt;
-	} else {
-		vpu_fmt = fmt;
+	} else if (!ctx->is_encoder) {
 		/*
 		 * Width/height on the CAPTURE end of a decoder are ignored and
 		 * replaced by the OUTPUT ones.
Signature · 1 line
2.34.1
maintainer Reviewed-by on v1 1/1
#1 lore raw

Le jeudi 13 avril 2023 à 09:03 +0200, Benjamin Gaignard a écrit :

Quoted 8 lines

ctx->vpu_dst_fmt is no more initialized before calling hantro_try_fmt() so assigne it to vpu_fmt led to crash the kernel.
Like for decoder case use 'fmt' as vpu format for encoder and clean up the code.

Fixes db6f68b51e5c ("media: verisilicon: Do not set context src/dst formats in reset functions")
Quoted 29 lines
---
 drivers/media/platform/verisilicon/hantro_v4l2.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/media/platform/verisilicon/hantro_v4l2.c +3 -5
index 8f1414085f47..51f528f36241 100644
@@ -293,13 +293,11 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
 		pix_mp->pixelformat = fmt->fourcc;
 	}
 
+	vpu_fmt = fmt;
+
 	if (coded) {
 		pix_mp->num_planes = 1;
-		vpu_fmt = fmt;
-	} else if (ctx->is_encoder) {
-		vpu_fmt = ctx->vpu_dst_fmt;
-	} else {
-		vpu_fmt = fmt;
+	} else if (!ctx->is_encoder) {
 		/*
 		 * Width/height on the CAPTURE end of a decoder are ignored and
 		 * replaced by the OUTPUT ones.
Signature · 1 line
2.34.1