From patchwork Tue Mar 7 06:03:28 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wu-Cheng Li X-Patchwork-Id: 9608113 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5824F604DC for ; Tue, 7 Mar 2017 06:04:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43D7626E3A for ; Tue, 7 Mar 2017 06:04:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 366AD28405; Tue, 7 Mar 2017 06:04:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BD65A26E3A for ; Tue, 7 Mar 2017 06:04:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0E9dAYwXFe6MDnoZHo4q9G76/xATfTznvkFM4s+OIgU=; b=YvI7DLO6Pll0u3lHwnoCuU1+Cg gZ5Ojhs3naLZaNy6fYfJ0UA4K+ZMhdRrhv0XsmtGtj6M32TaYrMCAjh5+lyyGHgQLhwJ+yBJJnLft vO9FWBf30XSneOrMWsKmHcbG4i5WfRZouOYXIzpotmRrDlTIpY3o2L9Yi0UbjnGxacQ9+xyw7Jcl6 0CoyTXFONCauLbQlhgrSVTSRWlWD4PPtXulpjFYDpurL/E3oTgyL0ZgdDh3ZXRJQMCufsBlzWwOXI v73QpqRY/ywlIWuQGX/RCFR87m2WuCNpydY2pRCGLu3K0eMGLF1jeSBXsPM/vyXCxRzDsJsR3IJo6 CBtFWL/w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cl8Et-0001MZ-Vz; Tue, 07 Mar 2017 06:04:52 +0000 Received: from mail-pf0-x22b.google.com ([2607:f8b0:400e:c00::22b]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cl8E5-000164-Qo for linux-arm-kernel@lists.infradead.org; Tue, 07 Mar 2017 06:04:03 +0000 Received: by mail-pf0-x22b.google.com with SMTP id w189so70294682pfb.0 for ; Mon, 06 Mar 2017 22:03:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=tgm+Nck0jPNlKM7cBJL71PtUTTbEpD7nnyyybBJE8vI=; b=nMn5MsUd+A+DigWDUTPoB/0mzqWM5Zkn53ihfXDdA9Wpn1ORBNayU55TAtVNcXxk4I xQj57P5J4h+kBqbODA99mc1ZCsljdYJUGMpYmyp5CAB1hFYCmpMdui4coQp/MtzNIHIf BkLslcEzg1Tk0i7PQMZVdh1TDqQWGBrNxHdLo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=tgm+Nck0jPNlKM7cBJL71PtUTTbEpD7nnyyybBJE8vI=; b=V7MKWQRJitEfuPxcToBTKK2X16O7XdNdri0cBzG0ncVurRysVE2FMFEnnr2+Q5Ud5N bz2HrcoYplb3oRP51bP9grqueyQf3DfqtckAmIWvNmKkV/zScuk+BCh8MNDUiSYvM2rl eaeZcCcRAGjX4tX8RqLhPwjFeNOzTiDYapQbm9VgRxTcQOu+Ioq+OX+ACXg5ZGJ4eyW8 7ZVn0yLAyA+NlH8hNzVry6X2+egAD5kDC1P8G8vbm6sZAUV2rnvDKID7EjP1CJJ7m4D+ 63wyCegP5ynBtMPR88PiCWrmdJ3DSpIKi8RgDEsyFMlXqNGMoSGfyHmtgvl21m8ieX0j GzuQ== X-Gm-Message-State: AMke39n+DmsBOcAHKE+0cR1wkD9UyflAQ5LicCOkefOojUmGK7iwiElCKIwlyfoNy+LvBleV X-Received: by 10.98.29.216 with SMTP id d207mr26131971pfd.144.1488866620883; Mon, 06 Mar 2017 22:03:40 -0800 (PST) Received: from wuchengli-z840.tpe.corp.google.com ([172.30.210.26]) by smtp.gmail.com with ESMTPSA id d199sm11539242pfd.107.2017.03.06.22.03.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 06 Mar 2017 22:03:40 -0800 (PST) From: Wu-Cheng Li To: pawel@osciak.com, tiffany.lin@mediatek.com, andrew-ct.chen@mediatek.com, mchehab@kernel.org, matthias.bgg@gmail.com, hans.verkuil@cisco.com, wuchengli@google.com Subject: [PATCH 1/1] mtk-vcodec: check the vp9 decoder buffer index from VPU. Date: Tue, 7 Mar 2017 14:03:28 +0800 Message-Id: <20170307060328.114348-2-wuchengli@chromium.org> X-Mailer: git-send-email 2.12.0.rc1.440.g5b76565f74-goog In-Reply-To: <20170307060328.114348-1-wuchengli@chromium.org> References: <20170307060328.114348-1-wuchengli@chromium.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170306_220401_923154_4D63F4B3 X-CRM114-Status: GOOD ( 12.57 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, djkurtz@chromium.org, Wu-Cheng Li , linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Wu-Cheng Li VPU firmware has a bug and may return invalid buffer index for some vp9 videos. Check the buffer indexes before accessing the buffer. Signed-off-by: Wu-Cheng Li --- drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c | 6 +++++ .../media/platform/mtk-vcodec/vdec/vdec_vp9_if.c | 26 ++++++++++++++++++++++ drivers/media/platform/mtk-vcodec/vdec_drv_if.h | 2 ++ 3 files changed, 34 insertions(+) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c index 502877a4b1df..7ebcf9e57ac7 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec.c @@ -1176,6 +1176,12 @@ static void vb2ops_vdec_buf_queue(struct vb2_buffer *vb) "[%d] vdec_if_decode() src_buf=%d, size=%zu, fail=%d, res_chg=%d", ctx->id, src_buf->index, src_mem.size, ret, res_chg); + + if (ret == -EIO) { + mtk_v4l2_err("[%d] Unrecoverable error in vdec_if_decode.", + ctx->id); + ctx->state = MTK_STATE_ABORT; + } return; } diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c index e91a3b425b0c..5539b1853f16 100644 --- a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c +++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c @@ -718,6 +718,26 @@ static void get_free_fb(struct vdec_vp9_inst *inst, struct vdec_fb **out_fb) *out_fb = fb; } +static int validate_vsi_array_indexes(struct vdec_vp9_inst *inst, + struct vdec_vp9_vsi *vsi) { + if (vsi->sf_frm_idx >= VP9_MAX_FRM_BUF_NUM - 1) { + mtk_vcodec_err(inst, "Invalid vsi->sf_frm_idx=%u.", + vsi->sf_frm_idx); + return -EIO; + } + if (vsi->frm_to_show_idx >= VP9_MAX_FRM_BUF_NUM) { + mtk_vcodec_err(inst, "Invalid vsi->frm_to_show_idx=%u.", + vsi->frm_to_show_idx); + return -EIO; + } + if (vsi->new_fb_idx >= VP9_MAX_FRM_BUF_NUM) { + mtk_vcodec_err(inst, "Invalid vsi->new_fb_idx=%u.", + vsi->new_fb_idx); + return -EIO; + } + return 0; +} + static void vdec_vp9_deinit(unsigned long h_vdec) { struct vdec_vp9_inst *inst = (struct vdec_vp9_inst *)h_vdec; @@ -834,6 +854,12 @@ static int vdec_vp9_decode(unsigned long h_vdec, struct mtk_vcodec_mem *bs, goto DECODE_ERROR; } + ret = validate_vsi_array_indexes(inst, vsi); + if (ret) { + mtk_vcodec_err(inst, "Invalid values from VPU."); + goto DECODE_ERROR; + } + if (vsi->resolution_changed) { if (!vp9_alloc_work_buf(inst)) { ret = -EINVAL; diff --git a/drivers/media/platform/mtk-vcodec/vdec_drv_if.h b/drivers/media/platform/mtk-vcodec/vdec_drv_if.h index db6b5205ffb1..ded1154481cd 100644 --- a/drivers/media/platform/mtk-vcodec/vdec_drv_if.h +++ b/drivers/media/platform/mtk-vcodec/vdec_drv_if.h @@ -85,6 +85,8 @@ void vdec_if_deinit(struct mtk_vcodec_ctx *ctx); * @res_chg : [out] resolution change happens if current bs have different * picture width/height * Note: To flush the decoder when reaching EOF, set input bitstream as NULL. + * + * Return: 0 on success. -EIO on unrecoverable error. */ int vdec_if_decode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs, struct vdec_fb *fb, bool *res_chg);