diff options
author | Charles Keepax <ckeepax@opensource.wolfsonmicro.com> | 2014-11-17 09:14:31 +0000 |
---|---|---|
committer | Robin Gong <b38343@freescale.com> | 2014-12-19 10:24:44 +0800 |
commit | ef26c0a7706c5c5319d56de28cb3244bf0ab2cdb (patch) | |
tree | 8cc384d5093a676f140a2c8473fdbc470edf4049 | |
parent | 9b85071287145bf16e8202c2be4fdf7a076f7f0d (diff) |
spi: Fix mapping from vmalloc-ed buffer to scatter list
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@opensource.wolfsonmicro.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Cc: stable@vger.kernel.org
(cherry picked from commit c1aefbdd050e1fb15e92bcaf34d95b17ea952097)
(cherry picked from commit bf9cdf03f8d30db8e5c14645e1be9b49b0e945da)
-rw-r--r-- | 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 43442fa38503..e7b6c56e7649 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -575,13 +575,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; |