Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp3440142pxa; Tue, 25 Aug 2020 23:41:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxTMzsY5GMCI87mZ/iCQV5toadKt3nkvcZZDpvUJjj7011FG4Oqf5eD/afR4cN1trIk+nE+ X-Received: by 2002:aa7:c405:: with SMTP id j5mr3702220edq.329.1598424106277; Tue, 25 Aug 2020 23:41:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598424106; cv=none; d=google.com; s=arc-20160816; b=x3UVMLDIGqkdEvXno157fWeCbc9KsCMqht5RVkt4cP2j+adVbw1ebr5GjmL9YaDPxc Lf1t+KyHsmDaCRi0Pt0NveVjwYRZT4giJldm13bkxWp5lVtWFfr2814dCKM9EL3hoiM/ Yx1xdB3Hy7eYwJswlQA22LR0adXE/Qa6jWnY4KNPFc5igUHoBTBRBjA805PUNtmlJLz8 gJXQdBXArhnDPMPLH+SmYG2BsSr7NFoeMlFMIVhw+/nDhygIg0Ydu0APgKtHc+ElUvVe Y5AW7j3Hsfyq2NCQJDjWZqmuNwuUrhOhVDPmOftgY/eCaw162ESrRX+k9NSBDp+DSIyW rHeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:cms-type:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature:dkim-filter; bh=bm4jyzGdoL7eueSepHu8xbaOpsUiBlIaWdzcyPajcJ4=; b=pN7qAn0gueP5YvHvXI09z0PoFX00PRC292VjMW+5XfqcrMgbmJGU8kJjXmEG3ZlLta TbEAgOQQSb3sCEWtXHRTTSacb0Qzzp1BnTz3bNRv6XZC1eG3syIunU1fd8O9YRYShqB0 guLoAAo0+GwgWT6oEoVAQePJOM5IdIPliBYhC0w0W+Ntcvk5AXfZ5040oy48JDXELOM4 HneEtU8TYB2aNYMcqvM/OSDaXmsdKkrD4Rm4GxKRyZTkDeCbKDZFgrzljl1gjM7aQob7 JRj2I2pfynYalNH++/4HNlDkaAd/FkPel1NbOtTXBWQkpDJfzaaLj5QP/D427KofHhb0 Oy4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="d/2w0Mo9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m20si780205eds.466.2020.08.25.23.41.23; Tue, 25 Aug 2020 23:41:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b="d/2w0Mo9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727923AbgHZGi0 (ORCPT + 99 others); Wed, 26 Aug 2020 02:38:26 -0400 Received: from mailout2.w1.samsung.com ([210.118.77.12]:39429 "EHLO mailout2.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726784AbgHZGfg (ORCPT ); Wed, 26 Aug 2020 02:35:36 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout2.w1.samsung.com (KnoxPortal) with ESMTP id 20200826063534euoutp02887e8f35a0f01d86af0c9eb20e38854c~uversa_yd1511215112euoutp02O for ; Wed, 26 Aug 2020 06:35:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout2.w1.samsung.com 20200826063534euoutp02887e8f35a0f01d86af0c9eb20e38854c~uversa_yd1511215112euoutp02O DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1598423734; bh=bm4jyzGdoL7eueSepHu8xbaOpsUiBlIaWdzcyPajcJ4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d/2w0Mo9bX1NLGeRcW20inr3skCuLL7er4lv14reNyRrglBDthd8/gQkWFS24dOgm /FkPBSiw7lMpHbJ4ZhpkrP4NYeMHWC1Hpo6nMN7jO+GCE8fTwIFKuH0hWpajmmkDBP Eemu9ZZGltfP0tECsmyJF+Jm3vN9FtwqssTf53WY= Received: from eusmges3new.samsung.com (unknown [203.254.199.245]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20200826063534eucas1p2871cf4916187b9bc380232b26bd6865e~uverSnhkK0402704027eucas1p2g; Wed, 26 Aug 2020 06:35:34 +0000 (GMT) Received: from eucas1p1.samsung.com ( [182.198.249.206]) by eusmges3new.samsung.com (EUCPMTA) with SMTP id 6E.4D.06318.5B2064F5; Wed, 26 Aug 2020 07:35:33 +0100 (BST) Received: from eusmtrp1.samsung.com (unknown [182.198.249.138]) by eucas1p1.samsung.com (KnoxPortal) with ESMTPA id 20200826063533eucas1p1fad2f2afb117b026081468d2d840ab0f~uveq-NYT81942019420eucas1p1m; Wed, 26 Aug 2020 06:35:33 +0000 (GMT) Received: from eusmgms1.samsung.com (unknown [182.198.249.179]) by eusmtrp1.samsung.com (KnoxPortal) with ESMTP id 20200826063533eusmtrp168812a4b34355f043831c99f380de8ca~uveq_iG8T1091110911eusmtrp1S; Wed, 26 Aug 2020 06:35:33 +0000 (GMT) X-AuditID: cbfec7f5-38bff700000018ae-d8-5f4602b5b2b9 Received: from eusmtip2.samsung.com ( [203.254.199.222]) by eusmgms1.samsung.com (EUCPMTA) with SMTP id 50.D0.06314.5B2064F5; Wed, 26 Aug 2020 07:35:33 +0100 (BST) Received: from AMDC2765.digital.local (unknown [106.120.51.73]) by eusmtip2.samsung.com (KnoxPortal) with ESMTPA id 20200826063533eusmtip25d907c392a9195b908baf25bf473b36a~uveqX7eyd0300803008eusmtip2u; Wed, 26 Aug 2020 06:35:32 +0000 (GMT) From: Marek Szyprowski To: dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Cc: Marek Szyprowski , Christoph Hellwig , Robin Murphy , Bartlomiej Zolnierkiewicz , linux-arm-kernel@lists.infradead.org, David Airlie , Daniel Vetter , Matthias Brugger , Chun-Kuang Hu , Philipp Zabel , linux-mediatek@lists.infradead.org Subject: [PATCH v9 10/32] drm: mediatek: use common helper for a scatterlist contiguity check Date: Wed, 26 Aug 2020 08:32:54 +0200 Message-Id: <20200826063316.23486-11-m.szyprowski@samsung.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200826063316.23486-1-m.szyprowski@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA0VSfyyUcRzue+97772O43Us35S027Kx5cdkvaaZjPZu/sg//ZGtdPLuWO7o zo+utbqdNB2HSy2RQtqJk1xSLuKII3XLj0njRDRTGePYSOrOi/57nufzfJ5nn+++OMI3sT3x ZEk6LZUIUwQYF23uWTMfeck6GR/YmBtKqs19LLKxpIFNVqnVKPm3WYOQwysLGPm0rptFVrSH kdbhKRapnx5hk0OGBxg5lD0AyPp3Fg6pvBFMWiZ6UdK4OMOOcKF0D3WAalutQKmWUguH0tfe wqhXq5Ns6mueiUW9qL5OjW1OI1TxqBZQb74oMKrwTyBV0FQLqGX9wVheHPd4Ip2SnElLA8LP c5N68jc4aUrny5XFxYgCDDuqgAMOiaNwtFzPUQEuzidqAOyd/b1NrACWLXSjDFkGcHzgF9hZ 6ar8yWIGWgBHZ1qQ3ZUJ6wRmd2FEEFTNq7awO5FjC1Y72U0I0YrAKsO6LRfH3Yh4OGBIsHtQ 4jCcvzuI2jGPCId1i2Uo0+YN6553IHbsYNNNeYUYo3/jQI2BbY+BRBQcKw1hZDf4w9TEYfAB 2F+cv3UBJLI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URXqezp+OEeFMSK6tSi/Lji0pz UosPMZoCHTWRWUo0OR8Y7Xkl8YamhuYWlobmxubGZhZK4rwdAgdjhATSE0tSs1NTC1KLYPqY ODilGhhVSyMMFBO4hNkYQq57ey+y1tgZ0mMnUL99W9yZ/T9/vL4eLJ34P9/748v+FXr/ZCw3 1f2cIvf8KZsP51kO2+nLuHzu3O10m9Nbu/3yKY3HuRJ7Vi/JMDWc7XAndq6Sb+WJ1Ry3Le7N Cl1buy3rwRqVc1XifkfWvtkVsHf1n8Vxq2pN3ddtTHdSYinOSDTUYi4qTgQAYwLi+b4CAAA= X-CMS-MailID: 20200826063533eucas1p1fad2f2afb117b026081468d2d840ab0f X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-RootMTR: 20200826063533eucas1p1fad2f2afb117b026081468d2d840ab0f X-EPHeader: CA CMS-TYPE: 201P X-CMS-RootMailID: 20200826063533eucas1p1fad2f2afb117b026081468d2d840ab0f References: <20200826063316.23486-1-m.szyprowski@samsung.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Use common helper for checking the contiguity of the imported dma-buf and do this check before allocating resources, so the error path is simpler. Signed-off-by: Marek Szyprowski --- drivers/gpu/drm/mediatek/mtk_drm_gem.c | 28 ++++++-------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/mediatek/mtk_drm_gem.c b/drivers/gpu/drm/mediatek/mtk_drm_gem.c index 6190cc3b7b0d..3654ec732029 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_gem.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_gem.c @@ -212,37 +212,21 @@ struct drm_gem_object *mtk_gem_prime_import_sg_table(struct drm_device *dev, struct dma_buf_attachment *attach, struct sg_table *sg) { struct mtk_drm_gem_obj *mtk_gem; - int ret; - struct scatterlist *s; - unsigned int i; - dma_addr_t expected; - mtk_gem = mtk_drm_gem_init(dev, attach->dmabuf->size); + /* check if the entries in the sg_table are contiguous */ + if (drm_prime_get_contiguous_size(sg) < attach->dmabuf->size) { + DRM_ERROR("sg_table is not contiguous"); + return ERR_PTR(-EINVAL); + } + mtk_gem = mtk_drm_gem_init(dev, attach->dmabuf->size); if (IS_ERR(mtk_gem)) return ERR_CAST(mtk_gem); - expected = sg_dma_address(sg->sgl); - for_each_sg(sg->sgl, s, sg->nents, i) { - if (!sg_dma_len(s)) - break; - - if (sg_dma_address(s) != expected) { - DRM_ERROR("sg_table is not contiguous"); - ret = -EINVAL; - goto err_gem_free; - } - expected = sg_dma_address(s) + sg_dma_len(s); - } - mtk_gem->dma_addr = sg_dma_address(sg->sgl); mtk_gem->sg = sg; return &mtk_gem->base; - -err_gem_free: - kfree(mtk_gem); - return ERR_PTR(ret); } void *mtk_drm_gem_prime_vmap(struct drm_gem_object *obj) -- 2.17.1