From patchwork Tue Mar 16 08:23:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Krzysztof_Ha=C5=82asa?= X-Patchwork-Id: 12141465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E7106C433DB for ; Tue, 16 Mar 2021 08:31:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B27B65004 for ; Tue, 16 Mar 2021 08:31:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234758AbhCPIbL (ORCPT ); Tue, 16 Mar 2021 04:31:11 -0400 Received: from ni.piap.pl ([195.187.100.5]:57866 "EHLO ni.piap.pl" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234824AbhCPIbE (ORCPT ); Tue, 16 Mar 2021 04:31:04 -0400 X-Greylist: delayed 393 seconds by postgrey-1.27 at vger.kernel.org; Tue, 16 Mar 2021 04:31:03 EDT Received: from t19.piap.pl (OSB1819.piap.pl [10.0.9.19]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ni.piap.pl (Postfix) with ESMTPSA id 4E550443991; Tue, 16 Mar 2021 09:24:26 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 ni.piap.pl 4E550443991 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=piap.pl; s=mail; t=1615883066; bh=mhirheRq8WviKByzNYMicvIkW+qgbFBkujfQT55US3A=; h=From:To:Cc:Subject:Date:From; b=M1cHjUu3FwM/mWOUgYgyeQg/+IMB5YgRujci2wQwovMpygx1bJlK7cbwIfetc0Wcb De3mxr0nIhJpnCg0FyeLfXVMYpQGvOT7s2w4pQcnbJ+VUssRTruncKTNTTJ0Cqe6tP gq/9DjT1zgdw1XTerMnaxLPLicVSW4nHKwkyyc0Q= From: "Krzysztof Halasa" To: Philipp Zabel Cc: Mauro Carvalho Chehab , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH] MEDIA CODA: Fix NULL ptr dereference in the encoder. Sender: khalasa@piap.pl Date: Tue, 16 Mar 2021 09:23:47 +0100 Message-ID: MIME-Version: 1.0 X-KLMS-Rule-ID: 4 X-KLMS-Message-Action: skipped X-KLMS-AntiSpam-Status: not scanned, whitelist X-KLMS-AntiPhishing: not scanned, whitelist X-KLMS-AntiVirus: Kaspersky Security for Linux Mail Server, version 8.0.3.30, not scanned, whitelist Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org 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 Cc: stable@vger.kernel.org # 5.11+ 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) {