media: verisilicon: Fix crash when probing encoder
authorBenjamin Gaignard <benjamin.gaignard@collabora.com>
Thu, 13 Apr 2023 10:47:56 +0000 (12:47 +0200)
committerHans Verkuil <hverkuil-cisco@xs4all.nl>
Thu, 13 Apr 2023 10:58:55 +0000 (12:58 +0200)
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 format for encoder and clean up
the code.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Tested-by: Marek Szyprowski <m.szyprowski@samsung.com>
Fixes: db6f68b51e5c ("media: verisilicon: Do not set context src/dst formats in reset functions")
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
drivers/media/platform/verisilicon/hantro_v4l2.c

index d238d407f986d4a7fa86d00e7e3960c2fb9ef420..835518534e3b94dc6f352cf3a8fe0330db4d79c5 100644 (file)
@@ -275,7 +275,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
                          struct v4l2_pix_format_mplane *pix_mp,
                          enum v4l2_buf_type type)
 {
-       const struct hantro_fmt *fmt, *vpu_fmt;
+       const struct hantro_fmt *fmt;
        bool capture = V4L2_TYPE_IS_CAPTURE(type);
        bool coded;
 
@@ -295,11 +295,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
 
        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.
@@ -311,7 +307,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx,
        pix_mp->field = V4L2_FIELD_NONE;
 
        v4l2_apply_frmsize_constraints(&pix_mp->width, &pix_mp->height,
-                                      &vpu_fmt->frmsize);
+                                      &fmt->frmsize);
 
        if (!coded) {
                /* Fill remaining fields */