From patchwork Mon Apr 3 09:43:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?SXJ1aSBXYW5nICjnjovnkZ4p?= X-Patchwork-Id: 78452 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp2178100vqo; Mon, 3 Apr 2023 02:49:50 -0700 (PDT) X-Google-Smtp-Source: AKy350YDDXxMbl6UlwJKKbOZvQbEX0EiXlNThHziJjsXAmBfVW8jezxOaRS5UfbE/MIln6h+7abj X-Received: by 2002:a17:906:2581:b0:87b:6bbb:11ac with SMTP id m1-20020a170906258100b0087b6bbb11acmr33621871ejb.60.1680515390472; Mon, 03 Apr 2023 02:49:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680515390; cv=none; d=google.com; s=arc-20160816; b=0XoapU/iEO1BByuKKVEyOw+F9R8YZp/JOCBz9tAoFUU1xGnEENEh7tUE29bMIUAymY L2CgINrQb17xT0QoK0JjetC1J70sDZztk0NhVuj4lx5FNDT6zW773LJHBkCYquXz3Sxh OfNrkWtt6cE0bJaMDtpN93w0BFWoCpnwjrDNyMLVjBEwqmkzCbBkdDQUZe7e1XYbvM53 SZCI5dQLa5m2Hvx1GGmsSE3y+NMh1CfYAZzMzIEeBoM2Mn7h+f0lfMkBStRP2Jcxbd4n Qj63AG7NjetQFBBKQ8FwkUrHySptI3fplc2xieYlt0wn5oFD+OSAshyHwrqGh4jZAcg/ goRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=EHJLyaDloXo64Cbva9s+jdVQPscInXF4sT/C8pUOcqU=; b=j1oT8U7rcIzeBhW22Uwz2mFl/x8st/eCLXTIpJ1WQVw3l93WlziDFSrdFBfNRxchaJ THIpq9y09bKELHoqgGQ+K4z0YkJY1LMYFUY1/V4oHMhwGeBYGfarfDSUYAJxfpIkrFPo HgPapmeUuQjfuG8aEPUbqdsFRBVX8iZTWDg7Jkl8GtT0wBugScijwBLKvU0JBpfjAtYM US3rSS9uJpeq4/WYqEu36ho7LmSZE6a5q+aORybyifoJnEwDk7jE6aH4JBl3x5rcRFy5 GQxMJwYRNvzNXJ/ieL4BZRVkqyM7hoAXzf6UB7QoQv45IguSXAxPAYoNrNvfekBTwqE8 X4Bg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="RDa7M/ps"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b23-20020a17090636d700b008cd6f50c059si3596754ejc.669.2023.04.03.02.49.26; Mon, 03 Apr 2023 02:49:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@mediatek.com header.s=dk header.b="RDa7M/ps"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231926AbjDCJpP (ORCPT + 99 others); Mon, 3 Apr 2023 05:45:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231744AbjDCJo5 (ORCPT ); Mon, 3 Apr 2023 05:44:57 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C708111643; Mon, 3 Apr 2023 02:44:29 -0700 (PDT) X-UUID: 073fa346d20411edb6b9f13eb10bd0fe-20230403 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject:CC:To:From; bh=EHJLyaDloXo64Cbva9s+jdVQPscInXF4sT/C8pUOcqU=; b=RDa7M/psoS9CVrNzXYX+j64JFQ3nozNMmRgVCPVrWDspit1EE7a5iP7dMDRFMPGyUa2pPwbQb4lVQs4H30tXuXdA8b4Sqm3TSciKRceMvBGlES2GsJesf4I2Ac9+ofRoPP303CTROPT3/NhuHVanxh3q48268XmnL3ZnBtc7Ric=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.22,REQID:b58f632c-3e4b-4051-a69c-9b3ed96ccbeb,IP:0,U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:120426c,CLOUDID:c75424b5-beed-4dfc-bd9c-e1b22fa6ccc4,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-UUID: 073fa346d20411edb6b9f13eb10bd0fe-20230403 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 589057485; Mon, 03 Apr 2023 17:43:46 +0800 Received: from mtkmbs13n2.mediatek.inc (172.21.101.108) by mtkmbs13n2.mediatek.inc (172.21.101.108) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.25; Mon, 3 Apr 2023 17:43:44 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs13n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1118.25 via Frontend Transport; Mon, 3 Apr 2023 17:43:44 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Matthias Brugger CC: , , , , , , Yunfei Dong , Irui Wang Subject: [PATCH] media: mediatek: vcodec: Coverity issues in encoder driver Date: Mon, 3 Apr 2023 17:43:42 +0800 Message-ID: <20230403094342.27498-1-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-MTK: N X-Spam-Status: No, score=-0.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS,SPF_PASS, UNPARSEABLE_RELAY autolearn=unavailable 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1762148105992530802?= X-GMAIL-MSGID: =?utf-8?q?1762148105992530802?= CERT-C Characters and Strings: check core id is in valid range: dev->reg_base[dev->venc_pdata->core_id] evaluates to an address that could be at negative offset of an array. CERT-C Expression: check buf is not NULL before used: Dereferencing buf, which is known to be NULL. Signed-off-by: Irui Wang --- .../platform/mediatek/vcodec/mtk_vcodec_enc.c | 2 +- .../mediatek/vcodec/mtk_vcodec_enc_drv.c | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c index d65800a3b89d..db65e77bd373 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c @@ -943,7 +943,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue *q, unsigned int count) * FIXME: This check is not needed as only active buffers * can be marked as done. */ - if (buf->state == VB2_BUF_STATE_ACTIVE) { + if (buf && buf->state == VB2_BUF_STATE_ACTIVE) { mtk_v4l2_debug(0, "[%d] id=%d, type=%d, %d -> VB2_BUF_STATE_QUEUED", ctx->id, i, q->type, (int)buf->state); diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c index 9095186d5495..125d5722d07b 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c @@ -89,16 +89,24 @@ static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, void *priv) struct mtk_vcodec_ctx *ctx; unsigned long flags; void __iomem *addr; + int core_id; spin_lock_irqsave(&dev->irqlock, flags); ctx = dev->curr_ctx; spin_unlock_irqrestore(&dev->irqlock, flags); - mtk_v4l2_debug(1, "id=%d coreid:%d", ctx->id, dev->venc_pdata->core_id); - addr = dev->reg_base[dev->venc_pdata->core_id] + - MTK_VENC_IRQ_ACK_OFFSET; + core_id = dev->venc_pdata->core_id; + if (core_id < 0 || core_id >= NUM_MAX_VCODEC_REG_BASE) { + mtk_v4l2_err("Invalid core id: %d, ctx id: %d", + core_id, ctx->id); + return IRQ_HANDLED; + } + + mtk_v4l2_debug(1, "id: %d, core id: %d", ctx->id, core_id); + + addr = dev->reg_base[core_id] + MTK_VENC_IRQ_ACK_OFFSET; - ctx->irq_status = readl(dev->reg_base[dev->venc_pdata->core_id] + + ctx->irq_status = readl(dev->reg_base[core_id] + (MTK_VENC_IRQ_STATUS_OFFSET)); clean_irq_status(ctx->irq_status, addr);