Skip to content

Commit df88e91

Browse files
andy-shevbroonie
authored andcommitted
spi: respect the maximum segment size of DMA device
The device which is actually does DMA may have a limitation of the maximum segment size. Respect this setting when preparing scatter-gather list. Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 92e963f commit df88e91

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

drivers/spi/spi.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -702,6 +702,7 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
702702
enum dma_data_direction dir)
703703
{
704704
const bool vmalloced_buf = is_vmalloc_addr(buf);
705+
unsigned int max_seg_size = dma_get_max_seg_size(dev);
705706
int desc_len;
706707
int sgs;
707708
struct page *vm_page;
@@ -710,10 +711,10 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
710711
int i, ret;
711712

712713
if (vmalloced_buf) {
713-
desc_len = PAGE_SIZE;
714+
desc_len = min_t(int, max_seg_size, PAGE_SIZE);
714715
sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len);
715716
} else {
716-
desc_len = master->max_dma_len;
717+
desc_len = min_t(int, max_seg_size, master->max_dma_len);
717718
sgs = DIV_ROUND_UP(len, desc_len);
718719
}
719720

@@ -739,7 +740,6 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
739740
sg_set_buf(&sgt->sgl[i], sg_buf, min);
740741
}
741742

742-
743743
buf += min;
744744
len -= min;
745745
}

0 commit comments

Comments
 (0)