From patchwork Sat Mar 17 15:28:13 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 10290867 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 ED678601BE for ; Sat, 17 Mar 2018 15:29:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E03FE29081 for ; Sat, 17 Mar 2018 15:29:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D4C9929118; Sat, 17 Mar 2018 15:29:43 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 85ECB29130 for ; Sat, 17 Mar 2018 15:29:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753488AbeCQP2o (ORCPT ); Sat, 17 Mar 2018 11:28:44 -0400 Received: from mail-lf0-f66.google.com ([209.85.215.66]:35149 "EHLO mail-lf0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753450AbeCQP2h (ORCPT ); Sat, 17 Mar 2018 11:28:37 -0400 Received: by mail-lf0-f66.google.com with SMTP id t132-v6so19499001lfe.2; Sat, 17 Mar 2018 08:28:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=AkZNSAlYV93Ca06XITmDpu5IPSUfn+nNm5Os971vgjg=; b=OSR2W6Aoo7tW5HEY9//qiyEsEEvvUmi8GHj2JqL6IU0dphffUdozmyYxhCEffRCr07 9Dx15wCh6fKnYFELFAhcw//Zjdf9hW/pfPFZwQ0B5QqdP1cApYtmJ692AgK/ac/0OUY4 +knuZ6bnq6dG/dvCdMPIxdi3Pe9FzM00bbOn1P816dBaCq3Re+oM6ITQDKXzF/iJXF46 e8JhonucXGPT9R2HXfU3n0Q7ezmeaNW4rKgIUC03MSHbraIx8IcCZzVoRWTGfpx2KY6D xA2rq/io1xsxdyxFXvGPijlIXHqG74LODs+P3/EOvy3yWKSBCj6ki8tE9Ag29CjxY8+M ZOGA== 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:in-reply-to:references; bh=AkZNSAlYV93Ca06XITmDpu5IPSUfn+nNm5Os971vgjg=; b=DpBnnDkLy+nmDX14CgSnTeE40IP5asllqjrbLwpwYEx1Qo2PDAuzAsm4/AzgKyHm3O GeLKgtAj+5CItONQxTDB5W5greaAFkNfqq51UKQ2rn4MEPzOzWHveEGmCsqUMBMQKyHo X/QI1MeBCx4meCEy1SEDnxI7gV0HZr05qOdq5Jf9Tsv8RS1xT0M5oXXudyh2gFFQJlaA ABPFjNMJ702nqEkAzcgsjxH7PdQpWNG6ePfeoUiwi8te21T0xrit0wPD2SrqkbFP6jHZ tmgY+tKpu7Ov8BiZcsGAID/NKx2O5+jvACWjbCtHiE/QpMK8yyR7jqHH617NCChspF8+ p82A== X-Gm-Message-State: AElRT7HR0jCeY36NWvwPMLN87UA84egZiiWgppQKqHfZD//8ZR3CgZSe tDhPtngntgOOWWE+J83GBf0= X-Google-Smtp-Source: AG47ELtmZvQsgAKo690LOGHc5BdTiusUKqiXXsgUIm/BBJudq0IaUEjhY5ODE77TB8ApUnW6xHTgMw== X-Received: by 10.46.14.10 with SMTP id 10mr4130887ljo.64.1521300515054; Sat, 17 Mar 2018 08:28:35 -0700 (PDT) Received: from localhost.localdomain (ppp109-252-55-234.pppoe.spdop.ru. [109.252.55.234]) by smtp.gmail.com with ESMTPSA id a142-v6sm2388276lfb.11.2018.03.17.08.28.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 17 Mar 2018 08:28:34 -0700 (PDT) From: Dmitry Osipenko To: Mauro Carvalho Chehab , Hans Verkuil Cc: Greg Kroah-Hartman , linux-media@vger.kernel.org, devel@driverdev.osuosl.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/5] media: staging: tegra-vde: Correct minimum size of U/V planes Date: Sat, 17 Mar 2018 18:28:13 +0300 Message-Id: <419bd84d9a3e098d5796a6ce74be25be5381f544.1521300358.git.digetx@gmail.com> X-Mailer: git-send-email 2.16.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Stride of U/V planes must be aligned to 16 bytes (2 macroblocks). This needs to be taken into account, otherwise it is possible to get a silent memory corruption if dmabuf size is less than the size of decoded video frame. Signed-off-by: Dmitry Osipenko --- drivers/staging/media/tegra-vde/tegra-vde.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/drivers/staging/media/tegra-vde/tegra-vde.c b/drivers/staging/media/tegra-vde/tegra-vde.c index 14899c887d58..94b4db55cdb5 100644 --- a/drivers/staging/media/tegra-vde/tegra-vde.c +++ b/drivers/staging/media/tegra-vde/tegra-vde.c @@ -602,12 +602,12 @@ static int tegra_vde_attach_dmabufs_to_frame(struct device *dev, struct tegra_vde_h264_frame *src, enum dma_data_direction dma_dir, bool baseline_profile, - size_t csize) + size_t lsize, size_t csize) { int err; err = tegra_vde_attach_dmabuf(dev, src->y_fd, - src->y_offset, csize * 4, SZ_256, + src->y_offset, lsize, SZ_256, &frame->y_dmabuf_attachment, &frame->y_addr, &frame->y_sgt, @@ -773,9 +773,11 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, enum dma_data_direction dma_dir; dma_addr_t bitstream_data_addr; dma_addr_t bsev_ptr; + size_t lsize, csize; size_t bitstream_data_size; unsigned int macroblocks_nb; unsigned int read_bytes; + unsigned int cstride; unsigned int i; long timeout; int ret, err; @@ -814,6 +816,10 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, goto free_dpb_frames; } + cstride = ALIGN(ctx.pic_width_in_mbs * 8, 16); + csize = cstride * ctx.pic_height_in_mbs * 8; + lsize = macroblocks_nb * 256; + for (i = 0; i < ctx.dpb_frames_nb; i++) { ret = tegra_vde_validate_frame(dev, &frames[i]); if (ret) @@ -827,7 +833,7 @@ static int tegra_vde_ioctl_decode_h264(struct tegra_vde *vde, ret = tegra_vde_attach_dmabufs_to_frame(dev, &dpb_frames[i], &frames[i], dma_dir, ctx.baseline_profile, - macroblocks_nb * 64); + lsize, csize); if (ret) goto release_dpb_frames; }