Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp52289pxk; Tue, 1 Sep 2020 16:01:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzfDyYsabh7i1IWikEMUVXjGdgu5uUiEd7LnxBl6U5t0M0Qc8jlMF+deIq2HyfwI5gc+Yzh X-Received: by 2002:aa7:d3c2:: with SMTP id o2mr3966113edr.11.1599001268513; Tue, 01 Sep 2020 16:01:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599001268; cv=none; d=google.com; s=arc-20160816; b=VLnZq2ufMzhvGr5KHduo2oT9K4C8yvAqT3IdR/TCyiNgB89FIsyg7VLfgCMqO2usFk IzBR19g33G15gz6fdhr5jSN6izJ9clhuuu1dfzGo1Je23HSuhqECW6Re0vEDlcugpK2v AZTJodL7BIH00YyEuR4Rum7orvLuOFpTR+PjK45rvNIrmZuV7bhMRlk22lO+52BG9ksm kill+RRVqJgubeDE4hNc3G8oMWq5mHsltD+a7CeN4JcBTu46DRvelC29Tnm+pzeeyYQw u082AacF4T69BI9KzmoRI3urzmF3l0WsmywbT+nFFHFyYwcRBVOZ28E4AuEJwcRY3E8u R2EQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=jNkuMHbF1UR8S5ubhtFycOmprejU1QUtKLlwVO/HmEM=; b=xc7z9NHonAj4dw8HRDrlxEcXHM8N6PtWO5ARCj7US9rdtbpn7ntVS1wmlfM0yakv9M f0qgz1p/0duUcPtW4+y7R+oqE6P2JALlbU/yE9k4mICdpgcGEMvCV03Cy8t9Eevnbol8 7ZjL9O6s/lpIRO9MCdAXgV/B6rnIn0n6J4QeowG6Ebhkkm+b4FyYjn3uzijFw3PQD55V vc2G6uwaH8YxeMJydY1i5/g+QcfG/Tk5yva1KjTb5CDx8JcaFvy+ipsnCVlLaWY3oYV0 jT6ETIOl+n0G7XKP0tXKCfm3n2iVX7t6cOI/tthr8BGlZ1Oq7GiLNCT7M8RWjlx7v1oE ng6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=w3AXvs40; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id h11si1584125ejo.55.2020.09.01.16.00.45; Tue, 01 Sep 2020 16:01:08 -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=@kernel.org header.s=default header.b=w3AXvs40; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727088AbgIAW7d (ORCPT + 99 others); Tue, 1 Sep 2020 18:59:33 -0400 Received: from mail.kernel.org ([198.145.29.99]:41910 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727052AbgIAW72 (ORCPT ); Tue, 1 Sep 2020 18:59:28 -0400 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0BC50207EA for ; Tue, 1 Sep 2020 22:59:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1599001167; bh=6+prf8hd/dD/hqUCmuKJ8TIy6p+8/B1mAtJifqlir+A=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=w3AXvs40WAjhXqbXqQI1GI9Yf7hMmKxb/eEPBdI1ctXxmiKOG5KwrJHt7sbbu9Re4 4sgXHSx9tWBEQYbqv9Pjkq506kssAi0Zcp7Cv+il7ZTLRd/z6hHjzlDnpX/M0hpjIY EmThNZ/vhzh/HMmvip5IgkrHvzr7gvSKWbKBXIAc= Received: by mail-ej1-f42.google.com with SMTP id d11so3916240ejt.13 for ; Tue, 01 Sep 2020 15:59:26 -0700 (PDT) X-Gm-Message-State: AOAM533q6l/yqgpVaOXEOFM5viND9qgodbmQ0cNuzzImoSNzoDOfCZno j94Ki0DvY//cZfZL1wCDcYna6Sn/pgYuUoHkvA== X-Received: by 2002:a17:906:7492:: with SMTP id e18mr3598885ejl.375.1599001165547; Tue, 01 Sep 2020 15:59:25 -0700 (PDT) MIME-Version: 1.0 References: <20200826063316.23486-1-m.szyprowski@samsung.com> <20200826063316.23486-11-m.szyprowski@samsung.com> In-Reply-To: <20200826063316.23486-11-m.szyprowski@samsung.com> From: Chun-Kuang Hu Date: Wed, 2 Sep 2020 06:59:14 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v9 10/32] drm: mediatek: use common helper for a scatterlist contiguity check To: Marek Szyprowski Cc: DRI Development , iommu@lists.linux-foundation.org, linaro-mm-sig@lists.linaro.org, linux-kernel , Christoph Hellwig , Robin Murphy , Bartlomiej Zolnierkiewicz , Linux ARM , David Airlie , Daniel Vetter , Matthias Brugger , Chun-Kuang Hu , Philipp Zabel , "moderated list:ARM/Mediatek SoC support" Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Marek: Marek Szyprowski =E6=96=BC 2020=E5=B9=B48=E6=9C= =8826=E6=97=A5 =E9=80=B1=E4=B8=89 =E4=B8=8B=E5=8D=882:35=E5=AF=AB=E9=81=93= =EF=BC=9A > > 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. > Acked-by: Chun-Kuang Hu > 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/med= iatek/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_tabl= e(struct drm_device *dev, > struct dma_buf_attachment *attach, struct sg_tabl= e *sg) > { > struct mtk_drm_gem_obj *mtk_gem; > - int ret; > - struct scatterlist *s; > - unsigned int i; > - dma_addr_t expected; > > - mtk_gem =3D 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 =3D mtk_drm_gem_init(dev, attach->dmabuf->size); > if (IS_ERR(mtk_gem)) > return ERR_CAST(mtk_gem); > > - expected =3D 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) !=3D expected) { > - DRM_ERROR("sg_table is not contiguous"); > - ret =3D -EINVAL; > - goto err_gem_free; > - } > - expected =3D sg_dma_address(s) + sg_dma_len(s); > - } > - > mtk_gem->dma_addr =3D sg_dma_address(sg->sgl); > mtk_gem->sg =3D 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 >