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: 8712261 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Original-To: patchwork-linux-crypto@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 B559DC0553 for ; Thu, 31 Mar 2016 12:31:09 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id DE58E2025B for ; Thu, 31 Mar 2016 12:31:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1D0872028D for ; Thu, 31 Mar 2016 12:31:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756643AbcCaM3z (ORCPT ); Thu, 31 Mar 2016 08:29:55 -0400 Received: from down.free-electrons.com ([37.187.137.238]:41988 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753691AbcCaM3v (ORCPT ); Thu, 31 Mar 2016 08:29:51 -0400 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=-7.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, 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 Cc: Mark Brown , linux-spi@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Vinod Koul , Dan Williams , dmaengine@vger.kernel.org, Mauro Carvalho Chehab , Hans Verkuil , Laurent Pinchart , linux-media@vger.kernel.org, Boris Brezillon , Richard Weinberger , Herbert Xu , "David S. Miller" , linux-crypto@vger.kernel.org, Vignesh R , linux-mm@kvack.org, Joerg Roedel , iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org 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> Sender: linux-crypto-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-crypto@vger.kernel.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;