Commit e86cbb20 authored by Charles Keepax's avatar Charles Keepax Committed by Luis Henriques

spi: Fix mapping from vmalloc-ed buffer to scatter list

commit c1aefbdd upstream.

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: default avatarCharles Keepax <ckeepax@opensource.wolfsonmicro.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 8e027c59
...@@ -606,13 +606,13 @@ static int spi_map_buf(struct spi_master *master, struct device *dev, ...@@ -606,13 +606,13 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
sg_free_table(sgt); sg_free_table(sgt);
return -ENOMEM; return -ENOMEM;
} }
sg_buf = page_address(vm_page) + sg_set_page(&sgt->sgl[i], vm_page,
((size_t)buf & ~PAGE_MASK); min, offset_in_page(buf));
} else { } else {
sg_buf = buf; sg_buf = buf;
sg_set_buf(&sgt->sgl[i], sg_buf, min);
} }
sg_set_buf(&sgt->sgl[i], sg_buf, min);
buf += min; buf += min;
len -= min; len -= min;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment