diff mbox series

MEDIA CODA: Fix NULL ptr dereference in the encoder.

Message ID m3a6r3tsks.fsf@t19.piap.pl
State Superseded
Headers show
Series MEDIA CODA: Fix NULL ptr dereference in the encoder. | expand

Commit Message

Krzysztof HaƂasa March 16, 2021, 8:23 a.m. UTC
ctx->mb_err_cnt_ctrl could be NULL in case of failed initialization
(on decoders), and encoders don't use it at all.

Fixes: b2d3bef1aa78 ("media: coda: Add a V4L2 user for control error macroblocks count")
Signed-off-by: Krzysztof Halasa <khalasa@piap.pl>
Cc: stable@vger.kernel.org # 5.11+
diff mbox series

Patch

diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index 2f42808c43a4..26e37cbfe8dd 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -2373,8 +2373,10 @@  static void coda_finish_decode(struct coda_ctx *ctx)
 	if (err_mb > 0) {
 		if (__ratelimit(&dev->mb_err_rs))
 			coda_dbg(1, ctx, "errors in %d macroblocks\n", err_mb);
-		v4l2_ctrl_s_ctrl(ctx->mb_err_cnt_ctrl,
-				 v4l2_ctrl_g_ctrl(ctx->mb_err_cnt_ctrl) + err_mb);
+		if (ctx->mb_err_cnt_ctrl)
+			v4l2_ctrl_s_ctrl(ctx->mb_err_cnt_ctrl,
+					 v4l2_ctrl_g_ctrl(ctx->mb_err_cnt_ctrl)
+					 + err_mb);
 	}
 
 	if (dev->devtype->product == CODA_HX4 ||
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 96802b8f47ea..285c80f87b65 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -2062,7 +2062,8 @@  static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
 	if (q_data_dst->fourcc == V4L2_PIX_FMT_JPEG)
 		ctx->params.gop_size = 1;
 	ctx->gopcounter = ctx->params.gop_size - 1;
-	v4l2_ctrl_s_ctrl(ctx->mb_err_cnt_ctrl, 0);
+	if (ctx->mb_err_cnt_ctrl)
+		v4l2_ctrl_s_ctrl(ctx->mb_err_cnt_ctrl, 0);
 
 	ret = ctx->ops->start_streaming(ctx);
 	if (ctx->inst_type == CODA_INST_DECODER) {