Received: by 2002:a05:7412:518d:b0:e2:908c:2ebd with SMTP id fn13csp410914rdb; Thu, 5 Oct 2023 09:18:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFsM1L0aIyJtZATBv9M2znlDF/xRANFXP8h4l+vB+EA251D2gJ+9iHmCafWQnNUaNkvf5zr X-Received: by 2002:a05:6a20:4292:b0:14c:a53c:498c with SMTP id o18-20020a056a20429200b0014ca53c498cmr6649480pzj.10.1696522720944; Thu, 05 Oct 2023 09:18:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696522720; cv=none; d=google.com; s=arc-20160816; b=ByGjXAy6u5SB+IDTMoGeiBk3Kjn0gAti+ULvFp+UQaM3yLI4U6Jqk3YbtB4nFl75J9 fmMLc4c07D29EYyIIYvU9LzjGT0x2iLVtfG3TUm/rB4quh9lrkyxZT5u+8xe38qibEST Fka0nDrgxt2idTrcQtdEWXwTCD2MScu1ggcqtPZTCGdvshw4KWfSn5d9kxVmhix6c2ft Ap8z+QZx3qBERexdwNqTKThcTUqs8n2qvpanQnuP0XwSvlpcmU1mUk0H7C+eerbmNUzC eKxZyk2Is8nSNc4kB8/He56bbj6Yu0pI1nJ99O4yiGw8Z/EtHrSDRxLqI4AXM3qLLwQF TJtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id; bh=9RA+Vl0TFvQv/YPYnZ9AtIDhxy0C3bUxH0kGu3wUPxs=; fh=yEPyaNN5qw4o7iT/cY4oB1pHIr+Atbb/lZlSKjr/SkU=; b=r/Stiz1CmCsYtukpeNlO5tWN3s1FnHlPy8mDgWqzTGR1mzd4Ar65SrNJ3CAZ6WZUqV Z+hq9EFO3xyF1VhJqQjlHDpN4XMcfheT0Hc3tfvu8JNSc+u3CdOAVvazjBKjI8noVYlI jbs6a41vgfacs7sfh0m4O6g2tvkXf3X3hQJ6jMXY4l6jY1YBLqFAgHAkOPPdaQjSEDOk GoLM1ziRCc1Da0iMWuzy2whTb1QeiypX+/iHiib5toVz3f8dAEWwQN6DDFxfs5QA+ihU 4RRlrpQnfRhQNgeUc/Uvr+CI6D/sJeu8z7BRtjEFppPDsoY+SCBHf+efq0J4a3cS2Ft6 BKHg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id e23-20020a637457000000b005777b0c8f59si1745284pgn.478.2023.10.05.09.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Oct 2023 09:18:40 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=xs4all.nl Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id D7F358315578; Thu, 5 Oct 2023 09:18:39 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242513AbjJEQSJ (ORCPT + 99 others); Thu, 5 Oct 2023 12:18:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241236AbjJEQOM (ORCPT ); Thu, 5 Oct 2023 12:14:12 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7850629B0D; Thu, 5 Oct 2023 07:42:55 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C973EC116AF; Thu, 5 Oct 2023 08:43:19 +0000 (UTC) Message-ID: Date: Thu, 5 Oct 2023 10:43:18 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] media: mediatek: vcodec: Handle encoder vsi NULL pointer case Content-Language: en-US, nl To: Irui Wang , Mauro Carvalho Chehab , Matthias Brugger , angelogioacchino.delregno@collabora.com, nicolas.dufresne@collabora.com, Yunfei Dong Cc: Project_Global_Chrome_Upstream_Group@mediatek.com, linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Maoguang Meng References: <20230926101909.15030-1-irui.wang@mediatek.com> <20230926101909.15030-2-irui.wang@mediatek.com> From: Hans Verkuil In-Reply-To: <20230926101909.15030-2-irui.wang@mediatek.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,RCVD_IN_DNSWL_MED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Thu, 05 Oct 2023 09:18:40 -0700 (PDT) On 26/09/2023 12:19, Irui Wang wrote: > There will be a kernel null pointer exception if 'vsi' is NULL, check > 'vsi' is not NULL before assign it to encoder instance. > > Signed-off-by: Irui Wang > --- > .../platform/mediatek/vcodec/encoder/venc/venc_h264_if.c | 5 +++++ > .../platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c | 5 +++++ > 2 files changed, 10 insertions(+) > > diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c > index a68dac72c4e4..385bcc0d14f3 100644 > --- a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c > +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c > @@ -597,6 +597,11 @@ static int h264_enc_init(struct mtk_vcodec_enc_ctx *ctx) > inst->hw_base = mtk_vcodec_get_reg_addr(inst->ctx->dev->reg_base, VENC_SYS); > > ret = vpu_enc_init(&inst->vpu_inst); > + if (!inst->vpu_inst.vsi) { > + mtk_venc_err(ctx, "share buffer is NULL"); > + kfree(inst); > + return -EFAULT; > + } Shouldn't this check be done in vpu_enc_init? It looks weird that a function can return 0, but there is still an error that needs to be checked manually afterwards. Regards, Hans > > if (MTK_ENC_IOVA_IS_34BIT(ctx)) > inst->vsi_34 = (struct venc_h264_vsi_34 *)inst->vpu_inst.vsi; > diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c > index 05abca91e742..23ca0d93324f 100644 > --- a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c > +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_vp8_if.c > @@ -326,6 +326,11 @@ static int vp8_enc_init(struct mtk_vcodec_enc_ctx *ctx) > inst->hw_base = mtk_vcodec_get_reg_addr(inst->ctx->dev->reg_base, VENC_LT_SYS); > > ret = vpu_enc_init(&inst->vpu_inst); > + if (!inst->vpu_inst.vsi) { > + mtk_venc_err(ctx, "share buffer is NULL"); > + kfree(inst); > + return -EFAULT; > + } > > inst->vsi = (struct venc_vp8_vsi *)inst->vpu_inst.vsi; >