From patchwork Mon Nov 17 09:14:32 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Charles Keepax X-Patchwork-Id: 5316441 Return-Path: X-Original-To: patchwork-linux-spi@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 1636AC11AD for ; Mon, 17 Nov 2014 09:22:14 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 47E8120160 for ; Mon, 17 Nov 2014 09:22:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3AD0820176 for ; Mon, 17 Nov 2014 09:22:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751489AbaKQJWL (ORCPT ); Mon, 17 Nov 2014 04:22:11 -0500 Received: from opensource.wolfsonmicro.com ([80.75.67.52]:37678 "EHLO opensource.wolfsonmicro.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751499AbaKQJWK (ORCPT ); Mon, 17 Nov 2014 04:22:10 -0500 Received: from localhost.localdomain (unknown [87.246.78.26]) by opensource.wolfsonmicro.com (Postfix) with ESMTPSA id D39F07500B7; Mon, 17 Nov 2014 09:22:06 +0000 (GMT) From: Charles Keepax To: broonie@kernel.org Cc: marex@denx.de, fabio.estevam@freescale.com, linux-spi@vger.kernel.org, patches@opensource.wolfsonmicro.com Subject: [PATCH 2/2] spi: spi-mxs: Fix mapping from vmalloc-ed buffer to scatter list Date: Mon, 17 Nov 2014 09:14:32 +0000 Message-Id: <1416215672-31554-2-git-send-email-ckeepax@opensource.wolfsonmicro.com> X-Mailer: git-send-email 1.7.2.5 In-Reply-To: <1416215672-31554-1-git-send-email-ckeepax@opensource.wolfsonmicro.com> References: <1416215672-31554-1-git-send-email-ckeepax@opensource.wolfsonmicro.com> Sender: linux-spi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP We can only use page_address on memory that has been mapped using kmap, when the buffer passed to the SPI has been allocated by vmalloc the page has not necessarily been mapped through kmap. This means sometimes page_address will return NULL causing the pointer we pass to sg_init_one to be invalid. Currently, this issue doesn't show up on the MXS architecture as the defconfig defines CONFIG_HIGHMEM=n which means all pages are mapped. For the sake of robustness though it is best to correct the issue. As we only call page_address so that we can pass a virtual address to sg_init_one which will eventually call virt_to_page on it, fix this by calling sg_set_page directly rather then relying on the sg_init_one helper. Note this patch is only build tested as I don't have an MXS system to test on. Signed-off-by: Charles Keepax --- drivers/spi/spi-mxs.c | 10 +++++----- 1 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-mxs.c b/drivers/spi/spi-mxs.c index a9e72f9..06a1154 100644 --- a/drivers/spi/spi-mxs.c +++ b/drivers/spi/spi-mxs.c @@ -182,7 +182,6 @@ static int mxs_spi_txrx_dma(struct mxs_spi *spi, int min, ret; u32 ctrl0; struct page *vm_page; - void *sg_buf; struct { u32 pio[4]; struct scatterlist sg; @@ -232,13 +231,14 @@ static int mxs_spi_txrx_dma(struct mxs_spi *spi, ret = -ENOMEM; goto err_vmalloc; } - sg_buf = page_address(vm_page) + - ((size_t)buf & ~PAGE_MASK); + + sg_init_table(&dma_xfer[sg_count].sg, 1); + sg_set_page(&dma_xfer[sg_count].sg, vm_page, + min, offset_in_page(buf)); } else { - sg_buf = buf; + sg_init_one(&dma_xfer[sg_count].sg, buf, min); } - sg_init_one(&dma_xfer[sg_count].sg, sg_buf, min); ret = dma_map_sg(ssp->dev, &dma_xfer[sg_count].sg, 1, (flags & TXRX_WRITE) ? DMA_TO_DEVICE : DMA_FROM_DEVICE);