Skip to content

Commit e4ff723

Browse files
minimaxwellgregkh
authored andcommitted
spi: Fix scatterlist elements size in spi_map_buf
commit ce99319 upstream. When SPI transfers can be offloaded using DMA, the SPI core need to build a scatterlist to make sure that the buffer to be transferred is dma-able. This patch fixes the scatterlist entry size computation in the case where the maximum acceptable scatterlist entry supported by the DMA controller is less than PAGE_SIZE, when the buffer is vmalloced. For each entry, the actual size is given by the minimum between the desc_len (which is the max buffer size supported by the DMA controller) and the remaining buffer length until we cross a page boundary. Fixes: 65598c1 ("spi: Fix per-page mapping of unaligned vmalloc-ed buffer") Signed-off-by: Maxime Chevallier <[email protected]> Signed-off-by: Mark Brown <[email protected]> Cc: [email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent faddb17 commit e4ff723

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

drivers/spi/spi.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -779,8 +779,14 @@ static int spi_map_buf(struct spi_controller *ctlr, struct device *dev,
779779
for (i = 0; i < sgs; i++) {
780780

781781
if (vmalloced_buf || kmap_buf) {
782-
min = min_t(size_t,
783-
len, desc_len - offset_in_page(buf));
782+
/*
783+
* Next scatterlist entry size is the minimum between
784+
* the desc_len and the remaining buffer length that
785+
* fits in a page.
786+
*/
787+
min = min_t(size_t, desc_len,
788+
min_t(size_t, len,
789+
PAGE_SIZE - offset_in_page(buf)));
784790
if (vmalloced_buf)
785791
vm_page = vmalloc_to_page(buf);
786792
else

0 commit comments

Comments
 (0)