Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit df88e91b authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Mark Brown
Browse files

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: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 92e963f5
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -702,6 +702,7 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
		       enum dma_data_direction dir)
{
	const bool vmalloced_buf = is_vmalloc_addr(buf);
	unsigned int max_seg_size = dma_get_max_seg_size(dev);
	int desc_len;
	int sgs;
	struct page *vm_page;
@@ -710,10 +711,10 @@ static int spi_map_buf(struct spi_master *master, struct device *dev,
	int i, ret;

	if (vmalloced_buf) {
		desc_len = PAGE_SIZE;
		desc_len = min_t(int, max_seg_size, PAGE_SIZE);
		sgs = DIV_ROUND_UP(len + offset_in_page(buf), desc_len);
	} else {
		desc_len = master->max_dma_len;
		desc_len = min_t(int, max_seg_size, master->max_dma_len);
		sgs = DIV_ROUND_UP(len, desc_len);
	}

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


		buf += min;
		len -= min;
	}