* [PATCH 1/2] spi: Fix mapping from vmalloc-ed buffer to scatter list
@ 2014-11-17 9:14 Charles Keepax
[not found] ` <1416215672-31554-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
0 siblings, 1 reply; 4+ messages in thread
From: Charles Keepax @ 2014-11-17 9:14 UTC (permalink / raw)
To: broonie-DgEjT+Ai2ygdnm+yROfE0A
Cc: marex-ynQEQJNshbs, fabio.estevam-KZfg59tc24xl57MIdRCFDg,
linux-spi-u79uwXL29TY76Z2rM5mHXA,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E
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_set_buf
to be invalid.
As we only call page_address so that we can pass a virtual address to
sg_set_buf which will then immediately call virt_to_page on it, fix this
by calling sg_set_page directly rather then relying on the sg_set_buf
helper.
Signed-off-by: Charles Keepax <ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
---
drivers/spi/spi.c | 6 +++---
1 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index ebcb33d..50f20f2 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -615,13 +615,13 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
sg_free_table(sgt);
return -ENOMEM;
}
- sg_buf = page_address(vm_page) +
- ((size_t)buf & ~PAGE_MASK);
+ sg_set_page(&sgt->sgl[i], vm_page,
+ min, offset_in_page(buf));
} else {
sg_buf = buf;
+ sg_set_buf(&sgt->sgl[i], sg_buf, min);
}
- sg_set_buf(&sgt->sgl[i], sg_buf, min);
buf += min;
len -= min;
--
1.7.2.5
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] spi: spi-mxs: Fix mapping from vmalloc-ed buffer to scatter list
[not found] ` <1416215672-31554-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
@ 2014-11-17 9:14 ` Charles Keepax
[not found] ` <1416215672-31554-2-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2014-11-17 10:40 ` [PATCH 1/2] spi: " Mark Brown
1 sibling, 1 reply; 4+ messages in thread
From: Charles Keepax @ 2014-11-17 9:14 UTC (permalink / raw)
To: broonie-DgEjT+Ai2ygdnm+yROfE0A
Cc: marex-ynQEQJNshbs, fabio.estevam-KZfg59tc24xl57MIdRCFDg,
linux-spi-u79uwXL29TY76Z2rM5mHXA,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E
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-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
---
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);
--
1.7.2.5
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] spi: Fix mapping from vmalloc-ed buffer to scatter list
[not found] ` <1416215672-31554-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2014-11-17 9:14 ` [PATCH 2/2] spi: spi-mxs: " Charles Keepax
@ 2014-11-17 10:40 ` Mark Brown
1 sibling, 0 replies; 4+ messages in thread
From: Mark Brown @ 2014-11-17 10:40 UTC (permalink / raw)
To: Charles Keepax
Cc: marex-ynQEQJNshbs, fabio.estevam-KZfg59tc24xl57MIdRCFDg,
linux-spi-u79uwXL29TY76Z2rM5mHXA,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E
[-- Attachment #1: Type: text/plain, Size: 391 bytes --]
On Mon, Nov 17, 2014 at 09:14:31AM +0000, Charles Keepax wrote:
> 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_set_buf
> to be invalid.
Applied, thanks.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] spi: spi-mxs: Fix mapping from vmalloc-ed buffer to scatter list
[not found] ` <1416215672-31554-2-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
@ 2014-11-24 18:58 ` Mark Brown
0 siblings, 0 replies; 4+ messages in thread
From: Mark Brown @ 2014-11-24 18:58 UTC (permalink / raw)
To: Charles Keepax
Cc: marex-ynQEQJNshbs, fabio.estevam-KZfg59tc24xl57MIdRCFDg,
linux-spi-u79uwXL29TY76Z2rM5mHXA,
patches-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E
[-- Attachment #1: Type: text/plain, Size: 300 bytes --]
On Mon, Nov 17, 2014 at 09:14:32AM +0000, Charles Keepax wrote:
> 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
Applied, thanks.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 473 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-11-24 18:58 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-11-17 9:14 [PATCH 1/2] spi: Fix mapping from vmalloc-ed buffer to scatter list Charles Keepax
[not found] ` <1416215672-31554-1-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2014-11-17 9:14 ` [PATCH 2/2] spi: spi-mxs: " Charles Keepax
[not found] ` <1416215672-31554-2-git-send-email-ckeepax-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2014-11-24 18:58 ` Mark Brown
2014-11-17 10:40 ` [PATCH 1/2] spi: " Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).