media: mtk-vcodec: vdec: clean up vidioc_vdec_s_fmt a bit
authorAlexandre Courbot <acourbot@chromium.org>
Fri, 6 Sep 2019 11:55:03 +0000 (08:55 -0300)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Tue, 1 Oct 2019 19:46:42 +0000 (16:46 -0300)
Check for a potentially NULL pointer that was overlooked and use shorter
accessors to the same data. While we are at it, sprinkle a few comments.

Signed-off-by: Alexandre Courbot <acourbot@chromium.org>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c

index 653f111532ab59f55ae8966f83beeb0cb343c40b..858727824889f6c10aa892af45aab0895a3ff907 100644 (file)
@@ -841,12 +841,20 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv,
                return -EINVAL;
 
        pix_mp = &f->fmt.pix_mp;
+       /*
+        * Setting OUTPUT format after OUTPUT buffers are allocated is invalid
+        * if using the stateful API.
+        */
        if ((f->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) &&
            vb2_is_busy(&ctx->m2m_ctx->out_q_ctx.q)) {
                mtk_v4l2_err("out_q_ctx buffers already requested");
                ret = -EBUSY;
        }
 
+       /*
+        * Setting CAPTURE format after CAPTURE buffers are allocated is
+        * invalid.
+        */
        if ((f->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) &&
            vb2_is_busy(&ctx->m2m_ctx->cap_q_ctx.q)) {
                mtk_v4l2_err("cap_q_ctx buffers already requested");
@@ -865,6 +873,8 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv,
                        fmt = mtk_vdec_find_format(f);
                }
        }
+       if (fmt == NULL)
+               return -EINVAL;
 
        q_data->fmt = fmt;
        vidioc_try_fmt(f, q_data->fmt);
@@ -873,10 +883,10 @@ static int vidioc_vdec_s_fmt(struct file *file, void *priv,
                q_data->coded_width = pix_mp->width;
                q_data->coded_height = pix_mp->height;
 
-               ctx->colorspace = f->fmt.pix_mp.colorspace;
-               ctx->ycbcr_enc = f->fmt.pix_mp.ycbcr_enc;
-               ctx->quantization = f->fmt.pix_mp.quantization;
-               ctx->xfer_func = f->fmt.pix_mp.xfer_func;
+               ctx->colorspace = pix_mp->colorspace;
+               ctx->ycbcr_enc = pix_mp->ycbcr_enc;
+               ctx->quantization = pix_mp->quantization;
+               ctx->xfer_func = pix_mp->xfer_func;
 
                if (ctx->state == MTK_STATE_FREE) {
                        ret = vdec_if_init(ctx, q_data->fmt->fourcc);