From patchwork Fri Jun 12 12:59:12 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hyungwon Hwang X-Patchwork-Id: 6598421 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 18B16C0020 for ; Fri, 12 Jun 2015 12:59:52 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9CF0B20684 for ; Fri, 12 Jun 2015 12:59:50 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id B577F20678 for ; Fri, 12 Jun 2015 12:59:49 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AA0977A0A0; Fri, 12 Jun 2015 05:59:33 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mailout4.samsung.com (mailout4.samsung.com [203.254.224.34]) by gabe.freedesktop.org (Postfix) with ESMTP id F251D6EAA7 for ; Fri, 12 Jun 2015 05:59:29 -0700 (PDT) Received: from epcpsbgr2.samsung.com (u142.gpu120.samsung.co.kr [203.254.230.142]) by mailout4.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0NPU00EB31F4LI20@mailout4.samsung.com> for dri-devel@lists.freedesktop.org; Fri, 12 Jun 2015 21:59:28 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.113]) by epcpsbgr2.samsung.com (EPCPMTA) with SMTP id D1.9A.28411.0B7DA755; Fri, 12 Jun 2015 21:59:28 +0900 (KST) X-AuditID: cbfee68e-f79c56d000006efb-ed-557ad7b01e27 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id C6.15.05312.0B7DA755; Fri, 12 Jun 2015 21:59:28 +0900 (KST) Received: from localhost.localdomain ([10.252.82.145]) by mmp2.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0NPU002KS1F1AP00@mmp2.samsung.com>; Fri, 12 Jun 2015 21:59:28 +0900 (KST) From: Hyungwon Hwang To: dri-devel@lists.freedesktop.org, devicetree@vger.kernel.org Subject: [PATCH 2/2] drm/exynos: ipp: validate a GEM handle with multiple planes Date: Fri, 12 Jun 2015 21:59:12 +0900 Message-id: <1434113958-15877-18-git-send-email-human.hwang@samsung.com> X-Mailer: git-send-email 1.9.1 In-reply-to: <1434113958-15877-1-git-send-email-human.hwang@samsung.com> References: <1434113958-15877-1-git-send-email-human.hwang@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrGLMWRmVeSWpSXmKPExsWyRsSkUHfD9apQg69f1S2utE5ntZh/5Byr xZWv79ksls7oY7WYdH8Ci8WLexdZLGZMfsnmwO7x4us2Zo/73ceZPPq2rGL0+LxJLoAlissm JTUnsyy1SN8ugStjz85djAVrRSpuPpzF2MDYItDFyMkhIWAi8eDPYlYIW0ziwr31bF2MXBxC AksZJaZP3MYCU3R90VMmiMR0Rom1D3aygSSEBH4wShx+Gg1iswnoSSy49oMdxBYRsJdY/PUU K0gDs0A3o8TK80/BEsICARLTW9aDrWMRUJW4820lcxcjBwevgIfExukuEMvkJE4emwxWwgkU vnvwFgvELneJ//cPsYPMlBCYzC5x9u4dqDkCEt8mH2IBmSMhICux6QAzxBxJiYMrbrBMYBRe wMiwilE0tSC5oDgpvchIrzgxt7g0L10vOT93EyMwuE//e9a3g/HmAetDjAIcjEo8vAlaVaFC rIllxZW5hxhNgTZMZJYSTc4HxlBeSbyhsZmRhamJqbGRuaWZkjhvgtTPYCGB9MSS1OzU1ILU ovii0pzU4kOMTBycUg2MBV+2SOQWZVu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-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Cc: sw0312.kim@samsung.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP FIMC & GSC driver can calculate the offset of planes. So there are use cases which IPP receives just one GEM handle of an image with multiple plane. This patch extends ipp_validate_mem_node() to validate this case. Signed-off-by: Hyungwon Hwang --- drivers/gpu/drm/exynos/exynos_drm_ipp.c | 51 ++++++++++++++++++++++++--------- 1 file changed, 38 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_ipp.c b/drivers/gpu/drm/exynos/exynos_drm_ipp.c index 54c5cf4..b3dc778 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_ipp.c +++ b/drivers/gpu/drm/exynos/exynos_drm_ipp.c @@ -482,8 +482,8 @@ static int ipp_validate_mem_node(struct drm_device *drm_dev, { struct drm_exynos_ipp_config *ipp_cfg; unsigned int num_plane; - unsigned long min_size, size; - unsigned int bpp; + unsigned long size, buf_size = 0, plane_size, img_size = 0; + unsigned int bpp, width, height; int i; ipp_cfg = &c_node->property.config[m_node->ops_id]; @@ -497,20 +497,45 @@ static int ipp_validate_mem_node(struct drm_device *drm_dev, * but it seems more than enough */ for (i = 0; i < num_plane; ++i) { - if (!m_node->buf_info.handles[i]) { - DRM_ERROR("invalid handle for plane %d\n", i); - return -EINVAL; - } + width = ipp_cfg->sz.hsize; + height = ipp_cfg->sz.vsize; bpp = drm_format_plane_cpp(ipp_cfg->fmt, i); - min_size = (ipp_cfg->sz.hsize * ipp_cfg->sz.vsize * bpp) >> 3; - size = exynos_drm_gem_get_size(drm_dev, - m_node->buf_info.handles[i], - c_node->filp); - if (min_size > size) { - DRM_ERROR("invalid size for plane %d\n", i); - return -EINVAL; + + /* + * The result of drm_format_plane_cpp() for chroma planes must + * be used with drm_format_xxxx_chroma_subsampling() for + * correct result. + */ + if (i > 0) { + width /= drm_format_horz_chroma_subsampling( + ipp_cfg->fmt); + height /= drm_format_vert_chroma_subsampling( + ipp_cfg->fmt); } + plane_size = width * height * bpp; + img_size += plane_size; + + if (m_node->buf_info.handles[i]) { + size = exynos_drm_gem_get_size(drm_dev, + m_node->buf_info.handles[i], + c_node->filp); + if (plane_size > size) { + DRM_ERROR( + "buffer %d is smaller than required\n", + i); + return -EINVAL; + } + + buf_size += size; + } + } + + if (buf_size < img_size) { + DRM_ERROR("size of buffers(%lu) is smaller than image(%lu)\n", + buf_size, img_size); + return -EINVAL; } + return 0; }