[PATCH 6/7] mtd: spi-nor: ensure memory used for nor->read() is DMA safe

From: Tudor.Ambarus
Date: Thu Nov 08 2018 - 06:07:29 EST


Use GFP_DMA to ensure that the memory we allocate for transfers in
nor->read() can be DMAed.

spi_nor_read_sfdp() calls spi_nor_read_raw(), which calls nor-read().
The latter might be implemented by the m25p80 driver which is on top
of the spi-mem layer. spi-mem requires DMA-able in/out buffers, let's
make sure they are.

Signed-off-by: Tudor Ambarus <tudor.ambarus@xxxxxxxxxxxxx>
---
drivers/mtd/spi-nor/spi-nor.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mtd/spi-nor/spi-nor.c b/drivers/mtd/spi-nor/spi-nor.c
index 2eaa21c85483..a13fc82bade5 100644
--- a/drivers/mtd/spi-nor/spi-nor.c
+++ b/drivers/mtd/spi-nor/spi-nor.c
@@ -2238,7 +2238,7 @@ static int spi_nor_read_sfdp_dma_unsafe(struct spi_nor *nor, u32 addr,
void *dma_safe_buf;
int ret;

- dma_safe_buf = kmalloc(len, GFP_KERNEL);
+ dma_safe_buf = kmalloc(len, GFP_KERNEL | GFP_DMA);
if (!dma_safe_buf)
return -ENOMEM;

@@ -3053,7 +3053,7 @@ static int spi_nor_parse_smpt(struct spi_nor *nor,

/* Read the Sector Map Parameter Table. */
len = smpt_header->length * sizeof(*smpt);
- smpt = kzalloc(len, GFP_KERNEL);
+ smpt = kzalloc(len, GFP_KERNEL | GFP_DMA);
if (!smpt)
return -ENOMEM;

@@ -3140,7 +3140,7 @@ static int spi_nor_parse_sfdp(struct spi_nor *nor,
if (header.nph) {
psize = header.nph * sizeof(*param_headers);

- param_headers = kmalloc(psize, GFP_KERNEL);
+ param_headers = kmalloc(psize, GFP_KERNEL | GFP_DMA);
if (!param_headers)
return -ENOMEM;

--
2.9.4