Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp1955130pxk; Tue, 1 Sep 2020 11:46:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+kblId9tdEWrNQevzObjYq6avPH0R5EI12usOCa8z6yO4oHuxKysE3Ubj8LD5+/hf0DEt X-Received: by 2002:aa7:d805:: with SMTP id v5mr3108338edq.29.1598985961334; Tue, 01 Sep 2020 11:46:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1598985961; cv=none; d=google.com; s=arc-20160816; b=sOMS+AXVMECab30t8r0kI4QPOgUP5T7QvEmjCDgGC8q3oCQmkAy7w+2yx0sJSwte6t tgRFD/f3ukWw71ktPLUtFE9lLOg1jzMc+76QbDmNP6X5isUA7H7uRhNNXh8EcRGSdJSZ PL49yncrAGARBZwvXv87L7+s2hEAoXr8JCP/AaSYu3kE0f+LmgrHkeh6pX2Yd4Y0YrNe 2qlY8nDE6DHAcwiQ9ifoKtcK7llb6WCY7/H7Yx9YZ4atDviaCfcwtPD+fOW5EJGMbSGe xDKnIuCdScuL4WvJpsi9VipTqZnCR0AGFkQODXQlktx0gVKsZQGtW+pHHiaQKWDkxo3b 9pXw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=CVXuHlu0G0lAadlqP5I856ww4a4bfu8aa/HIIibWnSg=; b=hIL3T+9408taXwKBrf4hzsve8jUqfs2Fwg4Ltpk6cu/MV8Rn4S1rExJEX1HDLHWP5y OXTsk605FRjJ8nbCduczbxfeFOjxX1YTx5CeiPQ6t2B4ugOcTnw7JAF08Phxh0pqgiMI oby1dsbWNXSyWui59IB3jPRJ2lV39UhdCvulVP1yCspQhapMJu1+95dMYnaZZnxoR1if yrDUkD0jinuWkUgIgiOkKo0pRonRhxuzY+mFm1sqzNwzplYeKr7k1OwOvDl5Ul+jOypk Lba8serx77MrCzs8Khri4v1XXd9LL+ndsXkT+5s7GmaRBl6v4NtNc0BNTCqlAmp8lgw6 eXYA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ox14si1258405ejb.516.2020.09.01.11.45.36; Tue, 01 Sep 2020 11:46:01 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730340AbgIASom (ORCPT + 99 others); Tue, 1 Sep 2020 14:44:42 -0400 Received: from foss.arm.com ([217.140.110.172]:48240 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726102AbgIASol (ORCPT ); Tue, 1 Sep 2020 14:44:41 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 9AAB81FB; Tue, 1 Sep 2020 11:44:40 -0700 (PDT) Received: from [10.57.40.122] (unknown [10.57.40.122]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 82E493F71F; Tue, 1 Sep 2020 11:44:36 -0700 (PDT) Subject: Re: [PATCH v9 10/32] drm: mediatek: use common helper for a scatterlist contiguity check To: Marek Szyprowski , dri-devel@lists.freedesktop.org, iommu@lists.linux-foundation.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org Cc: Christoph Hellwig , Bartlomiej Zolnierkiewicz , linux-arm-kernel@lists.infradead.org, David Airlie , Daniel Vetter , Matthias Brugger , Chun-Kuang Hu , Philipp Zabel , linux-mediatek@lists.infradead.org References: <20200826063316.23486-1-m.szyprowski@samsung.com> <20200826063316.23486-11-m.szyprowski@samsung.com> From: Robin Murphy Message-ID: <0fda65b1-1755-9e18-7c84-3156f5124752@arm.com> Date: Tue, 1 Sep 2020 19:44:34 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20200826063316.23486-11-m.szyprowski@samsung.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-08-26 07:32, Marek Szyprowski wrote: > 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. Reviewed-by: Robin Murphy > 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) >