]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
spi: spi-mxs: Fix mapping from vmalloc-ed buffer to scatter list
authorCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Mon, 17 Nov 2014 09:14:32 +0000 (09:14 +0000)
committerMark Brown <broonie@kernel.org>
Mon, 24 Nov 2014 18:58:08 +0000 (18:58 +0000)
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 <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/spi/spi-mxs.c

index a9e72f9d385e4e8ff73eb8766d2cf519b46768ac..06a11546a1a7a2f8d8958ec589474bae146e56be 100644 (file)
@@ -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);