From patchwork Thu Mar 31 12:29:43 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Boris BREZILLON X-Patchwork-Id: 8712361 Return-Path: X-Original-To: patchwork-linux-arm@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 0F423C0553 for ; Thu, 31 Mar 2016 12:32:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 1FC1920270 for ; Thu, 31 Mar 2016 12:32:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 42D592025B for ; Thu, 31 Mar 2016 12:32:00 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1albk8-0006ce-OJ; Thu, 31 Mar 2016 12:30:32 +0000 Received: from down.free-electrons.com ([37.187.137.238] helo=mail.free-electrons.com) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1albjl-00057f-BX; Thu, 31 Mar 2016 12:30:13 +0000 Received: by mail.free-electrons.com (Postfix, from userid 110) id F067B1820; Thu, 31 Mar 2016 14:29:48 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost.localdomain (LMontsouris-657-1-184-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id 5DFE217EA; Thu, 31 Mar 2016 14:29:48 +0200 (CEST) From: Boris Brezillon To: David Woodhouse , Brian Norris , linux-mtd@lists.infradead.org, Andrew Morton , Dave Gordon Subject: [PATCH 3/4] spi: use sg_alloc_table_from_buf() Date: Thu, 31 Mar 2016 14:29:43 +0200 Message-Id: <1459427384-21374-4-git-send-email-boris.brezillon@free-electrons.com> X-Mailer: git-send-email 2.5.0 In-Reply-To: <1459427384-21374-1-git-send-email-boris.brezillon@free-electrons.com> References: <1459427384-21374-1-git-send-email-boris.brezillon@free-electrons.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160331_053009_663016_C692730E X-CRM114-Status: GOOD ( 15.59 ) X-Spam-Score: -2.9 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Boris Brezillon , linux-crypto@vger.kernel.org, Herbert Xu , Vinod Koul , Richard Weinberger , Joerg Roedel , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org, Vignesh R , linux-mm@kvack.org, iommu@lists.linux-foundation.org, Mark Brown , Hans Verkuil , Laurent Pinchart , dmaengine@vger.kernel.org, Dan Williams , linux-media@vger.kernel.org, "David S. Miller" , linux-arm-kernel@lists.infradead.org, Mauro Carvalho Chehab MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace custom implementation of sg_alloc_table_from_buf() by a call to sg_alloc_table_from_buf(). Signed-off-by: Boris Brezillon Acked-by: Mark Brown --- drivers/spi/spi.c | 45 +++++---------------------------------------- 1 file changed, 5 insertions(+), 40 deletions(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index de2f2f9..eed461d 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -705,49 +705,14 @@ static int spi_map_buf(struct spi_master *master, struct device *dev, struct sg_table *sgt, void *buf, size_t len, enum dma_data_direction dir) { - const bool vmalloced_buf = is_vmalloc_addr(buf); - unsigned int max_seg_size = dma_get_max_seg_size(dev); - int desc_len; - int sgs; - struct page *vm_page; - void *sg_buf; - size_t min; - int i, ret; - - if (vmalloced_buf) { - desc_len = min_t(int, max_seg_size, PAGE_SIZE); - sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len); - } else { - desc_len = min_t(int, max_seg_size, master->max_dma_len); - sgs = DIV_ROUND_UP(len, desc_len); - } + struct sg_constraints constraints = { }; + int ret; - ret = sg_alloc_table(sgt, sgs, GFP_KERNEL); - if (ret != 0) + constraints.max_segment_size = dma_get_max_seg_size(dev); + ret = sg_alloc_table_from_buf(sgt, buf, len, &constraints, GFP_KERNEL); + if (ret) return ret; - for (i = 0; i < sgs; i++) { - - if (vmalloced_buf) { - min = min_t(size_t, - len, desc_len - offset_in_page(buf)); - vm_page = vmalloc_to_page(buf); - if (!vm_page) { - sg_free_table(sgt); - return -ENOMEM; - } - sg_set_page(&sgt->sgl[i], vm_page, - min, offset_in_page(buf)); - } else { - min = min_t(size_t, len, desc_len); - sg_buf = buf; - sg_set_buf(&sgt->sgl[i], sg_buf, min); - } - - buf += min; - len -= min; - } - ret = dma_map_sg(dev, sgt->sgl, sgt->nents, dir); if (!ret) ret = -ENOMEM;